带有 WS_POPUP 对话框的自定义工具提示
我想创建自定义工具提示,可以在其中放置任何类型的控件。 我从 CDialog 派生并使用 WS_POPUP | WS_BORDER 样式。 我还在 OnInitDialog 中添加了 CS_DROPSHADOW
样式来获取工具提示阴影。
然后我自己管理 WM_MOUSEHOVER
和 WM_MOUSELEAVE
事件来显示/隐藏工具提示。
我使用 SetWindowPos
和 SWP_NOACTIVATE
显示工具提示,以防止父对话框变为非活动状态以及新对话框变为活动状态。 但无论如何,当我使用 CDialog::Create 方法创建对话框时...主窗口变得不活动...这会产生非常糟糕的效果。
所以我的问题是如何创建一个具有 WS_POPUP 样式的 CDialog 而不会在新对话框出现时我的主窗口(或对话框的父窗口)变得不活动?
感谢您的帮助!
编辑:我不使用 WS_VISIBLE 样式来创建对话框...这就是资源:
IDD_LABEL_TOOLTIP_DLG DIALOGEX 0, 0, 100, 9
STYLE DS_SETFONT | WS_POPUP | WS_BORDER
FONT 8, "Tahoma", 0, 0, 0x0
BEGIN
LTEXT "##################",IDC_TOOLTIP_LBL_TEXT,0,0,99,9
END
显示工具提示的代码是这样的:
if(!pTooltipDlg)
{
pTooltipDlg = new MyCustomTooltipDlg();
pTooltipDlg->Create( MyCustomTooltipDlg::IDD, this);
}
pTooltipDlg->ShowWindow(SW_SHOWNOACTIVATE);
第一次(即调用创建时)主窗口失去焦点...其余的人都没有发生这种丑陋的效果...所以我确信是因为创建。
I want to create custom tooltips where I can put any kind of controls. I have derived from CDialog and used the WS_POPUP | WS_BORDER
styles. I also add the CS_DROPSHADOW
style in the OnInitDialog to get the tooltip shadow.
Then I manage myself the WM_MOUSEHOVER
and WM_MOUSELEAVE
events to show/hide the tooltips.
I display the tooltip using SetWindowPos
and SWP_NOACTIVATE
to prevent the parent from becoming inactive and the new dialog from becoming active. But anyway, when I create the dialog using CDialog::Create
method...the main window becomes inactive...what makes a very bad effect.
So my custion is how can I create a CDialog with the WS_POPUP style without my main window (or the parent window of the dialog) becomening inactive when the new dialog shows up???
Thanks for helping!
Edited: I do not use the WS_VISIBLE style to create the dialog...this this the resource:
IDD_LABEL_TOOLTIP_DLG DIALOGEX 0, 0, 100, 9
STYLE DS_SETFONT | WS_POPUP | WS_BORDER
FONT 8, "Tahoma", 0, 0, 0x0
BEGIN
LTEXT "##################",IDC_TOOLTIP_LBL_TEXT,0,0,99,9
END
The code that display the tooltip is something like that:
if(!pTooltipDlg)
{
pTooltipDlg = new MyCustomTooltipDlg();
pTooltipDlg->Create( MyCustomTooltipDlg::IDD, this);
}
pTooltipDlg->ShowWindow(SW_SHOWNOACTIVATE);
The first time (ie when the create is being call) the main windows lose the focus...the rest of them this ugly effect is not happening...so I am sure is because of the Create.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
创建窗口时,不要在其上设置 WS_VISIBLE 标志。 然后您可以将 ShowWindow 与 SW_SHOWNA 或 SW_SHOWNOACTIVATE 一起使用以使对话框可见。
When you create your window, don't set the WS_VISIBLE flag on it. Then you can use ShowWindow with SW_SHOWNA or SW_SHOWNOACTIVATE to make the dialog visible.
您是否在设置
WS_VISIBLE
的情况下调用CDialog::Create()
? 即使只是调用 Create() 也可能足以从父级获得焦点。 也可能值得在工具提示类上重写 WM_SETFOCUS ,并且不调用基类,以使焦点无法更改窗口。Are you calling
CDialog::Create()
withWS_VISIBLE
set? It might be that even just callingCreate()
is enough to take focus from the parent. It might also be worth overridingWM_SETFOCUS
on your tooltip class and not calling the base class to make it impossible for the focus to change windows.首先,考虑使用 CWnd 而不是 CDialog。 这可以让您更好地控制。 除了对话框模板之外,您并没有真正使用 CDialog 的任何功能; 动态创建控件并不太困难。
您可能还需要考虑在消息处理程序中处理 OnShowWindow 并确保所有显示命令都更改为 SW_SHOWNA,如 Mark Ransom 的评论中所示。
此外,作为工具提示,它可能应该有一个 NULL 父窗口。
First off, consider using a CWnd rather than a CDialog. This gives you much finer control. And you are not really using any features of the CDialog anyway other than the dialog template; it is not too difficult to dynamically create your controls.
You may also want to consider, in the message handlers, handling OnShowWindow and ensure any show commands are changed to SW_SHOWNA as in Mark Ransom's comment.
Additionally, as a tooltip, it should probably have a NULL parent window.
好的。 我终于明白了! 我只需在 OnInitDialog 方法中返回 FALSE 即可避免激活对话框。
感谢大家!
Ok. I finally got it! I just had to return FALSE in the OnInitDialog method to avoid the dialog from being activated.
Thanks to all of you!