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_Combo = 500
%IDC_Button = 501
Global hDlg As Dword, OldComboProc&
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 Button, hDlg, %IDC_Button, "Push", 20,10,150,25
Control Add ComboBox, hDlg, %IDC_Combo, MyArray(), 20,40,75,100
OldComboProc& = SetWindowLong(GetDlgItem(hDlg,%IDC_Combo), %GWL_WndProc, CodePtr(NewComboProc))
ComboBox Select hDlg, %IDC_Combo, 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_Size
Dialog Get Client hDlg to w,h
Control Set Size hDlg, %IDC_Combo, w-40, 100
Case %WM_InitDialog
PostMessage GetDlgItem(hDlg,%IDC_Combo),%CB_SetEditSel, 0,3 'starting selection
Case %WM_Destroy
SetWindowLong GetDlgItem(hDlg,%IDC_Combo), %GWL_WNDPROC, OldComboProc&
End Select
End Function
Function NewComboProc(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(OldComboProc&, hWnd, Msg, wParam, lParam)
Function = iReturn Xor %DlgC_HasSetSel
Exit Function
End If
End Select
Function = CallWindowProc(OldComboProc&, hWnd, Msg, wParam, lParam) 'send unprocessed messages to the original procedure
End Function
'gbs_00781
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm