Sign in to follow this  
Followers 0
Luigi

WM_COMMAND does not fire with WM_NOTIFY and WM CONTEXTMENU

1 post in this topic

Greetings!

I built this script with parts from anothers scripts.

Each one work fine. Toghether, WM_COMMAND does not work. Something is missing?

 

Regards

 

;~ #AutoIt3Wrapper_AU3Check_Parameters= -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
;~ #Tidy_Parameters=/sf

#include-once
#include <Array.au3>
#include <GUIConstantsEx.au3>
;~ #Include <GUIConstants.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3>

OnAutoItExitRegister("OnExit")

Opt("GUIOnEventMode", 1)
Opt("GUIEventOptions", 1)
Opt("MustDeclareVars", 1)

Global Enum $e_TreeAdd = 4000, $e_TreeDel, $e_Icon_A, $e_Icon_B, $e_Icon_C, $e_Icon_D

Global $aGuiSize[2] = [800, 600]
Global $hGui

Global Enum $eGID = 0, $eHANDLE, $eOVER

Global $TREE = 0

Global $TREE1[15]
Global $TREE2[15]
Global $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)

Global $iExStyle = Default

$hGui = GUICreate("TreeView", $aGuiSize[0], $aGuiSize[1])
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")

$TREE1[$eGID] = GUICtrlCreateTreeView(10, 10, 300, 400, $iStyle, $iExStyle)
$TREE1[$eHANDLE] = GUICtrlGetHandle($TREE1[$eGID])

$TREE2[$eGID] = GUICtrlCreateTreeView(320, 10, 300, 400, $iStyle, $iExStyle)
$TREE2[$eHANDLE] = GUICtrlGetHandle($TREE2[$eGID])

Populate()

GUISetState()

GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While Sleep(25)
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    ConsoleWrite("WM_COMMAND" & @LF)
    Switch $wParam
        Case $e_TreeAdd
            ConsoleWrite("$e_TreeAdd" & @LF)
        Case $e_TreeDel
            ConsoleWrite("$e_TreeDel" & @LF)
        Case $e_Icon_A
            ConsoleWrite("$e_Icon_A" & @LF)
            _GUICtrlTreeView_SetIcon($TREE[$eGID], $TREE[$eOVER], "shell32.dll", 3)
        Case $e_Icon_B
            ConsoleWrite("$e_Icon_B" & @LF)
            _GUICtrlTreeView_SetIcon($TREE[$eHANDLE], $TREE[$eOVER], "shell32.dll", 5)
        Case $e_Icon_C
            ConsoleWrite("$e_Icon_C" & @LF)
            _GUICtrlTreeView_SetIcon($TREE[$eGID], $TREE[$eOVER], "shell32.dll", 7)
        Case $e_Icon_D
            ConsoleWrite("$e_Icon_D" & @LF)
            _GUICtrlTreeView_SetIcon($TREE[$eGID], $TREE[$eOVER], "shell32.dll", 9)
    EndSwitch
EndFunc   ;==>WM_COMMAND

