Date: 02-16-2022
Return to Index
created by gbSnippets
'Gets handle to window's parent. Useful in cases where an app has multiple
'dialogs or where child windows have child windows themselves (such as the
'edit box used in a ComboBox or TreeView).
'Primary Code:
hParent = GetParent (hChild)
'Compilable Example: (Jose Includes)
'demonstrates how GetParent is used to determine the parent of the edit control
'used by the ComboBox or TreeView controls. Type something in the ComboBox
'and press Enter, or triple-click an item in the TreeView.
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Include "CommCtrl.inc"
#Resource "gbsnippets.pbr"
%IDC_TreeView = 200 : %IDC_ComboBox = 210
Global hDlg As Dword, hTreeView as Dword, hComboBox as Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Label, hDlg, 100, "Label", 20,10,150,20, %WS_Border
AddComboBox : AddTreeView
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_Command
Select Case CB.Ctl
Case %IdOk 'pressing Enter in TreeView or ComboBox edit box
If CB.Ctlmsg = %BN_Clicked Then
Select Case GetParent(GetFocus) 'gets parent of the control which has the focus
Case hTreeView
TreeView_EndEditLabelNow hTreeView, %False
MsgBox "TreeView edit closed!"
Case hComboBox
Control Send hDlg, %IDC_Combobox, %CB_SetCurSel, 0,0
MsgBox "ComboBox edit closed!"
End Select
Function = 1
End If
End Select
End Select
End Function
Sub AddTreeView
Local hItem as Dword, hTemp as Dword, hTemp2 as Dword, Style&
Style& = %TVS_TrackSelect Or %TVS_HasLines Or %TVS_HasButtons Or %TVS_LinesAtRoot Or %TVS_ShowSelAlways Or %WS_TabStop Or %TVS_EditLabels
Control Add TreeView, hDlg, %IDC_TreeView, "", 20,80,150,100, Style&, %WS_Ex_ClientEdge Or %WS_Ex_Left
TreeView Insert Item hDlg, %IDC_TreeView, 0, %TVI_Last, 0,0,"Root" To hItem
TreeView Insert Item hDlg, %IDC_TreeView, hItem, %TVI_Last, 0,0,"Mother" To hTemp
TreeView Insert Item hDlg, %IDC_TreeView, hTemp, %TVI_Last, 0,0,"Dan" To hTemp2
TreeView Set Expanded hDlg, %IDC_TreeView, hItem, %True
TreeView Set Expanded hDlg, %IDC_TreeView, hTemp, %True
Control Handle hDlg, %IDC_TreeView To hTreeView
End Sub
Sub AddComboBox
Dim MyArray(3) as String
MyArray(0) = "here!" : MyArray(1)= "go" : MyArray(2) = "items" : MyArray(3)= "ListBox"
Control Add ComboBox, hDlg, %IDC_ComboBox,MyArray(), 20,40, 100,60
Control Handle hDlg, %IDC_ComboBox To hComboBox
End Sub
'gbs_00025
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm