benners

Help with WM_Notify

1 post in this topic

#1 ·  Posted

I am trying to get the _GUICtrlTreeView_HitTest function to work correctly but after using different codes and settings, I have been unsuccessful.

I have searched the forum and found this snippet that Works but it uses GUIRegisterMsg. I already have a function that fires when a child item is selected in a treeview, and was trying to incorporate the _GUICtrlTreeView_HitTest  into that function, but I could never get the correct mouse position and the returned value was always;

"512 - To the right of the client area"

 The intention was if a checkbox was selected one function would run. If the text of the treeview item was selected, another function would run.

I have been trying to figure out what parameters are sent to MY_WM_NOTIFY,  $wParam is the treeview ControlID but I don't know what the second message is ($lParam). When the function is running and I randomly click the treeview items, it does not always return the same value, is it supposed to?

Could someone explain what is happening within the MY_WM_NOTIFY function on the lines  I have commented, DllStruct*.* functions are something I have steered clear of because I don't understand them.

I will probably recode and use the MY_WM_NOTIFY function to just return the result of _GUICtrlTreeView_HitTest so that the Event() function can act on it, I pressume I will need to have a global variable to keep track of the _GUICtrlTreeView_HitTest value.

#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

$Gui = GUICreate("Treeview", 300, 375)
$TreeView = GUICtrlCreateTreeView(5, 30, 290, 310, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_CHECKBOXES))
For $i = 1 To 5
    GUICtrlCreateTreeViewItem("Item " & $i, $TreeView)
    GUICtrlSetOnEvent(-1, "Event")
    GUICtrlSetImage(-1, "shell32.dll", -42, 4)
    GUICtrlSetImage(-1, "shell32.dll", -42, 2)
    GUICtrlCreateTreeViewItem("Sub Item " & $i, -1)
    GUICtrlSetOnEvent(-1, "Event")
    GUICtrlSetImage(-1, "shell32.dll", -85, 4)
    GUICtrlSetImage(-1, "shell32.dll", -85, 2)
Next
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetState(@SW_SHOW, $Gui)

GUIRegisterMsg($WM_NOTIFY, "MY_WM_NOTIFY")

While 1
    Sleep(100)
WEnd

Func Event()
    ; _GUICtrlTreeView_HitTest would go here
    ConsoleWrite("Event: Selected Treeview Text: " & GUICtrlRead(GUICtrlRead($TreeView), 1) & @LF)
EndFunc   ;==>Event

Func Close()
    Exit
EndFunc   ;==>Close

Func MY_WM_NOTIFY($hWnd, $nMsg, $wParam, $lParam)
    Local $nID = BitAND($wParam, 0x0000FFFF) ; get the treeview id ($TreeView)
    Local $stNmhdr = DllStructCreate("dword;int;int", $lParam) ; what is happening here?
    Local $hWndFrom = DllStructGetData($stNmhdr, 1) ; what is happening here?
    Local $nNotifyCode = DllStructGetData($stNmhdr, 3) ; what is happening here?

    If Not ($nNotifyCode = $NM_CLICK Or $nNotifyCode = $TVN_KEYDOWN) Then Return $GUI_RUNDEFMSG

    Local $tagPOINT = _WinAPI_GetMousePos(True, $hWndFrom)

    Switch _GUICtrlTreeView_HitTest($nID, DllStructGetData($tagPOINT, 1), DllStructGetData($tagPOINT, 2))
        Case 2
            ConsoleWrite('$lParam: ' & $lParam & " --------------------------------" & @LF)
            ConsoleWrite("MY_WM_NOTIFY: Treeview Icon clicked" & @LF)
        Case 4
            ConsoleWrite('$lParam: ' & $lParam & " --------------------------------" & @LF)
            ConsoleWrite("MY_WM_NOTIFY: Treeview Text clicked" & @LF)
        Case 16
            ConsoleWrite('$lParam: ' & $lParam & " --------------------------------" & @LF)
            ConsoleWrite("MY_WM_NOTIFY: Treeview Button clicked" & @LF)
        Case 64
            ConsoleWrite('$lParam: ' & $lParam & " --------------------------------" & @LF)
            ConsoleWrite("MY_WM_NOTIFY: Treeview Checkbox clicked" & @LF)
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_NOTIFY

 

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