Как можно добавить иконки слева от надписей в контекстном меню?
Или средствами autoit это нельзя сделать?
Например вот такой код:
Или средствами autoit это нельзя сделать?
Например вот такой код:
Код:
#include <GUIConstantsEx.au3>
#include <GUIMenu.au3>
#include <GUIListView.au3>
#include <WindowsConstants.au3>
;
Global $hListView , $iLast_LV_Index, $Form1
$Form1 = GUICreate("Context Menu on ListView Items - Example", 400, 300)
$DummyMenu = GUICtrlCreateDummy()
$ContextMenu = GUICtrlCreateContextMenu($DummyMenu)
$Some_Copy = GUICtrlCreateMenuItem("Copy", $ContextMenu)
$Some_Del = GUICtrlCreateMenuItem("Del", $ContextMenu)
$Exit_Item = GUICtrlCreateMenuItem("Exit", $ContextMenu)
$hListView = _GUICtrlListView_Create($Form1, "", 32, 16, 340, 260) ; LEFT],[TOP],WIDTH],[HEIGHT]
_GUICtrlListView_SetExtendedListViewStyle($hListView, _
BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_CHECKBOXES))
; Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
; Add items
_GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
_GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1)
_GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE,$Exit_Item
Exit
Case $Some_Copy
MsgBox(0,'','Копирование')
Case $Some_Del
MsgBox(0,'','Удаление')
EndSwitch
WEnd
; Show a menu in a given GUI window which belongs to a given GUI ctrl
Func ShowMenu($hWnd, $nContextID, $nContextControlID, $iMouse=0)
Local $hMenu = GUICtrlGetHandle($nContextID)
Local $iCtrlPos = ControlGetPos($hWnd, "", $nContextControlID)
Local $X = $iCtrlPos[0]
Local $Y = $iCtrlPos[1] + $iCtrlPos[3]
ClientToScreen($hWnd, $X, $Y)
If $iMouse Then
$X = MouseGetPos(0)
$Y = MouseGetPos(1)
EndIf
DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $X, "int", $Y, "hwnd", $hWnd, "ptr", 0)
EndFunc
; Convert the client (GUI) coordinates to screen (desktop) coordinates
Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
Local $stPoint = DllStructCreate("int;int")
DllStructSetData($stPoint, 1, $x)
DllStructSetData($stPoint, 2, $y)
DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint))
$x = DllStructGetData($stPoint, 1)
$y = DllStructGetData($stPoint, 2)
; release Struct not really needed as it is a local
$stPoint = 0
EndFunc
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
$hWndListView = $hListView
If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$iIndex = DllStructGetData($tInfo, "Index")
If $iIndex <> -1 Then
$iLast_LV_Index = $iIndex
ShowMenu($hWnd, $ContextMenu, $hListView, 1)
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc