为什么TTS_CLOSE风格的气球工具提示在“X”之后无法再次显示按钮被点击?这是正确的行为吗?
我正在创建一个气球工具提示 (TTS_BALLOON),其附加样式使“X”出现在该气球的右上角以将其关闭 (TTS_CLOSE )。
我正在创建的工具提示类型是“跟踪”,即我通过 TTM_TRACKACTIVATE 消息按需显示工具提示,正如 MSDN 上正确解释的那样。工具提示工作正常,在发送消息TTM_TRACKACTIVATE时显示/隐藏,但是,在显示工具提示并单击“X”后,它被正确隐藏,但不再可能显示工具提示以任何方式再次,甚至不使用 TTM_TRACKACTIVATE ,也不使用 TTM_POPUP 。 Visual Studio 论坛 (https://social.msdn.microsoft.com/Forums/vstudio/en-US/8ff12b85-c0a5-4a69-87d5-0a13ea9c43b0/help-with-ttsclose-style)甚至没有笔者今天得到了答案。
说到 TTM_POPUP 及其对应的 TTM_POP,在发送 TTM_POP 消息后,“从屏幕上删除工具提示”,我无法再显示,可以用TTM_POPUP,也可以用TTM_TRACKACTIVATE,即TTM_POP与点击效果相同“X”,根据我的理解,它只会破坏工具提示并使其无法使用。
我正在 Pascal (Delphi) 中开发一个类,以促进工具提示的创建和操作,现在我正在处理 TTS_CLOSE ,我不明白为什么会发生这种情况。正常吗?这是 Windows API 错误吗?
下面是示例代码。要重现该问题,请创建一个 Windows VCL Application 类型的项目,其唯一的 TForm 称为 Form1,并在此 TForm 中放置一个名为 BUTNHint 的 TButton 。然后将下面的代码完全粘贴到 TForm 的单元中,然后双击添加的按钮以及 TForm 的 OnShow 和 OnCreate 事件以连接处理程序。
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
BUTNHint: TButton;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure BUTNHintClick(Sender: TObject);
private
{ Private declarations }
FToolTipWindowHandle: HWND;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
Winapi.CommCtrl;
{$R *.dfm}
procedure TForm1.BUTNHintClick(Sender: TObject);
var
ToolInfo: TToolInfo;
begin
if not (SendMessage(FToolTipWindowHandle,TTM_GETCURRENTTOOL,0,0) > 0) then
begin
ZeroMemory(@ToolInfo,SizeOf(TToolInfo));
ToolInfo.cbSize := SizeOf(TToolInfo);
SendMessage(FToolTipWindowHandle,TTM_TRACKACTIVATE,WPARAM(True),LPARAM(@ToolInfo));
end
else
begin
ZeroMemory(@ToolInfo,SizeOf(TToolInfo));
ToolInfo.cbSize := SizeOf(TToolInfo);
SendMessage(FToolTipWindowHandle,TTM_TRACKACTIVATE,WPARAM(False),LPARAM(@ToolInfo));
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FToolTipWindowHandle := CreateWindowEx(WS_EX_NOACTIVATE or WS_EX_TOPMOST
,TOOLTIPS_CLASS
,nil
,TTS_NOPREFIX or TTS_ALWAYSTIP or TTS_BALLOON or TTS_CLOSE
,0,0,0,0
,TApplication(Owner).Handle
,0
,HInstance
,nil);
SendMessage(FToolTipWindowHandle,TTM_SETMAXTIPWIDTH,0,500);
SendMessage(FToolTipWindowHandle,TTM_SETTITLE,TTI_INFO,LPARAM(PChar('Título do ToolTip neste SSCCE')));
end;
procedure TForm1.FormShow(Sender: TObject);
var
ToolInfo: TToolInfo;
begin
ZeroMemory(@ToolInfo,SizeOf(TToolInfo));
ToolInfo.cbSize := SizeOf(TToolInfo);
ToolInfo.uFlags := TTF_TRACK or TTF_PARSELINKS;
ToolInfo.lpszText := 'Lorem ipsum dolor <a id="zzz">sit</a> amet, consectetur adipiscing '+'elit. Nunc eu vulputate ipsum, in dignissim velit. Donec vitae massa rhoncus, tincidunt enim sit amet, venenatis augue. Fusce fringilla pellentesque ligula, ac facilisis enim feugiat a. Nam lacinia eu sed.';
SendMessage(FToolTipWindowHandle,TTM_ADDTOOL,0,LPARAM(@ToolInfo));
end;
end.
运行程序时,按下该按钮可显示工具提示,再次单击该按钮可隐藏工具提示。请注意,这可以一遍又一遍地完成,但是,如果通过单击其关闭按钮 (X) 来关闭工具提示,则即使单击 TForm 上的现有按钮,工具提示也将不再出现几次。
I'm creating a Balloon ToolTip (TTS_BALLOON) with an additional style that makes an "X" appear in the upper right corner of this balloon in order to close it (TTS_CLOSE).
The type of ToolTip I'm creating is "tracking", ie I show the ToolTip on demand, via the TTM_TRACKACTIVATE message, as it is properly explained on MSDN. The ToolTip works correctly, being displayed/hidden upon sending the message TTM_TRACKACTIVATE, however, after displaying the ToolTip and clicking the "X", it is correctly hidden, but it is no longer possible to display the ToolTip again in any way, not even using TTM_TRACKACTIVATE , nor using TTM_POPUP. A similar question was asked on the Visual Studio Forum (https://social.msdn.microsoft.com/Forums/vstudio/en-US/8ff12b85-c0a5-4a69-87d5-0a13ea9c43b0/help-with-ttsclose-style) and not even there the author got an answer to this day.
Speaking of TTM_POPUP and its counterpart, TTM_POP, after sending a TTM_POP message, to "remove the ToolTip from the screen", I could no longer display it, either with TTM_POPUP or with TTM_TRACKACTIVATE, that is, TTM_POP has the same effect as click on the "X", which, in my understanding, only serves to break the ToolTip and make it unusable.
I'm developing a class in Pascal (Delphi) to facilitate the creation and manipulation of ToolTips and now I'm dealing with TTS_CLOSE and I don't understand why this happens. It's normal? Is it a Windows API bug?
Below is an example code. To reproduce the problem, create a project of type Windows VCL Application, whose only TForm is called Form1 and put a TButton named BUTNHint in this TForm. Then paste the code below completely into the TForm's Unit and then double click on the button that was added and on the TForm's OnShow and OnCreate events to connect the handlers.
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
BUTNHint: TButton;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure BUTNHintClick(Sender: TObject);
private
{ Private declarations }
FToolTipWindowHandle: HWND;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
Winapi.CommCtrl;
{$R *.dfm}
procedure TForm1.BUTNHintClick(Sender: TObject);
var
ToolInfo: TToolInfo;
begin
if not (SendMessage(FToolTipWindowHandle,TTM_GETCURRENTTOOL,0,0) > 0) then
begin
ZeroMemory(@ToolInfo,SizeOf(TToolInfo));
ToolInfo.cbSize := SizeOf(TToolInfo);
SendMessage(FToolTipWindowHandle,TTM_TRACKACTIVATE,WPARAM(True),LPARAM(@ToolInfo));
end
else
begin
ZeroMemory(@ToolInfo,SizeOf(TToolInfo));
ToolInfo.cbSize := SizeOf(TToolInfo);
SendMessage(FToolTipWindowHandle,TTM_TRACKACTIVATE,WPARAM(False),LPARAM(@ToolInfo));
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FToolTipWindowHandle := CreateWindowEx(WS_EX_NOACTIVATE or WS_EX_TOPMOST
,TOOLTIPS_CLASS
,nil
,TTS_NOPREFIX or TTS_ALWAYSTIP or TTS_BALLOON or TTS_CLOSE
,0,0,0,0
,TApplication(Owner).Handle
,0
,HInstance
,nil);
SendMessage(FToolTipWindowHandle,TTM_SETMAXTIPWIDTH,0,500);
SendMessage(FToolTipWindowHandle,TTM_SETTITLE,TTI_INFO,LPARAM(PChar('Título do ToolTip neste SSCCE')));
end;
procedure TForm1.FormShow(Sender: TObject);
var
ToolInfo: TToolInfo;
begin
ZeroMemory(@ToolInfo,SizeOf(TToolInfo));
ToolInfo.cbSize := SizeOf(TToolInfo);
ToolInfo.uFlags := TTF_TRACK or TTF_PARSELINKS;
ToolInfo.lpszText := 'Lorem ipsum dolor <a id="zzz">sit</a> amet, consectetur adipiscing '+'elit. Nunc eu vulputate ipsum, in dignissim velit. Donec vitae massa rhoncus, tincidunt enim sit amet, venenatis augue. Fusce fringilla pellentesque ligula, ac facilisis enim feugiat a. Nam lacinia eu sed.';
SendMessage(FToolTipWindowHandle,TTM_ADDTOOL,0,LPARAM(@ToolInfo));
end;
end.
When running the program press the button to display the ToolTip and click it again to hide the ToolTip. Note that this can be done over and over again, however, if you close the ToolTip by clicking its close button (X), the ToolTip will no longer appear, even by clicking the existing button on the TForm several times.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Sertac Akyuz 发现使用 < 工具提示气球上的“X”按钮单击时实际发生的情况之后强>TTS_CLOSE样式设置,我能够通过简单地在实际显示之前强制隐藏工具提示来解决问题:
根据Sertac Akyuz发现,我得出的结论是,当使用“X”关闭气球时,TooTip窗口被隐藏,但是它的一些内部控制,指的是 TTM_TRACKACTIVATE 消息的处理没有更新,这使得 ToolTip 窗口在内部“认为”它已经可见并简单地忽略应显示它的 TTM_TRACKACTIVATE 消息。在显示工具提示窗口之前隐藏它会导致实际发生的情况与窗口“认为”正在发生的情况之间出现某种同步。
对我来说,这是一个错误,因为官方文档中没有提及单击“X”按钮时会发生什么,并且如果没有文档说明这是功能,并且主要是因为它是这样工作的,那么它在我看来,这确实是一个错误。
After Sertac Akyuz's discovery of what actually happens when clicking the "X" button on a ToolTip balloon with the TTS_CLOSE style set, I was able to solve the problem by simply forcing the ToolTip to be hidden before actually showing it:
According to what Sertac Akyuz discovered, I came to the conclusion that, when closing the balloon using the "X", the TooTip window is hidden, but some internal control of it, referring to the handling of the TTM_TRACKACTIVATE message is not updated, which makes so that, internally, the ToolTip window "thinks" it is already visible and simply ignores the TTM_TRACKACTIVATE message that should display it. Hiding the ToolTip window before showing it causes a kind of synchronization between what is actually happening and what the window "thinks" is happening.
For me this is a bug, because there is no mention of what happens when the "X" button is clicked in the official documentation and if there is no documentation saying that this is the functionality and, mainly, because it works that way then it is of indeed a bug, in my opinion.