带有 WS_POPUP 对话框的自定义工具提示

发布于 2024-07-10 09:22:42 字数 1068 浏览 6 评论 0原文

我想创建自定义工具提示,可以在其中放置任何类型的控件。 我从 CDialog 派生并使用 WS_POPUP | WS_BORDER 样式。 我还在 OnInitDialog 中添加了 CS_DROPSHADOW 样式来获取工具提示阴影。

然后我自己管理 WM_MOUSEHOVERWM_MOUSELEAVE 事件来显示/隐藏工具提示。

我使用 SetWindowPosSWP_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

风渺 2024-07-17 09:22:42

创建窗口时,不要在其上设置 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.

哎呦我呸! 2024-07-17 09:22:42

您是否在设置 WS_VISIBLE 的情况下调用 CDialog::Create() ? 即使只是调用 Create() 也可能足以从父级获得焦点。 也可能值得在工具提示类上重写 WM_SETFOCUS ,并且调用基类,以使焦点无法更改窗口。

Are you calling CDialog::Create() with WS_VISIBLE set? It might be that even just calling Create() is enough to take focus from the parent. It might also be worth overriding WM_SETFOCUS on your tooltip class and not calling the base class to make it impossible for the focus to change windows.

权谋诡计 2024-07-17 09:22:42

首先,考虑使用 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.

绝情姑娘 2024-07-17 09:22:42

好的。 我终于明白了! 我只需在 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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文