Hi all.

I have a general problem with Win32 applications. If someone have a good solution, or suggestion, please, share it. :)

The problem: Application have 2 windows, let say: First and Second. The First window is the main window of the application. It have main menu assigned. Second window have some controls on it and have not main menu. So, when First window have the focus, Alt+somekey activates coresponding submenu, but when the Second window have the focus, Alt+somekey doesn't activate menu items from First window.

The question: How most naturally :) I can make menu shortcuts pressed in Second window to affect menu in the First one? I tryed different ways, redirecting some messages (WM_KEYDOWN, WM_SYSKEYDOWN etc.), but the behaviour is not very good. Note that Second window's window menu should still work with alt-space.

Regards.
Posted on 2003-10-03 09:03:38 by JohnFound
I haven't tried it, but you could use an accelerators table for the second window, without the NOINVERT flag, and pass the APIs the handle of the first window... perhaps something like this:
invoke TranslateAccelerator,hWndFirst,offset Msg

Or maybe:
push Msg.hwnd

mov eax,hWndFirst
mov Msg.hwnd,eax
invoke TranslateAccelerator,hWndFirst,offset Msg
pop Msg.hwnd

Like I said, I didn't try it so I don't know how would the OS takes this. :confused:
Posted on 2003-10-03 15:05:50 by QvasiModo
Well, this cost me long time to figure out how this should be written, but now I have the proper answer:

I find out that there is totaly wrong description in MS API referense, about WM_SYSCOMMAND|SC_KEYMENU.
Actually this message concerns not only window menu, but 'menu bar' (main menu) of the window.
It uses xPos argument (in contrast of API reference description) to pass the code (probably virtual key-code) of the key that is used for access the menu ($66 - 'f' for Alt+F - for example.) If only Alt key (or F10) key is pressed xPos = 0.

So, to solve above problem with multi-window (probably SDI) applications, you should redirect the message WM_SYSCOMMAND|SC_KEYMENU to your main form (that one with main menu) and you may have standard access to main menu from within every window.

Regards.
Posted on 2003-11-10 08:14:05 by JohnFound
I have a way thet can solve this problem by create the global hotkey.first,you should
adds a hotkey to the global atom table ,eg:
code.
name db "yourhotkeyname",0
invoke GlobalAddAtom,offset name
the return values is the newly created atom;
and then,you can use the RegisterHotKey function to define a system-wide hot key;
final,you should deal with WM_HOTKEY message in the WndProc function.
Remarks:when the process is terminate ,you must undefine the hotkey by UnRegisterHotKey;
Posted on 2003-11-11 00:05:25 by jefeng
Hi jefeng.

I know that this problem can be solved many ways. But the one described in my second post in this thread is the most natural way. I don't know how many people know this approach, because there is a wrong description in the MS API reference.

Hm, maybe this thread have to be included in the FAQ...?

Regards.
Posted on 2003-11-11 07:12:04 by JohnFound
JohnFound:
I will try your method.if i can solve,i will share my code.
Posted on 2003-11-12 06:05:00 by jefeng