views:

213

answers:

2

In my application I have a window which I popup with small messages on it (think similar to tooltip). This window uses the layered attributes to draw alpha backgrounds etc.

If I have several of these windows open at once, and I click one with my mouse, when they disappear they cause my application to lose focus (it switches focus to the app behind the current one).

How do I stop any interaction in my window?

+1  A: 

After playing with the WM_NCACTIVATE message with no luck, I overrode the WM_SETFOCUS message:

void CMyWindow::OnSetFocus(CWnd* pOldWnd)
{
    if (pOldWnd != NULL)
    {
     pOldWnd->SetFocus();
    }
}

That seems to do the trick. No idea why it works though! Comments welcome on that issue.

Mark Ingram
+1  A: 

It works because OnSetFocus (like many of the On* methods) gives you a chance to pre-empt an action before it actually occurs. The focus never actually switches to your non-interactive window.

Aidan Ryan