Author | Message | Time |
---|---|---|
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? | February 26, 2006, 8:41 PM |
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). | February 26, 2006, 8:44 PM |
Quarantine | Wouldn't you need Spy++ everytime you opened the application? | February 27, 2006, 1:20 AM |
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: [code] 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) [/code] 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. | February 27, 2006, 1:31 AM |
Topaz | [quote author=K link=topic=14374.msg147174#msg147174 date=1141003895] 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: [code] 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) [/code] 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. [/quote] WOW! Thanks! | February 27, 2006, 1:52 AM |
LivedKrad | Solved. | February 27, 2006, 2:21 AM |