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

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

    //Send digit 4 to the already opened calc.exe

    HWND windowHandle;
    
    windowHandle = FindWindowA(NULL,"Calculator");
    
    if(windowHandle != 0)
       ret = EnumChildWindows(windowHandle,GetButtonHandle,0);
    
    BOOL CALLBACK GetButtonHandle(HWND handle, LPARAM)
    {
    char label[100];
    int size = GetWindowTextA(handle,label,sizeof(label));
    
    if(strcmp(label,"4") == 0)
    {
    PostMessage(handle ,WM_LBUTTONDOWN,(WPARAM)0x0001,0);
    PostMessage(handle ,WM_LBUTTONUP,(WPARAM)0x0001,0);
    
    PostMessage(handle ,WM_LBUTTONDOWN,(WPARAM)0x0001,0);
    PostMessage(handle ,WM_LBUTTONUP,(WPARAM)0x0001,0);
    
    return false;
    }
    return true;
    }
    

提交回复
热议问题