?
Solved

VB6.0, get the handle of an activex control on a form

Posted on 2011-02-22
11
Medium Priority
?
1,558 Views
Last Modified: 2012-05-11
Hello,

I have a form with an ActiveX control on it for a html editor window.  The activex control does not have an inbuilt hWnd property.

How do I find the handle of thso control so I can pass it to a spellchecker etc that requires the handle.

Code samples would be appreciated.

Thank-you.
0
Comment
Question by:jcwiatr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34960405
Use FindWindow API to get the hwnd of the form and then either use FindwindowEx API or EnumWindows API to get the hwnd of the activex control.

If you are unable to do it then upload the form.

Sid

ps: If you are an API fan like me, then I would suggest you to bookmark this page :)

http://allapi.mentalis.org/agnet/apiguide.shtml
0
 
LVL 46

Expert Comment

by:aikimark
ID: 34965970
have you tried iterating through the CONTROLS collection?  If not mistaken, most controls should have an hwnd property.
Dim ctlThing As Control
For Each ctlThing In Me.Controls
  If ctlThing.Name = "the activex control you are seeking" Then
    Debug.Print ctlThing.Name, ctlThing.hWnd
  End If
Next

Open in new window

0
 
LVL 1

Author Comment

by:jcwiatr
ID: 34966042
hi aikimark - sounds easy - on testing the statement -
For Each ctlThing In Me.Controls

generates an error on me.controls..

method or data method not found
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:jcwiatr
ID: 34966120
aikimark, my mistake, i got it working and am getting the name of the control but when I add, ctlThing.hwnd I am getting the error Object does not support this property or method.  This makes sense I guess given there is no internal hWnd for this control.  I will give the API calls a go.
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34966168
Can you upload your userform?

Sid
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34966169
Also what type of control is it?

Sid
0
 
LVL 1

Author Comment

by:jcwiatr
ID: 34966211
just a basic form at this stage with an ActiveX control pinedit.ocx which is a html editor control.  I need the handle so I can bind a spell checker to it.

I have uploaded the form and control.  The file pinedit.txt in the archive needs to be renamed to pinedit.ocx and registerd.

Cheers. Form1.zip
0
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 1000 total points
ID: 34966364
It seems like a user defined control created with IE and Scrollbars.

It doesn't have a property "hwnd" but spy++ did give me a hwnd.

I tried this code but since that control doesn't have a caption, I couldn't get the caption.

Here is the code that I tried.

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private 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

Private Declare Function GetWindowTextLength Lib "user32.dll" Alias _
"GetWindowTextLengthA" (ByVal hwnd As Long) As Long

Private Declare Function GetWindowText Lib "user32.dll" Alias _
"GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As _
String, ByVal cch As Long) As Long

Dim sInput As String
Dim hhhdc As Long, lhWndChild As Long
Dim textlen As Long '<~~ Length of text of title
Dim titleText As String '<~~ Text of the title
Dim slength As Long '<~~ Length of the returned string



Private Sub Command1_Click()
    '~~> Form Caption
    sInput = "Form1"
    
    '~~> Get Handle of the Form
    hhhdc = FindWindow(vbNullString, sInput)
    
    Debug.Print "Value of Parent Window " & titleText; " is , " & hhhdc
    
    '~~> loop through the Child Windows
    Do
        lhWndChild = FindWindowEx(hhhdc, lhWndChild, vbNullString, vbNullString)
        
        textlen = GetWindowTextLength(lhWndChild)
        titleText = Space(textlen + 1)
        '~~> Get the text of the window
        slength = GetWindowText(lhWndChild, titleText, textlen + 1)
        
        '~~> Extract information from the buffer
        titleText = Left(titleText, slength)
        
        Debug.Print "Value of Child Window " & titleText; " is , " & lhWndChild

    Loop While lhWndChild

End Sub

Open in new window


Sid
0
 
LVL 46

Expert Comment

by:aikimark
ID: 34966539
I wonder if the ActiveX control is merely a container and might not be capable of handling messages, so doesn't have hWnd.
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34966658
Yeah, seems like it is. It definitely has IE in it.

Sid
0
 
LVL 1

Author Comment

by:jcwiatr
ID: 34966849
Thanks guys. I think you are right about the container.  Points awarded based on code to get the handle.  But I dont think i will be able to bind our spellchecker to it because of its internals.
Thanks for all the input.

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 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