1

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.

Javier De Pedro
  • 2,219
  • 4
  • 32
  • 49

4 Answers4

3

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
  • 299,747
  • 42
  • 398
  • 622
  • 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 Dec 12 '08 at 15:57
1

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
  • 2,196
  • 14
  • 15
  • 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 Dec 12 '08 at 16:14
1

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
  • 4,148
  • 1
  • 27
  • 21
  • 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 Dec 12 '08 at 23:09
0

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
  • 2,219
  • 4
  • 32
  • 49