Func WM_CONTEXTMENU($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $lParam
    ConsoleWrite("WM_CONTEXTMENU["&$GUI_RUNDEFMSG&"]" & @LF)
    Local $hMenu = _GUICtrlMenu_CreatePopup()
;~  Local $hMenuIcon = _GUICtrlMenu_CreatePopup()

;~  Switch $wParam
;~      Case $TREE1[$eHANDLE]
;~          If $TREE1[$eOVER] Then
    _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Add item", $e_TreeAdd)
    _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Del", $e_TreeDel)
;~              _GUICtrlMenu_InsertMenuItem($hMenu, 3, "", 0)
;~              _GUICtrlMenu_InsertMenuItem($hMenu, 3, "Set icon", 0, $hMenuIcon)
;~              _GUICtrlMenu_InsertMenuItem($hMenuIcon, 0, "icon A", $e_Icon_A)
;~              _GUICtrlMenu_InsertMenuItem($hMenuIcon, 1, "icon B", $e_Icon_B)
;~              _GUICtrlMenu_InsertMenuItem($hMenuIcon, 2, "icon C", $e_Icon_C)
;~              _GUICtrlMenu_InsertMenuItem($hMenuIcon, 3, "icon D", $e_Icon_D)
;~          Else
;~              _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Add root", $e_TreeAdd)
;~          EndIf
    _GUICtrlMenu_TrackPopupMenu($hMenu, $wParam)
;~      Case $TREE2[$eHANDLE]
;~          ConsoleWrite("$TREE2[$eHANDLE]" & @LF)
;~      Case Else
;~          ConsoleWrite("Else" & @LF)
;~  EndSwitch
    _GUICtrlMenu_DestroyMenu($hMenu)
;~  _GUICtrlMenu_DestroyMenu($hMenuIcon)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_CONTEXTMENU


Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $TREE1[$eHANDLE]
            $TREE = $TREE1
            Switch $iCode
                Case $NM_CLICK ; The user has clicked the left mouse button within the control
                    _DebugPrint("$NM_CLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control
                    _DebugPrint("$NM_DBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_RCLICK ; The user has clicked the right mouse button within the control
                    _DebugPrint("$NM_RCLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; Return 1 ; nonzero to not allow the default processing
                    _GUICtrlTreeView_SetSelected($TREE1[$eHANDLE], _GUICtrlTreeView_GetSelection($TREE1[$eHANDLE]), False)
                    Local $tPoint = _WinAPI_GetMousePos(True, $hWndFrom)
                    Local $tHitTest = _GUICtrlTreeView_HitTestEx($hWndFrom, DllStructGetData($tPoint, 1), DllStructGetData($tPoint, 2))


                    If BitAND(DllStructGetData($tHitTest, "Flags"), $TVHT_ONITEM) Then
                        _GUICtrlTreeView_SelectItem($hWndFrom, DllStructGetData($tHitTest, "Item"))
                        $TREE1[$eOVER] = DllStructGetData($tHitTest, "Item")
                        ConsoleWrite("$tHitTest[" & DllStructGetData($tHitTest, "Item") & "]" & @LF)
                    Else
                        $TREE1[$eOVER] = 0
                        ConsoleWrite("$tHitTest[ @empty ]" & @LF)
                    EndIf
;~                  Return 0 ; zero to allow the default processing
                Case $NM_RDBLCLK ; The user has double-clicked the right mouse button within the control
                    _DebugPrint("$NM_RDBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_KILLFOCUS ; control has lost the input focus
                    _DebugPrint("$NM_KILLFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; No return value
                Case $NM_RETURN ; control has the input focus and that the user has pressed the key
                    _DebugPrint("$NM_RETURN" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                    ; Case $NM_SETCURSOR ; control is setting the cursor in response to a WM_SETCURSOR message
                    ; Local $tInfo = DllStructCreate($tagNMMOUSE, $lParam)
                    ; $hWndFrom = HWnd(DllStructGetData($tInfo, "hWndFrom"))
                    ; $iIDFrom = DllStructGetData($tInfo, "IDFrom")
                    ; $iCode = DllStructGetData($tInfo, "Code")
                    ; _DebugPrint("$NM_SETCURSOR" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                    ; "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                    ; "-->Code:" & @TAB & $iCode & @CRLF & _
                    ; "-->ItemSpec:" & @TAB & DllStructGetData($tInfo, "ItemSpec") & @CRLF & _
                    ; "-->ItemData:" & @TAB & DllStructGetData($tInfo, "ItemData") & @CRLF & _
                    ; "-->X:" & @TAB & DllStructGetData($tInfo, "X") & @CRLF & _
                    ; "-->Y:" & @TAB & DllStructGetData($tInfo, "Y") & @CRLF & _
                    ; "-->HitInfo:" & @TAB & DllStructGetData($tInfo, "HitInfo"))
                    ; Return 0 ; to enable the control to set the cursor
                    ; Return 1 ; nonzero to prevent the control from setting the cursor
                Case $NM_SETFOCUS ; control has received the input focus
                    _DebugPrint("$NM_SETFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; No return value
                Case $TVN_BEGINDRAGA, $TVN_BEGINDRAGW
                    _DebugPrint("$TVN_BEGINDRAG")
                Case $TVN_BEGINLABELEDITA, $TVN_BEGINLABELEDITW
                    _DebugPrint("$TVN_BEGINLABELEDIT")
                Case $TVN_BEGINRDRAGA, $TVN_BEGINRDRAGW
                    _DebugPrint("$TVN_BEGINRDRAG")
                Case $TVN_DELETEITEMA, $TVN_DELETEITEMW
                    _DebugPrint("$TVN_DELETEITEM")
                Case $TVN_ENDLABELEDITA, $TVN_ENDLABELEDITW
                    _DebugPrint("$TVN_ENDLABELEDIT")
                Case $TVN_GETDISPINFOA, $TVN_GETDISPINFOW
                    _DebugPrint("$TVN_GETDISPINFO")
                Case $TVN_GETINFOTIPA, $TVN_GETINFOTIPW
                    _DebugPrint("$TVN_GETINFOTIP")
                Case $TVN_ITEMEXPANDEDA, $TVN_ITEMEXPANDEDW
                    _DebugPrint("$TVN_ITEMEXPANDED")
                Case $TVN_ITEMEXPANDINGA, $TVN_ITEMEXPANDINGW
                    _DebugPrint("$TVN_ITEMEXPANDING")
                Case $TVN_KEYDOWN
                    _DebugPrint("$TVN_KEYDOWN")
                Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
                    _DebugPrint("$TVN_SELCHANGED")
                Case $TVN_SELCHANGINGA, $TVN_SELCHANGINGW
                    _DebugPrint("$TVN_SELCHANGING")
                Case $TVN_SETDISPINFOA, $TVN_SETDISPINFOW
                    _DebugPrint("$TVN_SETDISPINFO")
                Case $TVN_SINGLEEXPAND
                    _DebugPrint("$TVN_SINGLEEXPAND")
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @CRLF & _
            "+======================================================" & @CRLF & _
            "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
            "+======================================================" & @CRLF)
EndFunc   ;==>_DebugPrint


Func OnExit()
    GUISetState($hGui, @SW_HIDE)
    GUIDelete($hGui)
EndFunc   ;==>OnExit

Func Quit()
    Exit
EndFunc   ;==>Quit


Func Populate()
    Local $hItem
    Local $TREE
    For $ii = 1 To 2
        $TREE = Eval("TREE" & $ii)
        _GUICtrlTreeView_BeginUpdate($TREE[$eHANDLE])
        For $x = 1 To Random(2, 10, 1)
            $hItem = _GUICtrlTreeView_Add($TREE[$eHANDLE], 0, StringFormat("[%02d] New Item", $x))
            _GUICtrlTreeView_SetIcon($TREE[$eHANDLE], $hItem, "shell32.dll", 3)

            For $y = 1 To Random(2, 10, 1)
                _GUICtrlTreeView_AddChild($TREE[$eHANDLE], $hItem, StringFormat("[%02d] New Child", $y))
            Next
        Next
        _GUICtrlTreeView_EndUpdate($TREE[$eHANDLE])
    Next
EndFunc   ;==>Populate

 


Visit my repository

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  
Followers 0