Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
'The following compilable code demonstrates a dialog with a single
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
%IDC_ComboA = 500 : %IDC_ComboB = 501 : %IDC_ComboC = 502 : %IDC_Button = 503
%IDM_Cut = 600 : %IDM_Copy = 601 : %IDM_Paste = 602
Global hDlg,hContextEdit As Dword
Global hComboA,hComboB,hComboC As Dword
Global hComboAEdit,hComboBEdit,hComboCEdit As Dword
Global OldComboAEditProc&,OldComboBEditProc&,OldComboCEditProc&
Function PBMain() As Long
Dim MyArray(3) As String
Array Assign MyArray() = "zero", "one", "two", "three"
Dialog New Pixels, 0, "ComboBox Test",300,300,200,200, %WS_OverlappedWindow, 0 To hDlg
Control Add ComboBox, hDlg, %IDC_ComboB, MyArray(), 20,50,75,100
Control Add ComboBox, hDlg, %IDC_ComboA, MyArray(), 20,10,75,100
Control Add ComboBox, hDlg, %IDC_ComboC, MyArray(), 20,90,75,100
Control Add Button, hDlg, %IDC_Button, "Clear", 20,130,75,25
SubClassComboBoxControls
CreateContextMenu 'just to show that subclass is working
ComboBox Select hDlg, %IDC_ComboA, 1 : ComboBox Select hDlg, %IDC_ComboB, 2 : ComboBox Select hDlg, %IDC_ComboC, 3 'pick a value in each combobox
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local w,h As Long
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
PostMessage hComboAEdit,%CB_SeteditSel, 0, Mak(Long,-1,0)
PostMessage hComboBEdit,%CB_SeteditSel, 0, Mak(Long,-1,0)
PostMessage hComboCEdit,%CB_SeteditSel, 0, Mak(Long,-1,0)
End Select
Case %WM_Size
Dialog Get Client hDlg To w,h
Control Set Size hDlg, %IDC_ComboA, w-40,20
Control Set Size hDlg, %IDC_ComboB, w-40,20
Case %WM_Destroy
SetWindowLong hComboAEdit, %GWL_WNDPROC, OldComboAEditProc&
SetWindowLong hComboBEdit, %GWL_WNDPROC, OldComboBEditProc&
SetWindowLong hComboCEdit, %GWL_WNDPROC, OldComboCEditProc&
End Select
End Function
Sub SubClassComboBoxcontrols
Local ComboInfo As ComboBoxInfo
Control Handle hDlg, %IDC_ComboA To hComboA
Control Handle hDlg, %IDC_ComboB To hComboB
Control Handle hDlg, %IDC_ComboC To hComboC
ComboInfo.cbSize = SizeOf(ComboBoxInfo)
GetComboBoxInfo(hComboA, ByVal VarPtr(ComboInfo)) 'get data about combobox
hComboAEdit = ComboInfo.hwndItem 'handle to edit control of combobox
OldComboAEditProc& = SetWindowLong(hComboAEdit, %GWL_WndProc, CodePtr(NewComboAEditProc)) 'subclass a control
GetComboBoxInfo(hComboB, ByVal VarPtr(ComboInfo)) 'get data about combobox
hComboBEdit = ComboInfo.hwndItem 'handle to edit control of combobox
OldComboBEditProc& = SetWindowLong(hComboBEdit, %GWL_WndProc, CodePtr(NewComboBEditProc)) 'subclass a control
GetComboBoxInfo(hComboC, ByVal VarPtr(ComboInfo)) 'get data about combobox
hComboCEdit = ComboInfo.hwndItem 'handle to edit control of combobox
OldComboCEditProc& = SetWindowLong(hComboCEdit, %GWL_WndProc, CodePtr(NewComboCEditProc)) 'subclass a control
End Sub
Function NewComboAEditProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
Case %WM_KillFocus
SendMessage hWnd,%CB_SeteditSel, 0, Mak(Long,-1,0)
Case %WM_ContextMenu
TrackPopupMenu hContextEdit, %TPM_LeftAlign, Lo(Integer,LParam), Hi(Integer,LParam), 0, hDlg, ByVal 0
Function = 0 : Exit Function 'use if no further message processing is required
End Select
Function = CallWindowProc(OldComboAEditProc&, hWnd, Msg, wParam, lParam) 'send unprocessed messages to the original procedure
End Function
Function NewComboBEditProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
Case %WM_KillFocus
SendMessage hWnd,%CB_SeteditSel, 0, Mak(Long,-1,0)
Case %WM_ContextMenu
TrackPopupMenu hContextEdit, %TPM_LeftAlign, Lo(Integer,LParam), Hi(Integer,LParam), 0, hDlg, ByVal 0
Function = 0 : Exit Function 'use if no further message processing is required
End Select
Function = CallWindowProc(OldComboBEditProc, hWnd, Msg, wParam, lParam) 'send unprocessed messages to the original procedure
End Function
Function NewComboCEditProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
Case %WM_KillFocus
SendMessage hWnd,%CB_SeteditSel, 0, Mak(Long,-1,0)
Case %WM_ContextMenu
TrackPopupMenu hContextEdit, %TPM_LeftAlign, Lo(Integer,LParam), Hi(Integer,LParam), 0, hDlg, ByVal 0
Function = 0 : Exit Function 'use if no further message processing is required
End Select
Function = CallWindowProc(OldComboCEditProc, hWnd, Msg, wParam, lParam) 'send unprocessed messages to the original procedure
End Function
Sub CreateContextMenu
Menu New PopUp To hContextEdit
Menu Add String, hContextEdit, "Cut", %IDM_Cut, %MF_Enabled
Menu Add String, hContextEdit, "Copy", %IDM_Copy, %MF_Enabled
Menu Add String, hContextEdit, "Paste", %IDM_Paste, %MF_Enabled
End Sub
' SendMessage hComboAEdit,%CB_SeteditSel, 0, Mak(Long,-1,0)
' SendMessage hComboBEdit,%CB_SeteditSel, 0, Mak(Long,-1,0)
' SendMessage hComboCEdit,%CB_SeteditSel, 0, Mak(Long,-1,0)
' SendMessage hComboA,%CB_SeteditSel, 0, Mak(Long,-1,0)
' SendMessage hComboB,%CB_SeteditSel, 0, Mak(Long,-1,0)
' SendMessage hComboC,%CB_SeteditSel, 0, Mak(Long,-1,0)
'gbs_00774
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm