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!
Click the yes button in a dialog box from another process?
Click the yes button in a dialog box from another process?
PB v5.40/6.10, Windows 10 64-bit.
16-core AMD Ryzen 9 5950X, 128 GB DDR5.
16-core AMD Ryzen 9 5950X, 128 GB DDR5.
Re: Click the yes button in a dialog box from another process?
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
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
Re: Click the yes button in a dialog box from another process?
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!
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.
16-core AMD Ryzen 9 5950X, 128 GB DDR5.
Re: Click the yes button in a dialog box from another process?
I have never done this right now, so just off the top of my head, a few functions that could help, without warranty!
If the window is active (by SetActiveWindow_() you can use something like this to simulate the user clicking a button.
Code: Select all
SetForegroundWindow_()
BringWindowToTop_()
SetWindowPos_() ; with #HWND_TOP Or #HWND_TOPMOST
SetActiveWindow_() ; #WM_ACTIVATE
SendMessage_() ; #WM_ACTIVATEAPP
AttachThreadInput_()
SetFocus_()
GetWindowThreadProcessId_()
Code: Select all
SendMessage_(hWnd, #BM_CLICK, 0, 0)
Mostly running PureBasic <latest stable version and current alpha/beta> (x64) on Windows 11 Home