How can I simulate a button click given the handle to the button's window?

后端 未结 5 1181
星月不相逢
星月不相逢 2020-12-16 01:07

I want to simulate a click on a button located in a dialog box.

I have the handle to that window. This is an Abort/Retry/Ignore kind of window.

I don\'t wan

5条回答
  •  攒了一身酷
    2020-12-16 01:24

    Here is a complete function:

    void clickControl(HWND hWnd, int x, int y)
    {
        POINT p;
        p.x = x; p.y = y;
        ClientToScreen(hWnd, &p);
        SetCursorPos(p.x, p.y);
        PostMessage(hWnd, WM_MOUSEMOVE, 0, MAKELPARAM(x, y));
        PostMessage(hWnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(x, y));
        PostMessage(hWnd, WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(x, y));
    }
    

提交回复
热议问题