How to create a non-interactive window in MFC
-
09-06-2019 - |
Question
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?
Solution 2
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.
OTHER TIPS
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.