Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#COMPILE EXE
#DIM ALL
#INCLUDE "WIN32API.INC"
'--------------------------------------------------------------------
%IDC_COMBOBOX1 = 151
GLOBAL ghDlg, ghCbFocus, ghCBList, gOldProc AS DWORD
'====================================================================
FUNCTION PBMAIN () AS LONG
DIALOG NEW 0, "CB Right-Click test",,, 180, 65, %WS_CAPTION OR %WS_SYSMENU, 0 TO ghDlg
'------------------------------------------------------------------
CONTROL ADD COMBOBOX, ghDlg, %IDC_COMBOBOX1, , 5, 5, 100, 60, %CBS_DROPDOWNLIST
COMBOBOX ADD ghDlg, %IDC_COMBOBOX1, "Item 0"
COMBOBOX ADD ghDlg, %IDC_COMBOBOX1, "Item 1"
COMBOBOX ADD ghDlg, %IDC_COMBOBOX1, "Item 2"
COMBOBOX SELECT ghDlg, %IDC_COMBOBOX1, 1
'-------------------------------------------------------------------
DIALOG SHOW MODAL ghDlg, CALL DlgProc
END FUNCTION
'======================================================================
CALLBACK FUNCTION DlgProc() AS LONG
LOCAL LBitem AS LONG
SELECT CASE CB.MSG
CASE %WM_INITDIALOG
ghCbFocus = GetWindow(GetDlgItem(CB.HNDL, %IDC_COMBOBOX1), %GW_CHILD) ' The Edit part is child of CB if %CBS_DROPDOWN
IF ghCbFocus = 0 THEN ghCbFocus = GetDlgItem(CB.HNDL, %IDC_COMBOBOX1) ' no edit part if %CBS_DROPDOWNLIST
CASE %WM_CTLCOLORLISTBOX ' sent when a ListBox och CB List needs repainting
IF GetFocus = ghCbFocus THEN ' ensure we get correct CB list
ghCBList = CB.LPARAM ' CB List handle - we can subclass (CB listbox is tricky - owner/parent is not CB)
IF gOldProc = 0 THEN gOldProc = SetWindowLong(ghCBList, %GWL_WNDPROC, CODEPTR(CBProc))
END IF
CASE %WM_DESTROY ' unsubclass CB List at exit
IF gOldProc THEN SetWindowLong ghCBList, %GWL_WNDPROC, gOldProc
CASE %WM_CONTEXTMENU ' R-clicked in CB (not list)
IF CB.WPARAM = GetDlgItem(CB.HNDL, %IDC_COMBOBOX1) THEN
DIALOG SET TEXT CB.HNDL, "R-clicked in CB"
END IF
CASE %WM_COMMAND
SELECT CASE CB.CTL
CASE %IDC_COMBOBOX1
IF CB.CTLMSG = %CBN_SELENDOK THEN 'L-clicked in cb list (selection made)
LBitem = SendMessage(CB.LPARAM, %CB_GETCURSEL, 0, 0)
DIALOG SET TEXT CB.HNDL, "L-clicked List item" + STR$(LBitem)
END IF
END SELECT
END SELECT
END FUNCTION
'====================================================================
' CB ListBox subclass procedure
'====================================================================
FUNCTION CBProc(BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, _
BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
LOCAL LBitem AS LONG
SELECT CASE wMsg
CASE %WM_CONTEXTMENU
LBitem = SendMessage(hWnd, %LB_GETCURSEL, 0, 0)
DIALOG SET TEXT ghDlg, "R-clicked List item" + STR$(LBitem)
END SELECT
FUNCTION = CallWindowProc(gOldProc, hWnd, wMsg, wParam, lParam)
END FUNCTION
http://www.garybeene.com/sw/gbsnippets.htm