Sign in to follow this  
Followers 0
mikeman118

$TVN_SELCHANGED Notification Not Working

7 posts in this topic

Hi, I've created a tree view control and I'd like to know when the selection changes. So I've registered the WM_NOTIFY message and using that I'm able to know when an item is double clicked, but it doesn't do anything when the selection changes. Here's my WM_NOTIFY code:

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hTV, $hSB
    $hSB = $StatusBar
    $hTV = $FolderView
    If Not IsHWnd($FolderView) Then $hTV = GUICtrlGetHandle($FolderView)
    If Not IsHWnd($StatusBar) Then $hSB = GUICtrlGetHandle($StatusBar)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hTV
            Switch $iCode
                Case $NM_DBLCLK
                    $Path = GetSelected2()
                    Run(@WindowsDir & "\explorer.exe " & $Path)
                ;GetSelected
                Case $TVN_SELCHANGED
                    MsgBox(0, "", "")
            EndSwitch
        Case $hSB
            Switch $iCode
                Case $NM_DBLCLK
                    Run(@WindowsDir & "\explorer.exe " & $CopyPath)
                ;GetSelected2()
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_NOTIFY

Does anyone know why it's not working? Thanks.

Share this post


Link to post
Share on other sites



mikeman118

$NM_DBLCLK and $TVN_SELCHANGED it's different notify messages.

Example 1 (with $NM_DBLCLK)

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

$Style = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)

$hGUI = GUICreate("Test", 300, 300)

$hTreeView = _GUICtrlTreeView_Create($hGUI, 10, 10, 280, 280)

