#include #include #include #include #include #include #include #include ; ======================================================================== ; Global variables ; ======================================================================== Global Enum $idOpen , $idSave, $idInfo ; ======================================================================== ; Main ; ======================================================================== $hGUI = GUICreate('Context Menu Demo (DB Click)', 400, 400) $Edit = GUICtrlCreateEdit("",0, 280,400, 130, $ES_WANTRETURN) $hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 394, 268) _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; Load images $hImage = _GUIImageList_Create(16,16,5,3) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16)) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 137) _GUIImageList_AddBitmap($hImage, @SystemDir & "\migwiz\PostMigRes\Web\base_images\WindowsOutlookExpress.bmp") _GUICtrlListView_SetImageList($hListView, $hImage, 1) ; Add columns _GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100) _GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100) _GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100) ; Add items _GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0) _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1) _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2, 3) _GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1) _GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1,2) _GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2) GUISetState() ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func ListView_RClick() Local $aHit $aHit = _GUICtrlListView_SubItemHitTest($hListView) If ($aHit[0] <> -1) Then ; Create a standard popup menu ; -------------------- To Do -------------------- $hMenu = _GUICtrlMenu_CreatePopup() $hBrush = _WinAPI_GetSysColorBrush($COLOR_INFOBK) _GUICtrlMenu_SetMenuBackground($hMenu, $hBrush) _GUICtrlMenu_AddMenuItem($hMenu, "Open", $idOpen) _GUICtrlMenu_AddMenuItem($hMenu, "Save", $idSave) _GUICtrlMenu_AddMenuItem($hMenu, "Info", $idInfo) _GUICtrlMenu_SetItemBmp($hMenu, 0, _WinAPI_Create32BitHBITMAP(_WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', 207, 16, 16), 1, 1)) _GUICtrlMenu_SetItemBmp($hMenu, 1, _WinAPI_Create32BitHBITMAP(_WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', 208, 16, 16), 1, 1)) _GUICtrlMenu_SetItemBmp($hMenu, 2, _WinAPI_Create32BitHBITMAP(_WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', 209, 16, 16), 1, 1)) ; ======================================================================== ; Shows how to capture the context menu selections ; ======================================================================== Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $hListView, -1, -1, 1, 1, 2) Case $idOpen _DebugPrint("Open: " & StringFormat("Item, SubItem [%d, %d]", $aHit[0], $aHit[1])) Case $idSave _DebugPrint("Save: " & StringFormat("Item, SubItem [%d, %d]", $aHit[0], $aHit[1])) Case $idInfo _DebugPrint("Info: " & StringFormat("Item, SubItem [%d, %d]", $aHit[0], $aHit[1])) EndSwitch _GUICtrlMenu_DestroyMenu($hMenu) EndIf EndFunc ;==>ListView_RClick Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) ;$iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_DBLCLK ; Sent by a list-view control when the user clicks an item with the left mouse button ListView_RClick() Return 0 EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _DebugPrint($s_text, $line = @ScriptLineNumber) GUICtrlSetData($Edit, _ "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _ "+======================================================" & @LF) GUICtrlSetFont($Edit,10) EndFunc ;==>_DebugPrint