Why using the TTF_CENTERTIP flag makes the ToolTip balloon style back to Windows XP style and how to solve this problem?

307 views Asked by At

I noticed that using the TTF_CENTERTIP flag when adding a ToolTip setting using TTM_ADDTOOL to a ToolTip window that has the TTS_BALLOON style causes this ToolTip to not appear with the Windows 10 style. In other words the balloon appears with rounded edges, as was the style of balloons in Windows XP.

Without using TTF_CENTERTIP the balloon appears with the correct style

Without using TTF_CENTERTIP the balloon appears with the correct style as seen above, however...

When using the TTF_CENTERTIP flag the style changes to "old style"

When using the TTF_CENTERTIP flag the style changes to "old style". The question is simple, why does this happen and how to make the balloons always have the latest style according to the OS on which the application runs?

Below is sample code. Create a Windows VCL Application project, where the main form is called Form1 and paste in this form two buttons (TButton) named "BUTN1" and "BUTN2". After doing this, simply paste all the code below in the unit of Form1

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls;

type
  TForm1 = class(TForm)
    BUTN1: TButton;
    BUTN2: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    FHwndTip: HWND;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses
  Winapi.CommCtrl;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  TI: TToolInfo;
begin
  FHwndTip := CreateWindowEx(WS_EX_NOACTIVATE or WS_EX_TOPMOST
                            ,TOOLTIPS_CLASS
                            ,nil
                            ,TTS_ALWAYSTIP or TTS_BALLOON
                            ,0,0,0,0
                            ,Self.Handle
                            ,0
                            ,HInstance
                            ,nil);

  SendMessage(FHwndTip,TTM_SETTITLE,TTI_INFO,LPARAM(PChar('Title')));
  SendMessage(FHwndTip,TTM_SETMAXTIPWIDTH,0,300);

  ZeroMemory(@TI,SizeOf(TToolInfo));

  TI.cbSize := SizeOf(TToolInfo);
  TI.hwnd := Self.Handle;

  TI.uId := BUTN1.Handle;
  TI.lpszText := 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tincidunt dictum dui vel luctus. Duis ornare arcu a varius pharetra. Curabitur tempor sit amet dui id malesuada. Aliquam efficitur, massa consectetur tristique iaculis, dolor diam tincidunt.';
  TI.uFlags := TTF_IDISHWND or TTF_SUBCLASS;
  SendMessage(FHwndTip,TTM_ADDTOOL,0,LPARAM(@TI));

  TI.uId := BUTN2.Handle;
  TI.lpszText := 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tincidunt dictum dui vel luctus. Duis ornare arcu a varius pharetra. Curabitur tempor sit amet dui id malesuada. Aliquam efficitur, massa consectetur tristique iaculis, dolor diam tincidunt.';
  TI.uFlags := TTF_IDISHWND or TTF_SUBCLASS or TTF_CENTERTIP;
  SendMessage(FHwndTip,TTM_ADDTOOL,0,LPARAM(@TI));
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  DestroyWindow(FHwndTip);
end;

end.

Update 1

In order to try to solve this problem I went to the new "Microsoft Stack Overflow" and asked the same question there. It was then that I discovered that the problem is not with my code, but with something Delphi probably does, but what?

https://learn.microsoft.com/en-us/answers/questions/786101/why-using-the-ttf-centertip-flag-makes-the-tooltip.html?childToView=786169

A user kindly did me the favor of trying to reproduce the problem using VS. The result was that the problem does not happen. What can it be?

Update 2

Another user said he was able to reproduce the problem using the same tool as the one who said he couldn't reproduce it (VS2022). Now it's gotten even more complicated, as I rely on the goodwill of these two individuals to figure out why one of them can see the problem and the other can't. I'm pretty sure that if this "detail" is discovered, I will be able to apply the solution in Delphi

Update 3

After several attempts to resolve this issue I came to the conclusion that this is indeed a bug in the Windows API. With the help of some users in Microsoft Q&A we were able to discover that when using the CreateDialog function, to create a window, using the TTF_CENTERTIP flag makes it look like Windows XP, however Delphi is not using CeateDialog, it is using CreateWindowEx both to create the application window (TApplication) and the main Form.

In one of my tests I showed the TApplication window, which is normally hidden, I put a button in it, I created and configured a ToolTip window for this button with the TTF_CENTERTIP flag and, in this case, the ToolTip appeared correctly, that is, for the TApplication window created with CreateWindowEx works, but for TForm1 window created also with CreateWindowEx it doesn't work. What is the difference??!!

Thinking it might be something related to the window styles I copied the styles from the TApplication window to TForm1 and was not successful.

In another attempt to find out the cause of the problem, I created an application using only Windows API functions and so I was able to create 2 windows, putting the ToolTip in the second one to check if it had something to do with "being something placed in the second application window", but I didn't succeed either. The original example (with only one main Window) can be found here: https://osdn.net/users/derekwildstar/pastebin/7879.

I've also done a second example, using CreateDialog to reproduce the problem using just API calls. Here is this example: https://osdn.net/users/derekwildstar/pastebin/7912

Well, in Microsoft's Q&A one person said he passed this problem on to "the team", let's see if they at least explain why this occurs, if it's normal, then maybe after that I can come up with a way to solve the problem in Delphi

0

There are 0 answers