Im trying to enable or diable every command button in a form. Im trying to use the Hwnd property of the form to get the form. This is how im doing it:
Public Sub CBEnable()
Dim c As CommandButton
Dim rtn As Long
rtn = GetWindowLong("918670", GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
For Each c In rtn
c.Enabled = True
But it hightlights
For Each c In rtn
and gives an error message : For Each may only itritate over a collection object or an array. What will be the correct way writing this?
08-07-2005, 07:38 PM
Changes them from Enabled to disabled back to Enabled....etc.
Dim b As CommandButton
For Each b In Me
b.Enabled = Not b.Enabled
That would work if it was the same form in which the code is being run. But im trying to enable and disable button in a completely different app. I know the hwnd of the app ( i created it loll ), that is why im trying to use the hwnd of that window. That is why im using GetWindowLong to get the window with that hwnd. What will the correct syntax be in that case?
08-07-2005, 08:35 PM
I'm not sure you can do it like this. The collection you need is the Controls collection, which can be retrieved by using the Controls property of the form:
For Each c In frmSomething.Controls
However, if the form is part of a different app, I don't think this property is exposed, so you can't access it. Getting the hWnd and getting an object reference are two quite different things... maybe there is a way, but it's not going to be this simple :(
The reason i was using GetWindow is beoz it uses the Hwnd property of a form to get it. That is how i want to get the form. I will have a look at other api's and see if they are of any use to me. :)
08-08-2005, 10:41 AM
You can use the FindWindowEx API to find windows within windows.
Use the classname of "ThunderCommandButton" if target app is in Design mode otherwise use "ThunderRT6CommandButton" when target app is compiled, to find the command buttons.
For each one you find, it will have its own window handle, you will want to use the EnableWindow() API to toggle its status on/off.
Obviously, this only works with VB6, Replace RT6 with RT5 in above name for VB5. To complicate things further, using this logic on other applications probably won't work, because their buttons can be anything, inlcuding the standard windows class of "BUTTON", custom usercontrols, or whatever. Not all buttons are command buttons in all applications.
08-08-2005, 10:59 AM
FindWindowEx tutorial here: