Jump to content
Sign in to follow this  
BugFix

TreeView - GUICtrlSetOnEvent fails

Recommended Posts

BugFix

Hi,

i create an treeview and add items with _GUICtrlTreeView_Add() and _GUICtrlTreeView_AddChild() because set icon for items too. But GUICtrlSetOnEvent() has no effect. I think because UDF returns handle instead ID.

So i've tested WM_NOTIFY. It works, but with an offset of one click. :)

I hope, someone knows an solution.

#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)
Opt("GuiOnEventMode", 1)

Global $gui, $hImage, $hTV, $aID_Sub[5], $ID_Table

$gui = GUICreate('Test TreeView')
GUISetOnEvent($GUI_EVENT_CLOSE, '_end')
$hTV = GUICtrlCreateTreeView(10,10,300,350,BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, _
        $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)

$hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage, "shell32.dll", 98)
_GUIImageList_AddIcon($hImage, "shell32.dll", 96)
_GUIImageList_AddIcon($hImage, "shell32.dll", 36)
_GUICtrlTreeView_SetNormalImageList($hTV, $hImage)

_GUICtrlTreeView_BeginUpdate($hTV)
$ID_Table = _GUICtrlTreeView_Add($hTV, 0, 'Table', 0, 0)
For $i = 1 To 5
    $aID_Sub[$i-1] = _GUICtrlTreeView_AddChild($hTV, $ID_Table, 'Sub' & $i, 1, 1)
    GUICtrlSetOnEvent($aID_Sub[$i-1], 'click_TV')  ; does'nt work (because have no ID and handle instead ?)
    For $j = 1 To 3
        _GUICtrlTreeView_AddChild($hTV, $aID_Sub[$i-1], 'Sub_Sub' & $j, 2, 2)
    Next
Next
_GUICtrlTreeView_EndUpdate($hTV)
_GUICtrlTreeView_Expand($hTV, $ID_Table)

GUISetState()
;~ GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') ; by using WM_NOTIFY are strange results, are reading with an offset of 1 click!

While 1
    Sleep(100)
WEnd

Func _end()
    Exit
EndFunc

Func click_TV()
    ConsoleWrite(_GUICtrlTreeView_GetText($hTV, _GUICtrlTreeView_GetSelection($hTV)) & @CRLF)
