• Welcome to Valhalla Legends Archive.
 

[Solved] Enabling a button

Started by LivedKrad, February 26, 2006, 02:41 PM

Previous topic - Next topic

LivedKrad

Is it possible to enable a button on another program's form? I was told that the API EnableWindow() could do this, but one of the parameters is obviously a handle. I don't know how to grab the handle of a button on a remote form. Can anyone assist?

K

Use FindWindow to find the top level window.  Use FindWindowExto enumerate through the child windows until you have found the button.  You will need to know some information about the windows, which you can find with Spy++ (which comes with Visual Studio).

Warrior

Wouldn't you need Spy++ everytime you opened the application?
Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?

K

No.  You just need to know the window text and/or class name of the main window, and the text and/or class name of the child window.  If there is more than one child with the same class at the same level in the window heirarchy, then you just need to call FindWindowEx() with the appropriate arguments to enumerate the siblings and find the correct one.

For example, the following code will find the "Defragment" button in the Windows XP Disk Defragmenter:


Dim mmcmainframe As Long, mdiclient As Long, mmcchildfrm As Long
Dim mmcviewwindow As Long, mmcocxviewwindow As Long, atlaxwinex As Long
Dim atlffa As Long, button As Long
mmcmainframe = FindWindow("mmcmainframe", vbNullString)
mdiclient = FindWindowEx(mmcmainframe, 0&, "mdiclient", vbNullString)
mmcchildfrm = FindWindowEx(mdiclient, 0&, "mmcchildfrm", vbNullString)
mmcviewwindow = FindWindowEx(mmcchildfrm, 0&, "mmcviewwindow", vbNullString)
mmcocxviewwindow = FindWindowEx(mmcviewwindow, 0&, "mmcocxviewwindow", vbNullString)
atlaxwinex = FindWindowEx(mmcocxviewwindow, 0&, "atlaxwinex", vbNullString)
atlffa = FindWindowEx(atlaxwinex, 0&, "atl:000007ff7236a190", vbNullString)
button = FindWindowEx(atlffa, 0&, "button", vbNullString)
button = FindWindowEx(atlffa, button, "button", vbNullString)


And as I should have mentioned before, there is this nifty application (which I just used to create that code!) which will generate the code for you.

topaz

Quote from: K on February 26, 2006, 07:31 PM
No. You just need to know the window text and/or class name of the main window, and the text and/or class name of the child window. If there is more than one child with the same class at the same level in the window heirarchy, then you just need to call FindWindowEx() with the appropriate arguments to enumerate the siblings and find the correct one.

For example, the following code will find the "Defragment" button in the Windows XP Disk Defragmenter:


Dim mmcmainframe As Long, mdiclient As Long, mmcchildfrm As Long
Dim mmcviewwindow As Long, mmcocxviewwindow As Long, atlaxwinex As Long
Dim atlffa As Long, button As Long
mmcmainframe = FindWindow("mmcmainframe", vbNullString)
mdiclient = FindWindowEx(mmcmainframe, 0&, "mdiclient", vbNullString)
mmcchildfrm = FindWindowEx(mdiclient, 0&, "mmcchildfrm", vbNullString)
mmcviewwindow = FindWindowEx(mmcchildfrm, 0&, "mmcviewwindow", vbNullString)
mmcocxviewwindow = FindWindowEx(mmcviewwindow, 0&, "mmcocxviewwindow", vbNullString)
atlaxwinex = FindWindowEx(mmcocxviewwindow, 0&, "atlaxwinex", vbNullString)
atlffa = FindWindowEx(atlaxwinex, 0&, "atl:000007ff7236a190", vbNullString)
button = FindWindowEx(atlffa, 0&, "button", vbNullString)
button = FindWindowEx(atlffa, button, "button", vbNullString)


And as I should have mentioned before, there is this nifty application (which I just used to create that code!) which will generate the code for you.

WOW! Thanks!
RLY...?

LivedKrad

#5
Solved.