Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
%IDC_ComboBox = 500
%IDC_Button = 501
Global hDlg,hEdit As Dword, OldEditProc&
Function PBMain() As Long
Dim MyArray(3) As String
Array Assign MyArray() = "zero item", "one item", "two item", "three item"
Dialog New Pixels, 0, "ComboBox Test",300,300,200,200, %WS_OverlappedWindow, 0 To hDlg
Control Add ComboBox, hDlg, %IDC_ComboBox, MyArray(), 20,50,75,100
Control Add Button, hDlg, %IDC_Button, "Clear", 20,130,75,25
SubClassComboBoxEditControl
ComboBox Select hDlg, %IDC_ComboBox, 1
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local w,h As Long
Select Case Cb.Msg
Case %WM_InitDialog
PostMessage GetDlgItem(hDlg,%IDC_ComboBox),%CB_SeteditSel, 0, 3
Case %WM_Size
Dialog Get Client hDlg To w,h
Control Set Size hDlg, %IDC_ComboBox, w-40,h-60
Case %WM_Destroy
SetWindowLong hEdit, %GWL_WNDPROC, OldEditProc&
End Select
End Function
Sub SubClassComboBoxEditControl
Local ComboInfo As ComboBoxInfo
ComboInfo.cbSize = SizeOf(ComboBoxInfo)
GetComboBoxInfo(GetDlgItem(hDlg,%IDC_ComboBox), ByVal VarPtr(ComboInfo)) 'get data about combobox
hEdit = ComboInfo.hwndItem 'handle to edit control of combobox
OldEditProc& = SetWindowLong(hEdit, %GWL_WndProc, CodePtr(NewProc)) 'subclass a control
End Sub
Function NewProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Local iReturn As Long
Select Case Msg
Case %WM_GetDlgCode
If lParam = %NULL Then
iReturn = CallWindowProc(OldEditProc&, hWnd, Msg, wParam, lParam)
Function = iReturn Xor %DlgC_HasSetSel
Exit Function
End If
End Select
Function = CallWindowProc(OldEditProc&, hWnd, Msg, wParam, lParam)
End Function
'gbs_00780
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm