Solved

HELP?? :Obtaining an Object Name from a HWND

Posted on 1998-11-12
11
240 Views
Last Modified: 2010-04-30
I desperately need to know how to obtain an object name from a hwnd.  Ie. I have the hwnd of the active form (of another application) and now I need to loop through all controls on that form and look for a property of a particular type of control.

Some of the code is listed below:
Option Explicit
Declare Function GetForegroundWindow& Lib "user32" ()

private sub find_control()
dim ret as long
ret = getforegroundwindow()
'..now I have the hwnd of that form
'..I would like to do the following
'..dim myobj as object
'..for each myobj in formname.hwnd
'..if typeof(myobj) is textbox then
'..it is a text box
'...etc
'..endif
'..loop
end sub

Does anyone out there know of the API of VB proc that I use????  Please help!?

Tom
0
Comment
Question by:tommy_boy
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1444691
I can be very short. It is impossible to get back from a hwnd to a control handle.
What you can do is sendmessage to the control. So for example, when it is an editbox you can send some messages to it.

The API FindWindowEx can help you. The first hwnd must be the parent window. The second hwnd is the previous found window in your name. The string parameters are the classnames of the windows. In your case "Edit". This allows you to find the window handles. Now you can send the window message.

Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

0
 
LVL 1

Author Comment

by:tommy_boy
ID: 1444692
Mirkwood...

Obtaining the windows handle of any control loaded on any form in any application is not the problem, as I know these API's.  Also sending a message to the form or control is not what I require.  Obtaining the name is.  I know it must be possible as there are applications out there that do this.

Thanks anyway...

0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1444693
Could you name one application that does what you are saying?
0
 
LVL 1

Author Comment

by:tommy_boy
ID: 1444694
Ok.. to explain the overview of what I am trying to achieve.  I need to be able to simulate MouseExit (Java, Access, VB tooltips etc).  For this example, let's say I am making a custom tooltip.  I can detect when the mouse is moved off a control, but if the user moves the mouse rapidly or the controls are very close together, more than one 'ToolTip' is displayed at the same time.  With Access or Java, if the user moves from one control to the next, only one event is fired, even if the controls are very close together.

Therefore, the only way I can be sure that only one 'ToolTip' is displayed for this type of control, is to loop through those controls and check for a 'displayed' property.  

Do you have another possible solution?  Do you know of a MouseExit API (not Desaware - I know they have a custom control that does this)?


0
 
LVL 1

Expert Comment

by:raygibbins
ID: 1444695
The following function will loop thru' all the forms and controls in a project and find and return the object name

Public Function GetControlName(ByVal hWnd As Long)
    Dim intFormNum As Integer
    Dim intControlNum As Integer
    For intFormNum = 0 To Forms.Count - 1
        If Forms(intFormNum).hWnd = hWnd Then
            GetControlName = Forms(intFormNum).Name
            Exit Function
        End If
        For intControlNum = 0 To Forms(intFormNum).Controls.Count - 1
            On Error Resume Next
            If Forms(intFormNum).Controls(intControlNum).hWnd = hWnd Then
                If Err.Number = 0 Then
                    GetControlName = Forms(intFormNum).Controls(intControlNum).Name
                End If
                Exit Function
            End If
        Next intControlNum
    Next intFormNum
GetControlName = "No Control"
End Function

stick Text1 on a form and run

Private Sub Form_Load()
    MsgBox GetControlName(Text1.hWnd)
End Sub

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 13

Expert Comment

by:Mirkwood
ID: 1444696
Raygibbins: Tommy Boy was talking about in another application. So the forms collection will never work.
0
 
LVL 1

Author Comment

by:tommy_boy
ID: 1444697
Yes as Mirkwood said, obtaining the name of a control inside THAT project is no problem.  Obtaining the name of a control outside that project, is.
0
 

Expert Comment

by:KRV
ID: 1444698
As far as I am aware the 3rd party software uses code similar to the first answer but before displaying the tooltip there is a check and balance by using the mouse API functions to establish that the mouse is actually over the same hdc as the sendmsg struct is calling
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 100 total points
ID: 1444699
I think that you should face the fact that it is not possible.
0
 
LVL 7

Expert Comment

by:Inteqam
ID: 2615095
emmmmmmmmmmm....

10 points for nothing.

:o)

0
 
LVL 7

Expert Comment

by:Inteqam
ID: 2615698
Strange ,

I Recieved the following

Inteqam has added a new comment to the question.
If you'd like to read Inteqam's comments, enter Experts Exchange at
the following URL:
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10097974 
<http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10097974 >
*      or -
http://www.experts-exchange.com/Q.10097974-2615095
<http://www.experts-exchange.com/Q.10097974-2615095>  (non-cookie
login)

for the comment above
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now