|
-
Mar 8th, 2012, 05:48 AM
#1
Thread Starter
Member
Click control to get Handle (Winspector style)
Hi guys
Id like to be able to click a button on an external window and a text box on my vb6 program be populated with that buttons handle, similar to the winspector drag and drop process.
Im wondering if this is possible in VB6.
Mods - Please move if this should be in the VB6 forum.
Thanks
-
Jul 1st, 2012, 01:18 PM
#2
Re: Click control to get Handle (Winspector style)
No. Clicking on a button of another application (un-related to your VB project) has no effect on your VB6 program. If, however, you have control of that other window (i.e. the source code) then you can get the button's handle by having that app send your VB program the button's handle. If you do not have any control then to get the handle of that button you will need to first get the handle of the other window by calling FindWindow API with the title bar name. Once you have the window handle you will need to set up a enumeration function in your program that loops through all the sub windows until it finds the button you need and then get the handle from there. This is complex code and I am not going to write the code to do that now as I don't have the time but I suggest you check into this by searching for how to get the handle of another window on the net (Google will have hits).
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jul 2nd, 2012, 08:59 PM
#3
Re: Click control to get Handle (Winspector style)
 Originally Posted by ripps
Hi guys
Id like to be able to click a button on an external window and a text box on my vb6 program be populated with that buttons handle, similar to the winspector drag and drop process.
Im wondering if this is possible in VB6.
You'll need to use a few API calls. Add a vb timer to your form. In the timer use WindowFromPoint to get the handle of the control under the mouse cursor, use GetAsyncKeyState to check if the mouse button was clicked (I'd use a right or middle mouse click so you don't fire the apps button), when mouse click is detected stop the timer and set your text box to the value returned from WindowFromPoint.
-
Jul 3rd, 2012, 12:22 AM
#4
Re: Click control to get Handle (Winspector style)
How's he going to know the X and Y for the WindowFromPoint (X, Y) function?
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jul 3rd, 2012, 08:44 AM
#5
Re: Click control to get Handle (Winspector style)
 Originally Posted by jmsrickland
How's he going to know the X and Y for the WindowFromPoint (X, Y) function?
GetCursorPos , I thought that would be obvious! .
-
Jul 3rd, 2012, 11:31 AM
#6
Re: Click control to get Handle (Winspector style)
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jul 3rd, 2012, 12:18 PM
#7
Re: Click control to get Handle (Winspector style)
OK, taking what Edgemeal said here is the code that works
Set your timer to Interval = 100
Code:
Private Type POINTAPI
x As Long
y As Long
End Type
Private MyPointAPI As POINTAPI
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Const VK_RBUTTON = &H2
Private ButtonhWnd As Long
Private Sub Timer1_Timer()
If GetAsyncKeyState(VK_RBUTTON) Then
GetCursorPos MyPointAPI
ButtonhWnd = WindowFromPoint(ByVal MyPointAPI.x, ByVal MyPointAPI.y)
Text1.Text = ButtonhWnd
Timer1.Enabled = False
End If
End Sub
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|