Programmatically press a button on another application (C, Windows)

前端 未结 12 1385
小蘑菇
小蘑菇 2021-01-30 14:47

I\'m trying to use the following code to press a button on my other application:

HWND ButtonHandle;
if( (wnd = FindWindow(0, \"Do you want to save?\")) )
{   
           


        
12条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 15:34

    If you can raise the window containing the button you can send raw mouse event to a position within the boundaries of button.

    There are two function to simulate mouse event SendInput and mouse_event. I recommend using mouse_event function. To raise a window you can use ShowWindow. I don't know how to get the handle of a button, but if you have its hWnd its easy to find its absolute position using GetWindowRect function. Try using these, if you run into any problems I will be glad to help.

    Or define a custom WM within your application window to handle save request. WM_CUSTOM or WM_USER (cant remember which) marks the start of user defined window messages.

提交回复
热议问题