October 11, 200322 yr 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! Matt KaprockiFor fastest support, please submit a ticket at http://support.precisionmanuals.com
October 11, 200322 yr Never mind, I figured it out. Using a hook with WH_GETMESSAGE works perfectly! :-) Matt KaprockiFor fastest support, please submit a ticket at http://support.precisionmanuals.com
October 12, 200322 yr 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?
October 12, 200322 yr 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);} Matt KaprockiFor fastest support, please submit a ticket at http://support.precisionmanuals.com
October 12, 200322 yr 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!
October 13, 200322 yr 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; }
October 14, 200322 yr 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); Matt KaprockiFor fastest support, please submit a ticket at http://support.precisionmanuals.com
October 14, 200322 yr 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;}
October 14, 200322 yr 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); }} Matt KaprockiFor fastest support, please submit a ticket at http://support.precisionmanuals.com
October 15, 200322 yr 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
Create an account or sign in to comment