Results 1 to 14 of 14

Thread: hWnd of Control

  1. #1

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274

    hWnd of Control

    I have an activex control which doesnt have any hWnd property, how can I get its handle.

  2. #2
    Megatron
    Guest
    Use the FindWindowEx function.
    Code:
    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
    
    ''Usage
    
    hwndctl = FindWindowEx(Me.hWnd, 0, "ClassName", vbNullString)

  3. #3

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    Code:
    wHandle = FindWindowEx(Me.hWnd, 0, "ThunderRT6TextBox", vbNullString)
    I dont know why its returning 0,

  4. #4
    Matthew Gates
    Guest
    Change ThunderRT6TextBox to ThunderTextBox.

  5. #5

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    But the classname is not ThunderTextBox, I got its classname by enumerating all the child windows. I think there is some other problem.

  6. #6
    Matthew Gates
    Guest
    For me, the classname is ThunderTextBox, does it work for you? If it does, why you complainin'?

  7. #7
    Megatron
    Guest
    Relax. ThunderRT6ControlName is the classname given when you EXE is compiled, and ThunderControlName is the classname given when working in the IDE.

    Before you use FindWindow, check and make sure if there is an easier way of getting the hWnd (via the hwnd propety)
    Code:
    hwndctl = MyControl.HWnd

  8. #8
    Megatron
    Guest
    Also, one question. Are you creating this yourself? (i.e: an ActiveX project)

  9. #9

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    The problem is that its a third party control and it doesnt have any hWnd property and the ThunderTextbox is not working for me, and the classname is ThunderRT6Textbox at design time.

  10. #10

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    I have attached the ocx with this post, I would be really thankful if anybody can disable the double click event for this control.
    Attached Files Attached Files

  11. #11
    Megatron
    Guest
    Code:
    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 Sub Command1_Click()
    
        h = FindWindowEx(FindWindowEx(hWnd, 0, "ThunderRT6UserControlDC", vbNullString), 0, "ThunderRT6TextBox", vbNullString)
        Print h
        
    End Sub

  12. #12
    Megatron
    Guest
    Now to subclass it:

    Add to a Module
    Code:
    Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
    Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Const GWL_WNDPROC = (-4)
    Const WM_LBUTTONDBLCLK = &H203
    Public hwndctl As Long
    Global WndProcOld As Long
    
    Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    
        If wMsg = WM_LBUTTONDBLCLK Then Exit Function
      
        WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
        
    End Function
    
    Sub SubClassWnd(hwnd As Long)
        WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
    End Sub
    
    Sub UnSubclassWnd(hwnd As Long)
        SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
        WndProcOld& = 0
    End Sub
    Add to a Form
    Code:
    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 Sub Form_Load()
    
        hwndctl = FindWindowEx(FindWindowEx(hwnd, 0, "ThunderRT6UserControlDC", vbNullString), 0, "ThunderRT6TextBox", vbNullString)
        SubClassWnd hwndctl
        
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        
        UnSubclassWnd hwndctl
        
    End Sub

  13. #13

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    Thanks a lot, but can you please tell me why you called the findwindowex function twice? and what should I do if I want to subclass all of these textboxes on my form?

  14. #14
    Megatron
    Guest
    The reason we call it twice is because ThunderRT6TextBox is a child of ThunderRT6UserControlDC, and this is a child of our main form. In other words, ThunderRT6TextBox is a grand-child of our form.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width