GUICtrlGetHandle
返回控件或特定项目(Menu, ContextMenu, TreeViewItem)的句柄.
GUICtrlGetHandle ( controlID )
参数
返回值
成功:
|
返回指定控件标识的句柄.
|
失败:
|
返回 0.
|
备注
以下控件不会返回句柄:
GUICtrlCreateDummy()
GUICtrlCreateGraphic()
GUICtrlCreateObj()
GUICtrlCreateListViewItem()
GUICtrlCreateTabItem().
ListViewItems 与 TabItems 使用索引管理.
获取这些项目的索引需使用: DllCall() 与 DllStructCreate().
相关
IsHWnd
函数示例
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
Example()
Func Example()
GUICreate("My GUI", 300, 200)
Local $idFileMenu = GUICtrlCreateMenu("&File")
GUICtrlCreateMenuItem("&Open", $idFileMenu)
GUICtrlCreateMenuItem("&Save", $idFileMenu)
GUICtrlCreateMenuItem("", $idFileMenu)
Local $idOptionsMenu = GUICtrlCreateMenu("O&ptions", $idFileMenu)
GUICtrlCreateMenuItem("View", $idOptionsMenu)
GUICtrlCreateMenuItem("", $idOptionsMenu)
GUICtrlCreateMenuItem("Tools", $idOptionsMenu)
GUICtrlCreateMenuItem("", $idFileMenu)
Local $idExitItem = GUICtrlCreateMenuItem("&Exit", $idFileMenu)
Local $idHelpMenu = GUICtrlCreateMenu("&?")
Local $idAboutItem = GUICtrlCreateMenuItem("&About", $idHelpMenu)
Local $idEndBtn = GUICtrlCreateButton("End", 110, 140, 70, 20)
SetMenuColor($idFileMenu, 0xEEBB99) ; BGR color value
SetMenuColor($idOptionsMenu, 0x66BB99); BGR color value
SetMenuColor($idHelpMenu, 0x99BBEE) ; BGR color value
GUISetState(@SW_SHOW)
Local $idMsg
; Loop until the user exits.
While 1
$idMsg = GUIGetMsg()
Switch $idMsg
Case $idExitItem, $idEndBtn, $GUI_EVENT_CLOSE
ExitLoop
Case $idAboutItem
MsgBox($MB_SYSTEMMODAL, "About...", "Colored menu sample")
EndSwitch
WEnd
EndFunc ;==>Example
; Apply the color to the menu
Func SetMenuColor($nMenuID, $nColor)
Local Const $MIM_APPLYTOSUBMENUS = 0x80000000
Local Const $MIM_BACKGROUND = 0x00000002
Local $hMenu = GUICtrlGetHandle($nMenuID)
Local $hBrush = DllCall("gdi32.dll", "hwnd", "CreateSolidBrush", "int", $nColor)
$hBrush = $hBrush[0]
Local $tMenuInfo = DllStructCreate("dword;dword;dword;uint;dword;dword;ptr")
DllStructSetData($tMenuInfo, 1, DllStructGetSize($tMenuInfo))
DllStructSetData($tMenuInfo, 2, BitOR($MIM_APPLYTOSUBMENUS, $MIM_BACKGROUND))
DllStructSetData($tMenuInfo, 5, $hBrush)
DllCall("user32.dll", "int", "SetMenuInfo", "hwnd", $hMenu, "struct*", $tMenuInfo)
; release Struct not really needed as it is a local
$tMenuInfo = 0
EndFunc ;==>SetMenuColor
----------------------------------------
|