创建来自图像和图像列表掩码的图标
#Include <GuiImageList.au3>
_GUIImageList_GetIcon($hWnd, $iIndex[, $iStyle = 0])
$hWnd | 控件句柄 |
$iIndex | 图像的 0 基索引 |
$iStyle | [可选参数] 绘制样式和覆盖图像: 1 - 使用透明蒙板,不涉及背景颜色 2 - 混合系统高亮颜色 25% 4 - 混合系统高亮颜色 50% 8 - 绘制蒙板 |
成功: | 返回图标句柄 |
失败: | 返回 0 |
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <WinAPI.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
$Debug_SB = False ; 检查传递给函数的类名, 设置为True并输出到一个控件的句柄,用于检查它是否工作
Global $hStatus, $iMemo
_Main()
Func _Main()
Local $hGUI, $hIcons[2], $hImage
Local $aParts[4] = [75, 150, 300, 400]
; 创建 GUI
$hGUI = GUICreate("ImageList Get Icon", 400, 300)
$hStatus = _GUICtrlStatusBar_Create($hGUI)
; 创建 memo 控件
$iMemo = GUICtrlCreateEdit("", 2, 2, 396, 274, $WS_VSCROLL)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
; 设置某部分
_GUICtrlStatusBar_SetParts($hStatus, $aParts)
_GUICtrlStatusBar_SetText($hStatus, "Part 1")
_GUICtrlStatusBar_SetText($hStatus, "Part 2", 1)
; 加载图像
$hImage = _GUIImageList_Create(11, 11)
_GUIImageList_Add($hImage, _WinAPI_CreateSolidBitmap($hStatus, 0xFF0000, 11, 11))
_GUIImageList_Add($hImage, _WinAPI_CreateSolidBitmap($hStatus, 0x00FF00, 11, 11))
_GUIImageList_Add($hImage, _WinAPI_CreateSolidBitmap($hStatus, 0x0000FF, 11, 11))
; 设置图标
$hIcons[0] = _GUIImageList_GetIcon($hImage, 1)
$hIcons[1] = _GUIImageList_GetIcon($hImage, 2)
_GUICtrlStatusBar_SetIcon($hStatus, 0, $hIcons[0])
_GUICtrlStatusBar_SetIcon($hStatus, 1, $hIcons[1])
; 显示图标句柄
MemoWrite("Part 1 icon handle .: 0x" & Hex($hIcons[0]))
MemoWrite("Part 2 icon handle .: 0x" & Hex($hIcons[1]))
; 循环直到用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
; 释放图标
MsgBox(4096, "信息", "Icon 1 Destroyed? " & _GUIImageList_DestroyIcon($hIcons[0]))
MsgBox(4096, "信息", "Icon 2 Destroyed? " & _GUIImageList_DestroyIcon($hIcons[1]))
GUIDelete()
EndFunc ;==>_Main
; 写入消息到 memo
Func MemoWrite($sMessage = "")
GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc ;==>MemoWrite
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Local $tinfo
Switch $hWndFrom
Case $hStatus
Switch $iCode
Case $NM_CLICK ; 用户在控件中点击了鼠标左键
$tinfo = DllStructCreate($tagNMMOUSE, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tinfo, "hWndFrom"))
$iIDFrom = DllStructGetData($tinfo, "IDFrom")
$iCode = DllStructGetData($tinfo, "Code")
_DebugPrint("$NM_CLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode & @LF & _
"-->ItemSpec:" & @TAB & DllStructGetData($tinfo, "ItemSpec") & @LF & _
"-->ItemData:" & @TAB & DllStructGetData($tinfo, "ItemData") & @LF & _
"-->X:" & @TAB & DllStructGetData($tinfo, "X") & @LF & _
"-->Y:" & @TAB & DllStructGetData($tinfo, "Y") & @LF & _
"-->HitInfo:" & @TAB & DllStructGetData($tinfo, "HitInfo"))
Return True ; 表明处理了鼠标点击且取消系统的默认处理
;~ Return FALSE ;允许对点击进行默认处理
Case $NM_DBLCLK ; 用户在控件中双击了鼠标左键
$tinfo = DllStructCreate($tagNMMOUSE, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tinfo, "hWndFrom"))
$iIDFrom = DllStructGetData($tinfo, "IDFrom")
$iCode = DllStructGetData($tinfo, "Code")
_DebugPrint("$NM_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode & @LF & _
"-->ItemSpec:" & @TAB & DllStructGetData($tinfo, "ItemSpec") & @LF & _
"-->ItemData:" & @TAB & DllStructGetData($tinfo, "ItemData") & @LF & _
"-->X:" & @TAB & DllStructGetData($tinfo, "X") & @LF & _
"-->Y:" & @TAB & DllStructGetData($tinfo, "Y") & @LF & _
"-->HitInfo:" & @TAB & DllStructGetData($tinfo, "HitInfo"))
Return True ; 表明处理了鼠标点击且取消系统的默认处理
;~ Return FALSE ;允许对点击进行默认处理
Case $NM_RCLICK ; 用户在控件中点击了鼠标右键
$tinfo = DllStructCreate($tagNMMOUSE, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tinfo, "hWndFrom"))
$iIDFrom = DllStructGetData($tinfo, "IDFrom")
$iCode = DllStructGetData($tinfo, "Code")
_DebugPrint("$NM_RCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode & @LF & _
"-->ItemSpec:" & @TAB & DllStructGetData($tinfo, "ItemSpec") & @LF & _
"-->ItemData:" & @TAB & DllStructGetData($tinfo, "ItemData") & @LF & _
"-->X:" & @TAB & DllStructGetData($tinfo, "X") & @LF & _
"-->Y:" & @TAB & DllStructGetData($tinfo, "Y") & @LF & _
"-->HitInfo:" & @TAB & DllStructGetData($tinfo, "HitInfo"))
Return True ; 表明处理了鼠标点击且取消系统的默认处理
;~ Return FALSE ;允许对点击进行默认处理
Case $NM_RDBLCLK ; 用户在控件中点击了鼠标右键
$tinfo = DllStructCreate($tagNMMOUSE, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tinfo, "hWndFrom"))
$iIDFrom = DllStructGetData($tinfo, "IDFrom")
$iCode = DllStructGetData($tinfo, "Code")
_DebugPrint("$NM_RDBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode & @LF & _
"-->ItemSpec:" & @TAB & DllStructGetData($tinfo, "ItemSpec") & @LF & _
"-->ItemData:" & @TAB & DllStructGetData($tinfo, "ItemData") & @LF & _
"-->X:" & @TAB & DllStructGetData($tinfo, "X") & @LF & _
"-->Y:" & @TAB & DllStructGetData($tinfo, "Y") & @LF & _
"-->HitInfo:" & @TAB & DllStructGetData($tinfo, "HitInfo"))
Return True ; 表明处理了鼠标点击且取消系统的默认处理
;~ Return FALSE ;允许对点击进行默认处理
Case $SBN_SIMPLEMODECHANGE ; 简单模式改变
_DebugPrint("$SBN_SIMPLEMODECHANGE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; 没有返回值
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _DebugPrint($s_text, $line = @ScriptLineNumber)
ConsoleWrite( _
"!===========================================================" & @LF & _
"+======================================================" & @LF & _
"-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
"+======================================================" & @LF)
EndFunc ;==>_DebugPrint