Javier De Pedro
Javier De Pedro

Reputation: 2239

Custom tooltip with a WS_POPUP dialog

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.

Upvotes: 1

Views: 3326

Answers (4)

Javier De Pedro
Javier De Pedro

Reputation: 2239

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!

Upvotes: 0

adzm
adzm

Reputation: 4136

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.

Upvotes: 1

JTeagle
JTeagle

Reputation: 2196

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.

Upvotes: 1

Mark Ransom
Mark Ransom

Reputation: 308158

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.

Upvotes: 3

Related Questions