本帖最后由 夜猫猫 于 2011-8-3 12:27 编辑
使用_GUICtrlListView_Create函数添加背景图片后,添加鼠标右键.双击全失效.
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
Local $hImage, $hListView
; Create GUI
$gui=GUICreate("ListView测试", 800, 600)
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")
$hListView = _GUICtrlListView_Create($gui, "", 2, 2, 596, 500, -1, -1, True)
_GUICtrlListView_SetView($hListView, 1)
; Load images
$hImage = _GUIImageList_Create(32,32,5,2)
_GUIImageList_SetIconSize($hImage,32,32)
_GUIImageList_SetBkColor($hImage,0xffffff)
_GUIImageList_AddIcon($hImage, @WindowsDir&"\notepad.exe",0,True) ;读取图标
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 48, 48))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 48, 48))
_GUICtrlListView_SetImageList($hListView, $hImage, 0)
_GUICtrlListView_SetBkImage($hListView, @ScriptDir & "\1.jpg")
; Add items
_GUICtrlListView_AddItem($hListView, "Item 1", 0)
_GUICtrlListView_AddItem($hListView, "Item 2", 1)
_GUICtrlListView_AddItem($hListView, "Item 3", 2)
_GUICtrlListView_SetIconSpacing($hListView, 64, 64)
$contextmenu = GUICtrlCreateContextMenu ($hListView)
$Run = GUICtrlCreateMenuitem ("运行",$contextmenu)
$Runpath = GUICtrlCreateMenuitem ("目录",$contextmenu)
$shuxin = GUICtrlCreateMenuitem ("属性",$contextmenu)
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func WM_Notify_Events($hWndGUI, $MsgID, $WParam, $LParam)
Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
If @error Then Return $GUI_RUNDEFMSG
$IDFrom = DllStructGetData($tagNMHDR, 2)
$Event = DllStructGetData($tagNMHDR, 3)
$tagNMHDR = 0
Switch $IDFrom;选择产生事件的控件
Case $hListView
Switch $Event; 选择产生的事件
Case $NM_CLICK ; 左击
$Index = _GUICtrlListView_GetSelectedIndices($hListView)
If Not StringLen($Index) Then; 这里用以判断是否选定了ListViewItem
Return
EndIf
$jy=_GUICtrlListView_GetItemText($hListView, Number($Index),0)
Case $NM_DBLCLK ; 双击
MsgBox(0,"","双击鼠标提示")
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
|