Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flash Dialog Message

Tags:

c#

pinvoke

winapi

A standard Windows dialog will flash if its owner window is clicked. The effect is similar to activating and deactivating the window.

When implementing a custom window border on my dialog, however, I can't figure out when I should flash the window. Windows does not flash the dialog for me.

Here's what I tried:

  • I watched all of the messages going to both the owner and dialog, but was unable to find any messages which exist solely to tell the window to flash.

  • I hooked Spy++ onto a default Windows dialog, but was also unable to find a "flash" message.

Looking in WinUser.h I couldn't find a "flash" message, so I am assuming it is some sort of combination of one or more messages with lParam and wParam specified.

Does anyone have any experience with this, or perhaps can point me to some pages which explain this? Any ideas are appreciated, since I have been working on this problem for several months now.

EDIT

In response to comments, here is the code for what I am currently using:

private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
    if (msg == 0x0020)
    {
        if ((short)((long)lParam & 0xffff) == (-2))
        {
            short hiword = (short)((((long)lParam) >> 16) & 0xffff);

            if (hiword == 0x0201 || hiword == 0x0204)
                Flash(); // My function which simulates a window flash
        }
    }

    return IntPtr.Zero;
}
like image 442
Ming Slogar Avatar asked Mar 28 '26 22:03

Ming Slogar


1 Answers

There isn't a message that tells you that Windows wants your window to flash. What you can do, however, is watch for the same trigger that Windows uses to start flashing your window in the first place.

Your window will flash when it has an owner window that's disabled (the WS_DISABLED style bit is set) and the user clicks a mouse button on any part of the disabled window.

Internally, this is handled by DefWindowProc in response to the WM_SETCURSOR message:

  • If the low-order word of lParam is HTERROR, and
  • the high-order word of lParam is one of the mouse button down messages (WM_LBUTTONDOWN, etc), and
  • the window has an enabled owned popup window, then
  • DefWindowProc will call FlashWindowEx on the popup window

So to identify the trigger for when you should flash your dialog yourself, all you have to do is the same thing as Windows does. In the owner window's window procedure, handle the WM_SETCURSOR message, perform the above three tests, and if all three are true then you can trigger your own custom flashing for your dialog. And of course, in that situation you wouldn't pass the message back to DefWindowProc to handle.

like image 195
Jonathan Potter Avatar answered Apr 01 '26 08:04

Jonathan Potter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!