Monday, May 14, 2007

A Easy message filter to a Win32 application vc++.

IF you know c# or vc.Net you can see interfaces like IMessageFilter , which allows to filter a particular message from the application.

So this can be done in win32 with some lines of coding , no need for any interface :)).
I don't want to explain anything more than these code snippets.We know every win32 app has a message loop. it may be look like this

while(GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
   TranslateMessage(&msg);
   DispatchMessage(&msg);
}
}

So we can add filter , which will filter all WM_LBUTTONDOWN message from this application by a mere checking, like
while (GetMessage(&msg, NULL, 0, 0))
{
 if (msg.message != WM_LBUTTONDOWN && !TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
 {
   TranslateMessage(&msg);
   DispatchMessage(&msg);
  }
}

Thats all.. 

No comments: