0
votes

this is an problem on windows platform. my windows is win 10 64 bit. i have an qt application and can find the window by findwindow. then i use postmessage from another process to simulate mouse click on the qt window, but this does not take effect. my code is as below.

void SimuClick(HWND hwnd, int x, int y)
{
    LPARAM point = MAKELPARAM(x, y);
    ::PostMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, point);
    ::PostMessage(hwnd, WM_LBUTTONUP, 0, point);
}

more details:

  1. the code takes effect on other window
  2. when i use the mouse to click the qt window. i can watch WM_LBUTTONDOWN and WM_LBUTTONUP messages posted to the qt window with spy++
  3. the qt window has WS_POPUP|WS_CAPTION|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX style
1
What does "the code takes effect in other window" mean? When you know your events are executed by another window then you should know where you have to search for the error. - user743414
Use SendInput instead - Dmitry Sazonov
@user743414 . "the code takes effect in other window" means the window not in qt application works well by postmessage to these windows. obviously, i can't distinguish the difference between the window in qt application and other non qt application windows. so i can't point out what's the error. - qianyi
@DmitrySazonov thanks for the advice. but SendInput not specify the window. if i want to simuclick take effect while the window is minimized, does SendInput works? - qianyi
I did some test. SendInput does not take effect as well. but I create an qt application with qt creator by myself, the PostMessage works on my own qt application. it's wired. does the app filter out the message by some method? - qianyi

1 Answers

1
votes

Finally, I find out what's the problem. The windows UIPI restriction block my message posted to the target process because the target process has a higher privilege than mine. I should set the uiAccess to true in manifest in link step.