0

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.

  • I am trying to create a virtual keyboard where i need a window handle of the each window i click .So if i click on firefox browser it did not return window handle . – ganapathy secrets Jul 09 '15 at 19:56

1 Answers1

-1

What about calling GetForegroundWindow() after the mouse click ? It will return the handle to window you've clicked.

Lukasas
  • 139
  • 8
  • thank you for reply , But it doesn't work .first mouse click should return a mouse click message to the hook registered window then only i can call GetForegroundWindow() . – ganapathy secrets Jul 10 '15 at 03:49
  • Firefox uses window-less controls. There will not be a native window for the majority of windows you see in the browser window. – IInspectable Oct 24 '16 at 02:10