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

前端 未结 12 1494
小蘑菇
小蘑菇 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:25

    if you sure ButtonHandle are valid handle you can use pair WM_LBUTTONDOWN and WM_LBUTTONUP message instead of BN_CLICKED

    HWND ButtonHandle;
    if( (wnd = FindWindow(0, "Do you want to save?")) )
    {   
        SendMessage(ButtonHandle, WM_LBUTTONDOWN, MK_LBUTTON, 0);
        SendMessage(ButtonHandle, WM_LBUTTONUP, MK_LBUTTON, 0);
    }
    

提交回复
热议问题