Custom Tooltip with WS_POPUP Dialog Box
I want to create custom tooltips where I can place any controls. I got from CDialog and used styles WS_POPUP | WS_BORDER
. I also add styling CS_DROPSHADOW
to OnInitDialog to get the shadow of the tooltip.
Then I manage events WM_MOUSEHOVER
and WM_MOUSELEAVE
to show / hide the tooltips.
I am showing the tooltip with SetWindowPos
and SWP_NOACTIVATE
to prevent the parent from being included and the new dialog becomes active. But anyway, when I create a dialog using the method CDialog::Create
... the main window becomes inactive ... which makes a very bad effect.
So my question is, how do I create a CDialog with type WS_POPUP without my main window (or parent dialog box), becoming inactive when a new dialog pops up?
Thanks for the help!
Edited: I am not using the WS_VISIBLE style to create a dialog ... this is this 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 displays the tooltip looks something like this:
if(!pTooltipDlg)
{
pTooltipDlg = new MyCustomTooltipDlg();
pTooltipDlg->Create( MyCustomTooltipDlg::IDD, this);
}
pTooltipDlg->ShowWindow(SW_SHOWNOACTIVATE);
The first time (i.e. when the call is created) the main windows lose focus ... the rest of them this ugly effect doesn't happen ... so I'm pretty sure it has to do with creation.
source to share
First of all, consider using CWnd and not CDialog. This gives you much finer control. And you don't use any of the CDialog functions at all other than the dialog template; it's not that hard to dynamically create your controls.
You can also look into the message handlers handling the OnShowWindow and make sure any show commands are changed to SW_SHOWNA, as in Mark Ransom's comment.
Also, the parent window should probably be NULL as a tooltip.
source to share