Click to See Complete Forum and Search --> : C++ Winapi - Hooks


zaryk
June 22nd, 2009, 07:30 AM
Could someone explain how to process the PostMessage within the main program?


//Dll
LRESULT CALLBACK DesktopHook(int nCode, WPARAM wParam, LPARAM lParam )
{
if (nCode < 0)
{
return CallNextHookEx(desktopHook, nCode, wParam, lParam);
}

POINT pt = ((MOUSEHOOKSTRUCT*)lParam)->pt;
cursorWindow = WindowFromPoint(pt);

if (cursorWindow == desktopWindow)
{
switch (wParam)
{
case WM_LBUTTONDBLCLK:
{
PostMessage(MainWindow, WM_LBUTTONDBLCLK, 0, MAKELPARAM(pt.x, pt.y));
}
break;
}
}
return CallNextHookEx(desktopHook, nCode, wParam, lParam);
}

_Superman_
June 23rd, 2009, 10:50 AM
Simply add a WM_LBUTTONDBLCLK case in the switch statement of the window procedure identified by the handle MainWindow.

If you're using MFC, it adds the OnLButtonDblClk function in your window class.
You can use the class view properties wizard to add this function.

zaryk
June 23rd, 2009, 12:47 PM
Alright. Thanks for confirming that for me. I tried it before posting here, but it seems like it hadn't done anything. Ill keep working at it, though. If I need some more help, Ill post. Thanks.

Edit: Works only when clicking within Main Program.....After removing if (cursorWindow == desktopWindow) that is.

So Apparently, its not finding DesktopWindow and only doing anything when I click Main Program window.

Edit: Moved a variable to a different location. Receives message on desktop. But, also receives message when clicking on Main Program window after re-adding if (cursorWindow == desktopWindow).

Edit: Alright. Everythings working correctly. Thanks again.