| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
specifically, I am working with the Win32 API need to check whether the flags MF_SYSMENU and MF_STRING are included in the high-order word of the WPARAM in a WM_MENUSELECT message.
Here is some code: Code:
#define pmsg_lparam ((LPMSG)lParam)
LRESULT __declspec(dllexport) CALLBACK GetMsgHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
//nCode tells me what to do with the message. <0: return. HC_ACTION: process. (HC_ACTION = 0, so the first test below is valid.)
//wParam tells me whether the message has been removed from the queue (PM_NOREMOVE/PM_REMOVE).
//lParam is a pointer to the MSG. pmsg_lparam i have #defined to be ((LPMSG)lParam).
if (nCode != HC_ACTION) goto end; //ok, we're allowed to process the message
if (pmsg_lparam->message != WM_MENUSELECT) goto end; //the message is about a menu
if (HIWORD(pmsg_lparam->wParam) & MF_SYSMENU != 0) goto end; //said menu is the system menu
if (HIWORD(pmsg_lparam->wParam) & MF_STRING != 0) goto end; //clicked menu item is of the type we are looking for
if (LOWORD(pmsg_lparam->wParam) != IDM_HIDEWINDOW) goto end; //said menu item is ours
PostMessage(FindWindow("WinHiderClass", "WinHider"), MSG_HOOKTRIGGERED, WH_GETMESSAGE, 0); //all conditions met, E.T. calls home.
end: //sorry about the use of goto, but i believe this is a legitimate use of it. it's not like you have to read a huge mess of spaghetti code. using the goto prevents the necessity of typing the next line after every if statement.
return CallNextHookEx(NULL, nCode, wParam, lParam);
but, all those conditions are never met. I have tried replacing & with | and even ^, and testing for ==0 instead of !=0, but to no avail. what am I doing wrong? } |
|
#2
|
|||
|
|||
|
Approach seems right to me.
It may be due to : Code:
if(psmg_lparam->message != WM_MENUSELECT) goto end; Be sure to check all conditions. |
|
#3
|
|||
|
|||
|
thanks Cirus.
got it working now. I did some snooping with messages and some reading online (thanks Google and MSDN :-) ) and found that I should be using WM_SYSCOMMAND instead of WM_MENUSELECT (the latter for some reason does not give me the wanted results when the menu item is actually clicked, only when it is moused over). Here is the working code if anyone cares: Code:
LRESULT __declspec(dllexport) CALLBACK GetMsgHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
//nCode tells me what to do with the message. <0: return. HC_ACTION: process. (HC_ACTION = 0, so the first test below is valid.)
//wParam tells me whether the message has been removed from the queue (PM_NOREMOVE/PM_REMOVE).
//lParam is a pointer to the MSG. pmsg_lparam i have #defined to be ((LPMSG)lParam).
if (nCode != HC_ACTION) goto end; //ok, we're allowed to process the message
if (pmsg_lparam->message != WM_SYSCOMMAND) goto end; //the message is about a menu
if (pmsg_lparam->wParam != IDM_HIDEWINDOW) goto end; //said menu item is ours
PostMessage(FindWindow("WinHiderClass", "WinHider"), MSG_HOOKTRIGGERED, WH_GETMESSAGE, (LPARAM)pmsg_lparam->hwnd); //all conditions met, E.T. calls home.
end: //sorry about the use of goto, but i believe this is a legitimate use of it. it's not like you have to read a huge mess of spaghetti code. using the goto prevents the necessity of typing the next line after every if statement.
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
|
|
#4
|
|||
|
|||
|
yes, you are right now. Selecting menu , will always satisfy the first condition( in your prev. code).As a result other conditions will be bypassed.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > how to check if a bit flag is included in a word |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|