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 = 601 : %IDC_Edit = 602
%IDM_EditCut = 603 : %IDM_EditCopy = 604
%IDM_EditPaste = 605 : %IDM_EditDelete = 606
Global hDlg, hCombo, hComboEdit, hContextEdit As Dword, OldEditProc As Long
Function PBMain() As Long
Dim MyArray(3) As String
Array Assign MyArray() = "zero", "one", "two", "three"
Dialog New Pixels, 0, "ComboBox Context Menu",300,300,200,100, %WS_SysMenu, 0 To hDlg
Control Add ComboBox, hDlg, %IDC_ComboBox, MyArray(), 10,20,150,100
Control Handle hDlg, %IDC_ComboBox to hCombo
ComboBox Select hDlg, %IDC_ComboBox, 1
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local ComboInfo As ComboBoxInfo
Select Case CB.Msg
Case %WM_InitDialog
CreateContextMenu
ComboInfo.cbSize = SizeOf(ComboBoxInfo)
GetComboBoxInfo(hCombo, ByVal VarPTR(ComboInfo)) 'get data about combobox
hComboEdit = ComboInfo.hwndItem 'handle to edit control of combobox
OldEditProc = SetWindowLong(hComboEdit, %GWL_WndProc, Codeptr(NewProc)) 'subclass a control
Case %WM_Command
Select Case Cb.Ctl
Case %IDM_EditCut : SendMessage hComboEdit, %WM_CUT, 0, 0
Case %IDM_EditCopy : SendMessage hComboEdit, %WM_COPY, 0, 0
Case %IDM_EditPaste : SendMessage hComboEdit, %WM_PASTE, 0, 0
Case %IDM_EditDelete : SendMessage hComboEdit, %WM_CLEAR, 0, 0
End Select
Case %WM_Destroy
SetWindowLong hComboEdit, %GWL_WNDPROC, OldEditProc
End Select
End Function
Function NewProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
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(OldEditProc, 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_EditCut, %MF_Enabled
Menu Add String, hContextEdit, "Copy", %IDM_EditCopy, %MF_Enabled
Menu Add String, hContextEdit, "Paste", %IDM_EditPaste, %MF_Enabled
Menu Add String, hContextEdit, "Delete", %IDM_EditDelete, %MF_Enabled
End Sub
'gbs_00783
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm