Click the yes button in a dialog box from another process?

Just starting out? Need help? Post your questions and find answers here.
Quin
Enthusiast
Enthusiast
Posts: 282
Joined: Thu Mar 31, 2022 7:03 pm
Location: United States
Contact:

Click the yes button in a dialog box from another process?

Post by Quin »

In my PB program, I'm running an executable that pops up a message box (not a MessageRequester because it's Python but it looks the same). I want my program to click the yes button automatically. However, SetForegroundWindow_() doesn't work. I use FindWindow_() to get the window handle after a small delay of 500 MS because the program takes a little bit to launch, then I called SetForegroundWindow_() on the hwnd. However, it returns 0. From looking at the docs, that's because it's part of another process. But how else would I do this?
Thanks for any help!
PB v5.40/6.10, Windows 10 64-bit.
16-core AMD Ryzen 9 5950X, 128 GB DDR5.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Click the yes button in a dialog box from another process?

Post by RASHAD »

1- Get the handle of the Python application
2- Get the rectangle dimensions of Python application
3- Get the x,y of the YES button
4- Set the Cursor position to the YES button
5- Run the mouse click event
Egypt my love
Quin
Enthusiast
Enthusiast
Posts: 282
Joined: Thu Mar 31, 2022 7:03 pm
Location: United States
Contact:

Re: Click the yes button in a dialog box from another process?

Post by Quin »

Hi,
Thanks for your reply! Can you provide some API documentation? I'm on Windows, but have no idea what functions to look for for this.
Thanks!
PB v5.40/6.10, Windows 10 64-bit.
16-core AMD Ryzen 9 5950X, 128 GB DDR5.
Axolotl
Enthusiast
Enthusiast
Posts: 435
Joined: Wed Dec 31, 2008 3:36 pm

Re: Click the yes button in a dialog box from another process?

Post by Axolotl »

I have never done this right now, so just off the top of my head, a few functions that could help, without warranty!

Code: Select all

SetForegroundWindow_()  
BringWindowToTop_() 
SetWindowPos_() ; with #HWND_TOP Or #HWND_TOPMOST 
SetActiveWindow_()  ; #WM_ACTIVATE 
SendMessage_() ; #WM_ACTIVATEAPP 
AttachThreadInput_() 
SetFocus_() 
GetWindowThreadProcessId_()  
If the window is active (by SetActiveWindow_() you can use something like this to simulate the user clicking a button.

Code: Select all

SendMessage_(hWnd, #BM_CLICK, 0, 0) 
Mostly running PureBasic <latest stable version and current alpha/beta> (x64) on Windows 11 Home
Post Reply