views:

311

answers:

2

In Windows, when you press Alt, and release it again, the menu bar gets activated. However, when you press Alt, then click, then release, the menu bar does not get activated because presumably you wanted to Alt+click, not activate the menu bar.

I want to support Alt+mouse wheel changes (which would map to horizontal scrolling). This works fine, but if you are ready and release the Alt key, the menu bar activates. Obviously this is not desirable. There must be some kind of action that Windows does internally when you Alt+click to cancel the internal 'ActivateMenuBarWhenAltIsReleased' flag. If I know what it is, I can do this myself when I receive a mouse wheel message.

So, does anyone know how the system works that activates the menu bar when you press and release Alt, and how to cancel this? Thanks!

A: 

I think this link (keybd_event Function) will help you out

mahesh
Which key would I need to send?
Frederik Slijkerman
+2  A: 

When you release the Alt key, the system generates a WM_SYSCOMMAND/SC_KEYMENU message. Futhermore, unless you press a key to open a specific popup menu, the lparam will be 0. DefWindowProc, upon receiving this, will enter the menu loop. So, all you have to do is detect this message and prevent it from getting to DefWindowProc:

LRESULT CALLBACK MainWndProc(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
    switch (msg) {
        // ...
        case WM_SYSCOMMAND: {
            DWORD cmd = wparam & 0xfff0;
            // test for Alt release without any letter key pressed
            if (cmd == SC_KEYMENU && lparam == 0) {
                // don't let it reach DefWindowProc
                return 0;
            }
            break;
        }
        // ...
    }

    return DefWindowProc(wnd, msg, wparam, lparam);
}
efotinis
This might work for an application, but I'm writing a plug-in so I don't have control over the main message loop...
Frederik Slijkerman