Jump to content
Sign in to follow this  
GaryFrost

WM_MENUSELECT

Recommended Posts

Something I ran across, might be usefull to someone.

#include <GuiConstants.au3>

Global Const $WM_MENUSELECT = 0x11F

Global Const $MF_BITMAP = 0x4
Global Const $MF_CHECKED = 0x8
Global Const $MF_DISABLED = 0x2
Global Const $MF_GRAYED = 0x1
Global Const $MF_HILITE = 0x80
Global Const $MF_MOUSESELECT = 0x8000
Global Const $MF_OWNERDRAW = 0x100
Global Const $MF_POPUP = 0x10
Global Const $MF_SYSMENU = 0x2000

GUICreate("My GUI", 500, 500, Default, Default, BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX))  ; will create a dialog box that when displayed is centered
$filemenu = GUICtrlCreateMenu("&File")
$fileitem = GUICtrlCreateMenuitem("Open", $filemenu)
GUICtrlSetState(-1, $GUI_DEFBUTTON)
$helpmenu = GUICtrlCreateMenu("?")
$saveitem = GUICtrlCreateMenuitem("Save", $filemenu)
GUICtrlSetState(-1, $GUI_DISABLE)
$infoitem = GUICtrlCreateMenuitem("Info", $helpmenu)
$exititem = GUICtrlCreateMenuitem("Exit", $filemenu)
$recentfilesmenu = GUICtrlCreateMenu("Recent Files", $filemenu, 1)

$separator1 = GUICtrlCreateMenuitem("", $filemenu, 2)    ; create a separator line

$viewmenu = GUICtrlCreateMenu("View", -1, 1)  ; is created before "?" menu
$viewstatusitem = GUICtrlCreateMenuitem("Statusbar", $viewmenu)

GUISetState(@SW_SHOW)       ; will display an empty dialog box
GUIRegisterMsg($WM_MENUSELECT, "WM_MENUSELECT_Events")

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Func WM_MENUSELECT_Events($hWndGUI, $MsgID, $wParam, $lParam)
    Local $index = _LoWord($wParam)
    Local $flags = _HiWord($wParam)
    _DebugPrint("index or identifier: " & $index)
    If BitAND($flags, $MF_BITMAP) Then _DebugPrint("$MF_BITMAP")
    If BitAND($flags, $MF_CHECKED) Then _DebugPrint("$MF_CHECKED")
    If BitAND($flags, $MF_DISABLED) Then _DebugPrint("$MF_DISABLED")
    If BitAND($flags, $MF_GRAYED) Then _DebugPrint("$MF_GRAYED")
    If BitAND($flags, $MF_HILITE) Then _DebugPrint("$MF_HILITE")
    If BitAND($flags, $MF_MOUSESELECT) Then _DebugPrint("$MF_MOUSESELECT")
    If BitAND($flags, $MF_OWNERDRAW) Then _DebugPrint("$MF_OWNERDRAW")
    If BitAND($flags, $MF_POPUP) Then _DebugPrint("$MF_POPUP")
    If BitAND($flags, $MF_SYSMENU) Then _DebugPrint("$MF_SYSMENU")
    If $lParam Then _DebugPrint("Handle: " & $lParam)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_MENUSELECT_Events

Func _HiWord($x)
    Return BitShift($x, 16)
EndFunc   ;==>_HiWord

Func _LoWord($x)
    Return BitAND($x, 0xFFFF)
EndFunc   ;==>_LoWord

Func _DebugPrint($s_text)
    $s_text = StringReplace(StringReplace($s_text, @CRLF, @LF), @LF, @LF & "!-->")
    ConsoleWrite( _
            "+===========================================================" & @LF & _
            "!-->" & $s_text & @LF & _
            "+===========================================================" & @LF & @LF)
EndFunc   ;==>_DebugPrint

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...