views:

1072

answers:

4

Hi,

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.

+2  A: 

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.

Mark Ransom
Thanks for your help! I am now using ShowWindow(SW_SHOWNOACTIVATE) instead of SetWindowPos and SWP_NOACTIVATE. I didn't realize this option and it is far more smart.Bad it still not working...I have edited the question with some comments.
Javier De Pedro
+1  A: 

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.

JTeagle
Thanks!I also tried that. I added this map entry ON_WM_SETFOCUS( ) to my tooltip dialog but the method OnSetFocus is not even being call.
Javier De Pedro
+1  A: 

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.

adzm
I prefer not to change CDialog for CWnd because I want to be able to use any kind of control. In the example I just used a Label but I want to create much more complex dialogs with ActiveX, etc.I appreciate the other two suggestions but they don't solve the problem.Thanks anyway!
Javier De Pedro
+1  A: 

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!

Javier De Pedro