For $i = 1 To 10
    $hItem = _GUICtrlTreeView_Add($hTreeView, 0, "Item " & $i)
    
    For $j = 1 To 10
        _GUICtrlTreeView_AddChild($hTreeView, $hItem, "Child " & $j)
    Next
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tNMHDR, $hWndFrom, $iCode
    
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    
    Switch $hWndFrom
        Case $hTreeView
            Switch $iCode
                Case $NM_DBLCLK
                    Local $tPOINT = _WinAPI_GetMousePos(True, $hWnd)
                    Local $iX = DllStructGetData($tPOINT, "X")
                    Local $iY = DllStructGetData($tPOINT, "Y")
                    
                    Local $aPos = ControlGetPos($hGUI, "", $hTreeView)
                    
                    Local $iItem = _GUICtrlTreeView_HitTestItem($hTreeView, $iX - $aPos[0], $iY - $aPos[1])
                    ConsoleWrite("!> " & _GUICtrlTreeView_GetText($hTreeView, $iItem) & @LF)
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFuncoÝ÷ Ù±1jje{oÛÂ+aoMúMSR°ÑöÚºÚ"µÍÚ[ÛYH    ÑÝZPÛÛÝ[Ñ^]LÉÝÂÚ[ÛYH ÑÝZUYUY]Ë]LÉÝÂÚ[ÛYH ÕÚ[ÝÜÐÛÛÝ[Ë]LÉÝÂÌÍÔÝ[HH]Ô  ÌÍÕ×ÒTÐUÓË  ÌÍÕ×ÒTÓSTË   ÌÍÕ×ÓSTÐUÓÕ ÌÍÕ×ÑTÐPQQÑÔ    ÌÍÕ×ÔÒÕÔÑSSÐVTÊBÌÍÚÕRHHÕRPÜX]J ][ÝÕÝ    ][ÝËÌÌ
BÌÍÚYUY]ÈHÑÕRPÝYUY]×ÐÜX]J ÌÍÚÕRKLL
BÜ ÌÍÚHHHÈLIÌÍÚ][HHÑÕRPÝYUY]×ÐY
    ÌÍÚYUY]Ë    ][ÝÒ][H   ][ÝÈ  [È ÌÍÚJBBQÜ    ÌÍÚHHÈLBWÑÕRPÝYUY]×ÐYÚ[
    ÌÍÚYUY]Ë    ÌÍÚ][K   ][ÝÐÚ[   ][ÝÈ  [È ÌÍÚBS^^ÕRTYÚÝÙÊ ÌÍÕÓWÓÕQK ][ÝÕÓWÓÕQI][ÝÊBÕRTÙ]Ý]J
BÂ[[ÕRQÙ]ÙÊ
HH  ÌÍÑÕRWÑUSÐÓÔÑB[ÈÓWÓÕQJ ÌÍÚÛ    ÌÍÓÙË  ÌÍÝÔ[K  ÌÍÛ[JBSØØ[ ÌÍÝR ÌÍÚÛÛK ÌÍÚPÛÙBBIÌÍÝRHÝXÝÜX]J    ÌÍÝYÓR  ÌÍÛ[JBIÌÍÚÛÛHHÝXÝÙ]]J    ÌÍÝR ][ÝÚÛÛI][ÝÊBIÌÍÚPÛÙHHÝXÝÙ]]J  ÌÍÝR ][ÝÐÛÙI][ÝÊBBTÝÚ]Ú ÌÍÚÛÛBBPØÙH  ÌÍÚYUY]ÂBBTÝÚ]Ú  ÌÍÚPÛÙBBBBPØÙH   ÌÍÕÔÑSÒSÑQBBBBSØØ[ ÌÍÝSÈHÝXÝÜX]J    ÌÍÝYÓUQUQUË    ÌÍÛ[JBBBBBSØØ[ ÌÍÚS]Ò][HHÝXÝÙ]]J    ÌÍÝSË   ][ÝÓ]Ú][I][ÝÊBBBBBBBBBBPÛÛÛÛUÜ]JÑÕRPÝYUY]×ÑÙ]^
    ÌÍÚYUY]Ë    ÌÍÚS]Ò][JH  [ÈBBBQ[ÝÚ]ÚQ[ÝÚ]ÚBT] ÌÍÑÕRWÔSQTÑÂ[[

;)

Share this post


Link to post
Share on other sites

Sorry to sound stupid, but what's the difference between the two examples, rasim? I know that TVN_SELCHANGED and NM_DBLCLK are different messages, I just mentioned that to say that I had my WM_NOTIFY working. Now my other question is, do I have to use _GUICtrlTreeView_Create to make my treeview, or can I just use GUICtrlCreateTreeView? The reason I ask is because any example that I've found that uses TVN_SELCHANGED uses _GUICtrlTreeView_Create to create the treeview.

Share this post


Link to post
Share on other sites

mikeman118

what's the difference between the two examples

TVN_SELCHANGED message appear if you select a treeview item, so you can not processing mouse double click, because in first click you already activate a treeview item. Second example demonstrate, how can processing double click on item.

do I have to use _GUICtrlTreeView_Create to make my treeview, or can I just use GUICtrlCreateTreeView?

INHO has a no differences.

Share this post


Link to post
Share on other sites

Sorry to bring this back up again, but I can still not get it to work. Here's my treeview creation code:

$Style = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
    $SceneTreeView = GUICtrlCreateTreeView(232, 48, 81, 321, $Style)

Notice that it's not created with the _GUICtrlTreeView_Create function.

Here's the WM_NOTIFY code:

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tNMHDR, $hWndFrom, $iCode

    If Not IsHWnd($SceneTreeView) Then $hTV = GUICtrlGetHandle($SceneTreeView)
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
   
    Switch $hWndFrom
        Case $hTV 
            Switch $iCode
                Case $TVN_SELCHANGED
                    Local $tINFO = DllStructCreate($tagNMTREEVIEW, $lParam)
                    Local $iNewItem = DllStructGetData($tINFO, "NewhItem")
                   
                    ConsoleWrite(_GUICtrlTreeView_GetText($SceneTreeView, $iNewItem) & @LF)
            EndSwitch
    EndSwitch
   
    Return $GUI_RUNDEFMSG
EndFunc

As you can see, it's exactly the same as rasim's code except for this line,

If Not IsHWnd($SceneTreeView) Then $hTV = GUICtrlGetHandle($SceneTreeView)

but I have to have that or else nothing happens at all. Also I use the GUICtrlCreateTreeView function rather than the one rasim used. Anyway, it's receiving the messages from the treeview, just not the $TVN_SELCHANGED message. Am I missing something here? Thanks.

Share this post


Link to post
Share on other sites

mikeman118

Hmm...looks like a bug. ;) Use a _GUICtrlTreeView_Create() function.

Share this post


Link to post
Share on other sites

mikeman118

Hmm...looks like a bug. ;) Use a _GUICtrlTreeView_Create() function.

That would make sense. I have noticed that a lot of the user defined GUI functions make other functions not work. Thanks anyway.

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