EndFunc

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

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTreeview
            Switch $iCode
                Case $NM_CLICK
                    click_TV()
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFYoÝ÷ Øý½è(µ¨(¡Ûb§­®²)àiÛ¦#hÂ+p¢¹,~)Þ²"êÚºÚ"µÍÚ[ÛYH  ÑÕRPÛÛÝ[Ñ^]LÉÝÂÚ[ÛYH ÑÝZUYUY]Ë]LÉÝÂÚ[ÛYH ÕYUY]ÐÛÛÝ[Ë]LÉÝÂÚ[ÛYH    ÕÚ[ÝÜÐÛÛÝ[Ë]LÉÝÂÚ[ÛYH Ð^K]LÉÝÂÜ
    ][ÝÓ]ÝXÛUÉ][ÝËJBÜ
    ][ÝÑÝZSÛ][[ÙI][ÝËJBÛØ[ ÌÍÙÝZK  ÌÍÚ[XYÙK    ÌÍÚ  ÌÍØRQÔÝXÍWK   ÌÍÒQÕXBÌÍÙÝZHHÕRPÜX]J ÌÎNÕÝYUY]ÉÌÎNÊBÕRTÙ]Û][
    ÌÍÑÕRWÑUSÐÓÔÑK ÌÎN×Ù[  ÌÎNÊBÌÍÚHÕRPÝÜX]UYUY]ÊLLÌÍL]Ô  ÌÍÕ×ÒTÐUÓË  ÌÍÕ×ÒTÓSTË   ÌÍÕ×ÓSTÐUÓÕÂBIÌÍÕ×ÑTÐPQQÑÔ ÌÍÕ×ÔÒÕÔÑSSÐVTÊK ÌÍÕÔ×ÑVÐÓQSQÑJBÛØ[   ÌÍÕÓWÓÕQWÑSSVHHÕRPÝÜX]Q[[^J
BÕRPÝÙ]Û][
    ÌÍÕÓWÓÕQWÑSSVK   ][ÝØÛXÚ×Õ][ÝÊBÌÍÚ[XYÙHHÑÕRR[XYÙSÝÐÜX]JMM
KÊBÑÕRR[XYÙSÝÐYXÛÛ  ÌÍÚ[XYÙK    ][ÝÜÚ[Ì ][ÝËN
BÑÕRR[XYÙSÝÐYXÛÛ ÌÍÚ[XYÙK    ][ÝÜÚ[Ì ][ÝËMBÑÕRR[XYÙSÝÐYXÛÛ  ÌÍÚ[XYÙK    ][ÝÜÚ[Ì ][ÝËÍBÑÕRPÝYUY]×ÔÙ]ÜX[[XYÙSÝ
    ÌÍÚ  ÌÍÚ[XYÙJBÑÕRPÝYUY]×ÐYÚ[]J ÌÍÚBÌÍÒQÕXHHÑÕRPÝYUY]×ÐY
    ÌÍÚ  ÌÎNÕXIÌÎNË
BÜ ÌÍÚHHHÈ
BIÌÍØRQÔÝXÉÌÍÚKLWHHÑÕRPÝYUY]×ÐYÚ[
    ÌÍÚ  ÌÍÒQÕXK ÌÎNÔÝXÌÎNÈ   [È ÌÍÚKKJBQÜ   ÌÍÚHHÈÂBWÑÕRPÝYUY]×ÐYÚ[
    ÌÍÚ  ÌÍØRQÔÝXÉÌÍÚKLWK   ÌÎNÔÝXÔÝXÌÎNÈ  [È ÌÍÚBS^^ÑÕRPÝYUY]×Ñ[]J   ÌÍÚBÑÕRPÝYUY]×Ñ^[
    ÌÍÚ  ÌÍÒQÕXJBÕRTÙ]Ý]J
BÕRTYÚÝÙÊ  ÌÍÕÓWÓÕQK ÌÎNÕÓWÓÕQIÌÎNÊBÚ[HBTÛY
L
BÑ[[ÈÙ[

BQ^][[Â[ÈÛXÚ×Õ
BSØØ[ ÌÍÚ][HHÑÕRPÝYUY]×ÑÙ]Ù[[Û  ÌÍÚBRYÑÕRPÝYUY]×ÑÙ][[J ÌÍÚ  ÌÍÚ][JH  ÉÝÈ  ÌÍÒQÕXH[]PÛÛÛÛUÜ]JÑÕRPÝYUY]×ÑÙ]^
    ÌÍÚ  ÌÍÚ][JH  [ÈÔB[[Â[ÈÓWÓÕQJ  ÌÍÚÛ    ÌÍÚSÙË ÌÍÚ]Ô[K ÌÍÚ[[JBÙÜÙY   ÌÍÚÛ    ÌÍÚSÙË ÌÍÚ]Ô[BØØ[    ÌÍÚÛÛK ÌÍÚRQÛK ÌÍÚPÛÙK    ÌÍÝR ÌÍÚÛY]Y]  ÌÍÚÛY]Y]ÈH ÌÍÚYÝÒÛ
    ÌÍÚH[    ÌÍÚÛY]Y]ÈHÕRPÝÙ][J  ÌÍÚB ÌÍÝRHÝXÝÜX]J  ÌÍÝYÓR  ÌÍÚ[[JB  ÌÍÚÛÛHHÛ
ÝXÝÙ]]J  ÌÍÝR ][ÝÚÛÛI][ÝÊJB ÌÍÚRQÛHHÝXÝÙ]]J  ÌÍÝR ][ÝÒQÛI][ÝÊB   ÌÍÚPÛÙHHÝXÝÙ]]J ÌÍÝR ][ÝÐÛÙI][ÝÊBÝÚ]Ú   ÌÍÚÛÛBØÙH    ÌÍÚÛY]Y]ÂÝÚ]Ú   ÌÍÚPÛÙBBBBPØÙH   ÌÍÓWÐÓPÒÂÕRPÝÙ[Ñ[[^J ÌÍÕÓWÓÕQWÑSSVJB[ÝÚ]Ú[ÝÚ]Ú] ÌÍÑÕRWÔSQTÑÂ[[ÈÏOIÝÕÓWÓÕQ
Edited by BugFix

Best Regards BugFix  

Share this post


Link to post
Share on other sites
BugFix

Thanks for your reply, i'll test it too.


Best Regards BugFix  

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  

×