CODE IN DLL :
extern "C" __declspec(dllexport) bool install()
{
hHookcbt = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProc, hinst, 0);
hook = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)MouseProc, hinst, 0);
khook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)KeyboardProc, hinst, 0);
return TRUE;
}
LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0)
{
return CallNextHookEx(hook, nCode, wParam, lParam);
}
//char c = MapVirtualKey(wParam,MAPVK_VK_TO_CHAR);
switch (wParam)
{
case WM_LBUTTONUP:
SendMessage(whandle, 9, wParam, lParam);
break;
case WM_RBUTTONUP:
SendMessage(whandle, 0, wParam, lParam);
break;
default:
break;
}
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
CODE IN EXE: Using Mouse structure to get window handle of the mouse clicked window and it works all default applications eg:notepad,sticky notes but not on firefox,taskmanager,etc.
// SETTING THIS WINDOW HANDLE TO THE DLL
swh = (SetWindowHandle)GetProcAddress(hinst, "setwindowhandle");
if (!swh(hWnd))
{
printf("\nDLL FAILED TO ADDED THIS WINDOW HANDLE");
}
else{
printf("\nDLL ADDED THIS WINDOW HANDLE");
}
case 9:
mhs = (MOUSEHOOKSTRUCT*)lParam;
cout <<endl<< "x=" << mhs->pt.x<<" y="<<mhs->pt.y;
SelWinH = mhs->hwnd;
cout << endl << "Selected window process id=" << GetProcessId(SelWinH);
tid = GetWindowThreadProcessId(mhs->hwnd, &pid);
cout << endl << "tid =" << tid << " " << "pid = " << pid;
cout << endl << "---------------------------------------------------------------------------------";
break;
Here SelWinH stores the WHND of the mouse selected window . But when i clicked on the firefox browser it did not respond.