Print Page | Close Window

Getting the child handle

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Controls
Forum Description: Topics Related to Codejock Controls
URL: http://forum.codejock.com/forum_posts.asp?TID=18076
Printed Date: 27 November 2024 at 7:34am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Getting the child handle
Posted By: eSynaptic
Subject: Getting the child handle
Date Posted: 19 March 2011 at 9:23pm
I am dynamically loading a form as a tab item. When I hit the close button on the tab, how can I get the handle of the form so I can unload it when the tab closes?

example:

'load the form as a tab item
With wndTab
 
 Set nTab = .InsertItem(0, "Example Tab", form1.hWnd, 0
 
End With

Now... using the NavigateButtonClick event, how can I get the loaded form to unload it?

Thank you!!

Jason




Replies:
Posted By: eSynaptic
Date Posted: 19 March 2011 at 10:06pm
This is what I am doing... is there an easier way?

Private Sub wndTab_NavigateButtonClick(ByVal Id As Long, Cancel As Variant)
On Error Resume Next
Dim i As Long
Dim szTag As String
Dim oFrm As Form

szTag = wndTab.Selected.Tag

'find the tag name
For i = Forms.Count - 1 To 1 Step -1
    DoEvents
    
    If Forms(i).Tag = szTag Then
      Unload Forms(i)
    End If
Next

End Sub



Posted By: Xander75
Date Posted: 21 March 2011 at 6:25am
Hi,

Use the following code to resolve the issue you have of closing the child form.


Private Sub wndTab_NavigateButtonClick(ByVal Id As Long, Cancel As Variant)
    Dim i As Long

    For i = Forms.Count - 1 To 0 Step -1
        If Forms(i).hWnd = wndTab.Selected.Handle Then
            Unload Forms(i)
        End If
    Next
End Sub



-------------
Product: Xtreme SuitePro (ActiveX) v15.3.1
Platform: Windows 7 64-bit (SP1) Professional Edition
Languages: C#.Net using Visual Studio 2012 & Visual Basic 6.0 (SP6)


Posted By: Xander75
Date Posted: 21 March 2011 at 7:12am
Or if you'd prefer to use an API, you can do this with one line of code in the "NavigateButtonClick" event...


Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Const WM_CLOSE = &H10

Private Sub Form_Load()
    wndTab.ShowCloseItemButton = xtpTabItemButtonSelected
    wndTab.InsertItem 0, "Example Tab", Form2.hwnd, 0
    wndTab.InsertItem 1, "Example Tab", Form3.hwnd, 0
End Sub

Private Sub wndTab_NavigateButtonClick(ByVal Id As Long, Cancel As Variant)
    PostMessage wndTab.Selected.Handle, WM_CLOSE, 0&, 0&
End Sub



-------------
Product: Xtreme SuitePro (ActiveX) v15.3.1
Platform: Windows 7 64-bit (SP1) Professional Edition
Languages: C#.Net using Visual Studio 2012 & Visual Basic 6.0 (SP6)



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net