Sign in to follow this  
Guest szm99

Modules and Menu Bars

Recommended Posts

I've got my module to display correctly on the FS menu bar, but I can't seem to intercept the clicks. I have a hook set for WH_CALLWNDPROC, and it works fine, but I'm not getting a WM_COMMAND message when I click on the menu bar. I thought WM_COMMAND was the message to look for when clicking the menu bar, but I guess not. If I open FSUIPC, I don't get a WM_COMMAND message until I click OK to close the dialog. I've also tried WM_MENUSELECT, but I'm having a hard time discerning the clicks on the sub menus from the main menus, along with highlites, etc. Any ideas? Thanks!

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

sounds interresting. However, WH_GETMESSAGE may get a lot of messages and ultimately, may impair the module in catching and treating all these messages could potentially affect performances in the sim. How does it work so far to this respect?

Share this post


Link to post
Share on other sites

Here's my function for the WH_GETMESSAGE hook. Seems to work perfectly with no side effects. What way would you do it? WH_GETMESSAGE seems to be the only way I can catch a WM_COMMAND from a menu bar.LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam){ MSG *message; if (nCode >= 0) { message = (MSG *)lParam; if (message->message == WM_COMMAND) { if (LOWORD(message->wParam) == ID_FFS_ABOUT) { MessageBox(hwnd,"Flight Factory-Simulations!","FFS",MB_OK); } } } return CallNextHookEx(hhook_msgproc, nCode, wParam, lParam);}

Share this post


Link to post
Share on other sites

Sounds great indeed. I miss-understood your use of GetMessage at first (and my Windows API knowledge as well :-) ) Since the hook is only called when the application calls for a GetMessage() or PeekMessage(), then you are right there is little overhead. I suspect that when you move your mouse a lot it sends a lot of messages in the queue, and for each the hook callback will have to test them though. But there are very few ways around anyhow!

Share this post


Link to post
Share on other sites

I cant make my module to display correctly on the FS menu bar.Here is the code,Any and all help greatly appreciated. BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)HWND hWnd = FindWindow ("FS98MAIN", NULL);HMENU hMenu,hPopupMenu;switch(dwReason) { case DLL_PROCESS_ATTACH: hMenu=GetMenu(hWnd); hPopupMenu=CreatePopupMenu(); AppendMenu(hPopupMenu,MF_STRING,0x1016,"TEST"); AppendMenu(hMenu,MF_POPUP,(UINT)hPopupMenu,"test"); DrawMenuBar(hWnd); . . . . . break; case DLL_PROCESS_DETACH: . . . . DeleteMenu(hMenu,0x1016,MF_BYCOMMAND) break; }

Share this post


Link to post
Share on other sites

It's pretty tricky to do. You need to set a hook using SetWindowsHookEx on WH_CALLWNDPROC. Then in CallWndProc, when you get a WM_INITMENU message, draw your menu. Here's how I create the menu for my module:hMenu = GetMenu(hwnd);SubMenu = GetSubMenu(hMenu, 0);MyMenu = CreatePopupMenu();AppendMenu(MyMenu, MF_STRING, ID_FFS_SETTINGS, "&Settings");AppendMenu(MyMenu, MF_SEPARATOR, 0, 0);AppendMenu(MyMenu, MF_STRING, ID_FFS_ABOUT, "&About");AppendMenu(SubMenu, MF_STRING | MF_POPUP, (UINT)MyMenu, "Flight Factory");SetMenu(hwnd, hMenu);

Share this post


Link to post
Share on other sites

my code still have some problem. First,it cant get a WM_INITMENU message in CallWndProc. Second,it seem that the hook cant be released even using UnhookWindowsHookEx.LRESULT CALLBACK CallWndProc(int nCode,WPARAM wParam,LPARAM lParam) { hWnd = FindWindow ("FS98MAIN", NULL); MSG *message; if(hWnd) { if (nCode >= 0) { message = (MSG *)lParam; if (message->message == WM_INITMENU) { hMenu = GetMenu(hWnd); SubMenu = GetSubMenu(hMenu, 0); MyMenu = CreatePopupMenu(); AppendMenu(MyMenu, MF_STRING, 12343, "&Test"); . . . } } return CallNextHookEx(hhookSysMsg, nCode, wParam,lParam);} BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved){ case DLL_PROCESS_ATTACH: hhookSysMsg = SetWindowsHookEx(WH_CALLWNDPROC,CallWndProc,hDLL,0); break; case DLL_PROCESS_DETACH: if(hhookSysMsg) UnhookWindowsHookEx(hhookSysMsg); break;}

Share this post


Link to post
Share on other sites

Try hhookSysMsg = SetWindowsHookEx(WH_CALLWNDPROC,CallWndProc,0, GetCurrentThreadId());UnhookWindowsHookEx(hhook_winproc) works fine for me, what error do you get?Also, in CallWndProc(), you should be using a CWPSTRUCT, such as:CWPSTRUCT *message;if (nCode >= 0){ message = (CWPSTRUCT *)lParam; if (message->message == WM_INITMENU) { hMenu = GetMenu(hWnd); SubMenu = GetSubMenu(hMenu, 0); MyMenu = CreatePopupMenu(); AppendMenu(MyMenu, MF_STRING, 12343, "&Click Me!"); AppendMenu(SubMenu, MF_STRING | MF_POPUP, (UINT)MyMenu, "&Test"); SetMenu(hwnd, hMenu); DrawMenuBar(hwnd); }}

Share this post


Link to post
Share on other sites

Thank you MKaprocki,now the hook can be released when exit FS.But the new menu only occurs when i clicks an item on the menu bar and disappear when menu bar not become active. WM_INITMENU occurs when the user clicks an item on the menu bar or presses a menu key,should i add some other code?Regards

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this