Jump to content
Sign in to follow this  
ficofico

GUICtrlCreateTreeView

Recommended Posts

ficofico

I've a GUICtrlCreateTreeView created by a for cycle, items are various pdf file in some folder.

At this moment I need a button that when clicked generate's the event "read from selected GUICtrlCreateTreeViewitem and open pdf file".

I'll want intead to generate the event when some GUICtrlCreateTreeViewitem are clicked.... how to?

Thanks

#include <GuiConstants.au3>
#include <ClipBoard.au3>
#include <WindowsConstants.au3>
#Include <Misc.au3>
#include <File.au3>
#include <Process.au3>
#include <Constants.au3>
#include <String.au3>
#include <array.au3>
#include <TreeViewConstants.au3>
#include <GUIConstantsEx.au3>
#include <IE.au3>
#include <StaticConstants.au3>
;#RequireAdmin

GUICreate("Programma consultazione laboratorio",1024,768,0,0)
GUISetState()

$oIE = _IECreateEmbedded ()
$GUIActiveX = GUICtrlCreateObj($oIE, 250, 10, 774, 676)
_IENavigate ($oIE,@scriptdir & "\intro.pdf",0 )

$treeview = GUICtrlCreateTreeView(6, 6, 220, 680, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$ematologia = GUICtrlCreateTreeViewItem("Ematologia", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$biochimica = GUICtrlCreateTreeViewItem("Biochimica", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$coagulazione = GUICtrlCreateTreeViewItem("Coagulazione", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$sierologia = GUICtrlCreateTreeViewItem("Sierologia", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$batteriologia = GUICtrlCreateTreeViewItem("Batteriologia", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$procedure = GUICtrlCreateTreeViewItem("Procedure", $treeview)
GUICtrlSetColor(-1, 0x0000C0)


$cerca=FileFindFirstFile(@ScriptDir & "\ematologia\*.pdf")
dim $arr[1]=[""]
for $numerofile = 1 to 300000 step + 1
$i = 0
_ArraySort($arr)
$file = FileFindNextFile($cerca) 
if @error then exitloop
_ArrayAdd($arr, $file)
$trim=StringTrimright ($file, 4 )
$nome=GUICtrlCreateTreeViewItem($trim, $ematologia)
next
 
$cerca=FileFindFirstFile(@ScriptDir & "\biochimica\*.pdf")
for $numerofile = 1 to 300000 step + 1
$i = 0
$file = FileFindNextFile($cerca) 
if @error then exitloop
_ArrayAdd($arr, $file)
$trim=StringTrimright ($file, 4 )
$nome=GUICtrlCreateTreeViewItem($trim, $biochimica)
next 

$cerca=FileFindFirstFile(@ScriptDir & "\coagulazione\*.pdf")
for $numerofile = 1 to 300000 step + 1
$i = 0
$file = FileFindNextFile($cerca) 
if @error then exitloop
_ArrayAdd($arr, $file)
$trim=StringTrimright ($file, 4 )
$nome=GUICtrlCreateTreeViewItem($trim, $coagulazione)
next 

$cerca=FileFindFirstFile(@ScriptDir & "\sierologia\*.pdf")
for $numerofile = 1 to 300000 step + 1
$i = 0
$file = FileFindNextFile($cerca) 
if @error then exitloop
_ArrayAdd($arr, $file)
$trim=StringTrimright ($file, 4 )
$nome=GUICtrlCreateTreeViewItem($trim, $sierologia)
next 

$cerca=FileFindFirstFile(@ScriptDir & "\batteriologia\*.pdf")
for $numerofile = 1 to 300000 step + 1
$i = 0
$file = FileFindNextFile($cerca) 
if @error then exitloop
_ArrayAdd($arr, $file)
$trim=StringTrimright ($file, 4 )
$nome=GUICtrlCreateTreeViewItem($trim, $batteriologia)
next 

$cerca=FileFindFirstFile(@ScriptDir & "\procedure\*.pdf")
for $numerofile = 1 to 300000 step + 1
$i = 0
$file = FileFindNextFile($cerca) 
if @error then exitloop
_ArrayAdd($arr, $file)
$trim=StringTrimright ($file, 4 )
$nome=GUICtrlCreateTreeViewItem($trim, $procedure)
next 

GUICtrlSetState($ematologia,BitOR($GUI_EXPAND, $GUI_DEFBUTTON))    
GUICtrlSetState($biochimica,BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) 
GUICtrlSetState($sierologia,BitOR($GUI_EXPAND, $GUI_DEFBUTTON))    
GUICtrlSetState($batteriologia,BitOR($GUI_EXPAND, $GUI_DEFBUTTON))  
GUICtrlSetState($coagulazione,BitOR($GUI_EXPAND, $GUI_DEFBUTTON))    
GUICtrlSetState($procedure,BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) 

$Button=GUICtrlCreateButton("LEGGI",10,700,200,20)


While 1

$msg = GUIGetMsg()
select
    
    Case $msg = $GUI_EVENT_CLOSE 
    ExitLoop
        
    Case $msg = $button
    $text = GUICtrlRead($treeview, 1)
    $text2=$text & ".pdf"
        
    if FileExists(@scriptdir & "\ematologia\" & $text2) then
    _IENavigate ($oIE,@scriptdir & "\ematologia\" & $text2,0 )
        
    elseif  FileExists(@scriptdir & "\biochimica\" & $text2) then
    _IENavigate ($oIE,@scriptdir & "\biochimica\" & $text2,0 ) 
    
    elseif FileExists(@scriptdir & "\coagulazione\" & $text2) then
    _IENavigate ($oIE,@scriptdir & "\coagulazione\" & $text2,0 ) 
    
    elseif FileExists(@scriptdir & "\sierologia\" & $text2) then
    _IENavigate ($oIE,@scriptdir & "\sierologia\" & $text2,0 ) 
    
    elseif FileExists(@scriptdir & "\batteriologia\" & $text2) then
    _IENavigate ($oIE,@scriptdir & "\batteriologia\" & $text2,0 ) 
    
    else 
    $apri=fileopen(@scriptdir & "\procedure\" & $text2)
    _IENavigate ($oIE,@scriptdir & "\procedure\" & $text2,0 ) 
    endif
    
endselect
WEnd
GUIDelete()
Exit
Edited by ficofico

Share this post


Link to post
Share on other sites
exodius
This post should give you a good jump on your resolution.

Share this post


Link to post
Share on other sites
ficofico

This post should give you a good jump on your resolution.

Thanks exodius, but I'm not able to modify my script with your suggestion..

I've understand that I need "DllStructSetData" and "dllcall", but post it's written with function, mine not and.... I'm too nooby :idea:

would you like to give me more suggestion? :)

Share this post


Link to post
Share on other sites
exodius

Thanks exodius, but I'm not able to modify my script with your suggestion..

I've understand that I need "DllStructSetData" and "dllcall", but post it's written with function, mine not and.... I'm too nooby :idea:

would you like to give me more suggestion? :)

Credit to rasim for the portion of this that does what you're asking for help with.

#include <GuiConstants.au3>
#include <GuiTreeView.au3>
#include <ClipBoard.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <File.au3>
#include <Process.au3>
#include <Constants.au3>
#include <String.au3>
#include <array.au3>
#include <TreeViewConstants.au3>
#include <GUIConstantsEx.au3>
#include <IE.au3>
#include <StaticConstants.au3>
;#RequireAdmin

GUICreate("Programma consultazione laboratorio", 1024, 768, 0, 0)

$oIE = _IECreateEmbedded()
$GUIActiveX = GUICtrlCreateObj($oIE, 250, 10, 774, 676)
_IENavigate($oIE, @ScriptDir & "\intro.pdf", 0)

$treeview = GUICtrlCreateTreeView(6, 6, 220, 680, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$hTreeView = GUICtrlGetHandle($treeview) ; <--- This declaration is key for getting the WM_Notify to work

$ematologia = GUICtrlCreateTreeViewItem("Ematologia", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$biochimica = GUICtrlCreateTreeViewItem("Biochimica", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$coagulazione = GUICtrlCreateTreeViewItem("Coagulazione", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$sierologia = GUICtrlCreateTreeViewItem("Sierologia", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$batteriologia = GUICtrlCreateTreeViewItem("Batteriologia", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$procedure = GUICtrlCreateTreeViewItem("Procedure", $treeview)
GUICtrlSetColor(-1, 0x0000C0)

$cerca = FileFindFirstFile(@ScriptDir & "\ematologia\*.pdf")
Dim $arr[1] = [""]
For $numerofile = 1 To 300000 Step +1
    $i = 0
    _ArraySort($arr)
    $file = FileFindNextFile($cerca)
    If @error Then ExitLoop
    _ArrayAdd($arr, $file)
    $trim = StringTrimRight($file, 4)
    $nome = GUICtrlCreateTreeViewItem($trim, $ematologia)
Next

$cerca = FileFindFirstFile(@ScriptDir & "\biochimica\*.pdf")
For $numerofile = 1 To 300000 Step +1
    $i = 0
    $file = FileFindNextFile($cerca)
    If @error Then ExitLoop
    _ArrayAdd($arr, $file)
    $trim = StringTrimRight($file, 4)
    $nome = GUICtrlCreateTreeViewItem($trim, $biochimica)
Next

$cerca = FileFindFirstFile(@ScriptDir & "\coagulazione\*.pdf")
For $numerofile = 1 To 300000 Step +1
    $i = 0
    $file = FileFindNextFile($cerca)
    If @error Then ExitLoop
    _ArrayAdd($arr, $file)
    $trim = StringTrimRight($file, 4)
    $nome = GUICtrlCreateTreeViewItem($trim, $coagulazione)
Next

$cerca = FileFindFirstFile(@ScriptDir & "\sierologia\*.pdf")
For $numerofile = 1 To 300000 Step +1
    $i = 0
    $file = FileFindNextFile($cerca)
    If @error Then ExitLoop
    _ArrayAdd($arr, $file)
    $trim = StringTrimRight($file, 4)
    $nome = GUICtrlCreateTreeViewItem($trim, $sierologia)
Next

$cerca = FileFindFirstFile(@ScriptDir & "\batteriologia\*.pdf")
For $numerofile = 1 To 300000 Step +1
    $i = 0
    $file = FileFindNextFile($cerca)
    If @error Then ExitLoop
    _ArrayAdd($arr, $file)
    $trim = StringTrimRight($file, 4)
    $nome = GUICtrlCreateTreeViewItem($trim, $batteriologia)
Next

$cerca = FileFindFirstFile(@ScriptDir & "\procedure\*.pdf")
For $numerofile = 1 To 300000 Step +1
    $i = 0
    $file = FileFindNextFile($cerca)
    If @error Then ExitLoop
    _ArrayAdd($arr, $file)
    $trim = StringTrimRight($file, 4)
    $nome = GUICtrlCreateTreeViewItem($trim, $procedure)
Next

GUICtrlSetState($ematologia, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
GUICtrlSetState($biochimica, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
GUICtrlSetState($sierologia, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
GUICtrlSetState($batteriologia, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
GUICtrlSetState($coagulazione, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
GUICtrlSetState($procedure, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))

;~ $Button = GUICtrlCreateButton("LEGGI", 10, 700, 200, 20)


GUISetState()


GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit

;~      Case $msg = $Button
;~          $text = GUICtrlRead($treeview, 1)
;~          $text2 = $text & ".pdf"

;~          If FileExists(@ScriptDir & "\ematologia\" & $text2) Then
;~              _IENavigate($oIE, @ScriptDir & "\ematologia\" & $text2, 0)

;~          ElseIf FileExists(@ScriptDir & "\biochimica\" & $text2) Then
;~              _IENavigate($oIE, @ScriptDir & "\biochimica\" & $text2, 0)

;~          ElseIf FileExists(@ScriptDir & "\coagulazione\" & $text2) Then
;~              _IENavigate($oIE, @ScriptDir & "\coagulazione\" & $text2, 0)

;~          ElseIf FileExists(@ScriptDir & "\sierologia\" & $text2) Then
;~              _IENavigate($oIE, @ScriptDir & "\sierologia\" & $text2, 0)

;~          ElseIf FileExists(@ScriptDir & "\batteriologia\" & $text2) Then
;~              _IENavigate($oIE, @ScriptDir & "\batteriologia\" & $text2, 0)

;~          Else
;~              $apri = FileOpen(@ScriptDir & "\procedure\" & $text2)
;~              _IENavigate($oIE, @ScriptDir & "\procedure\" & $text2, 0)
;~          EndIf

    EndSelect
WEnd

Func _WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    ConsoleWrite('@@ (28) :(' & @MIN & ':' & @SEC & ') WM_NOTIFY()' & @CR) ;### Function Trace
    Local $tNMHDR, $hWndFrom, $iCode

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

    Switch $hWndFrom
        Case $hTreeView
            Switch $iCode
                Case $NM_CLICK
                    Local $tPOINT = DllStructCreate("int X;int Y")

                    DllStructSetData($tPOINT, "X", MouseGetPos(0))
                    DllStructSetData($tPOINT, "Y", MouseGetPos(1))

                    _ScreenToClient($hTreeView, $tPOINT)

                    Local $iX = DllStructGetData($tPOINT, "X")
                    Local $iY = DllStructGetData($tPOINT, "Y")

                    Local $iItem = _GUICtrlTreeView_HitTestItem($hTreeView, $iX, $iY)

                    If $iItem <> 0 Then
                        $vSelected = _GUICtrlTreeView_GetText($hTreeView, $iItem) & ".pdf"
                        _IENavigate($oIE, @ScriptDir & "\ematologia\" & $vSelected, 0)
                    EndIf
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc

Func _ScreenToClient($hWnd, $tPOINT)
    ConsoleWrite('@@ (58) :(' & @MIN & ':' & @SEC & ') _ScreenToClient()' & @CR) ;### Function Trace
    Local $aRet = DllCall("user32.dll", "int", "ScreenToClient", "hwnd", $hTreeView, "ptr", DllStructGetPtr($tPOINT))
    Return $aRet[0]
EndFunc   ;==>_ScreenToClient

Share this post


Link to post
Share on other sites
ficofico

VERY VERY VERY thanks exodius

Share this post


Link to post
Share on other sites
ficofico

Script work well, but there's something strange....

When I click in some GUICtrlCreateTreeViewItem under "ematologia" or "biochimica" or the other category, I need to double click the first time, but only the first time....each time I click in a new GUICtrlCreateTreeViewItem in a new category..... if I click item under "ematologia" for example there's no problem after the first time, but if I click an item in a new category I need to double click the first time....

Do you know why Exdious?

This is the full code with very simple changes from yours

#include <GuiConstants.au3>
#include <GuiTreeView.au3>
#include <ClipBoard.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <File.au3>
#include <Process.au3>
#include <Constants.au3>
#include <String.au3>
#include <array.au3>
#include <TreeViewConstants.au3>
#include <GUIConstantsEx.au3>
#include <IE.au3>
#include <StaticConstants.au3>
;#RequireAdmin

GUICreate("Programma consultazione laboratorio", 1024, 768, 0, 0)

$oIE = _IECreateEmbedded()
$GUIActiveX = GUICtrlCreateObj($oIE, 250, 10, 774, 676)
_IENavigate($oIE, @ScriptDir & "\intro.pdf", 0)

$treeview = GUICtrlCreateTreeView(6, 6, 220, 680, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$hTreeView = GUICtrlGetHandle($treeview) ; <--- This declaration is key for getting the WM_Notify to work

$ematologia = GUICtrlCreateTreeViewItem("Ematologia", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$biochimica = GUICtrlCreateTreeViewItem("Biochimica", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$coagulazione = GUICtrlCreateTreeViewItem("Coagulazione", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$sierologia = GUICtrlCreateTreeViewItem("Sierologia", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$batteriologia = GUICtrlCreateTreeViewItem("Batteriologia", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$procedure = GUICtrlCreateTreeViewItem("Procedure", $treeview)
GUICtrlSetColor(-1, 0x0000C0)

$cerca = FileFindFirstFile(@ScriptDir & "\ematologia\*.pdf")
Dim $arr[1] = [""]
For $numerofile = 1 To 300000 Step +1
    $i = 0
    _ArraySort($arr)
    $file = FileFindNextFile($cerca)
    If @error Then ExitLoop
    _ArrayAdd($arr, $file)
    $trim = StringTrimRight($file, 4)
    $nome = GUICtrlCreateTreeViewItem($trim, $ematologia)
Next

$cerca = FileFindFirstFile(@ScriptDir & "\biochimica\*.pdf")
For $numerofile = 1 To 300000 Step +1
    $i = 0
    $file = FileFindNextFile($cerca)
    If @error Then ExitLoop
    _ArrayAdd($arr, $file)
    $trim = StringTrimRight($file, 4)
    $nome = GUICtrlCreateTreeViewItem($trim, $biochimica)
Next

$cerca = FileFindFirstFile(@ScriptDir & "\coagulazione\*.pdf")
For $numerofile = 1 To 300000 Step +1
    $i = 0
    $file = FileFindNextFile($cerca)
    If @error Then ExitLoop
    _ArrayAdd($arr, $file)
    $trim = StringTrimRight($file, 4)
    $nome = GUICtrlCreateTreeViewItem($trim, $coagulazione)
Next

$cerca = FileFindFirstFile(@ScriptDir & "\sierologia\*.pdf")
For $numerofile = 1 To 300000 Step +1
    $i = 0
    $file = FileFindNextFile($cerca)
    If @error Then ExitLoop
    _ArrayAdd($arr, $file)
    $trim = StringTrimRight($file, 4)
    $nome = GUICtrlCreateTreeViewItem($trim, $sierologia)
Next

$cerca = FileFindFirstFile(@ScriptDir & "\batteriologia\*.pdf")
For $numerofile = 1 To 300000 Step +1
    $i = 0
    $file = FileFindNextFile($cerca)
    If @error Then ExitLoop
    _ArrayAdd($arr, $file)
    $trim = StringTrimRight($file, 4)
    $nome = GUICtrlCreateTreeViewItem($trim, $batteriologia)
Next

$cerca = FileFindFirstFile(@ScriptDir & "\procedure\*.pdf")
For $numerofile = 1 To 300000 Step +1
    $i = 0
    $file = FileFindNextFile($cerca)
    If @error Then ExitLoop
    _ArrayAdd($arr, $file)
    $trim = StringTrimRight($file, 4)
    $nome = GUICtrlCreateTreeViewItem($trim, $procedure)
Next

GUICtrlSetState($ematologia, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
GUICtrlSetState($biochimica, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
GUICtrlSetState($sierologia, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
GUICtrlSetState($batteriologia, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
GUICtrlSetState($coagulazione, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
GUICtrlSetState($procedure, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))


GUISetState()
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit

    EndSelect
WEnd


Func _WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    ConsoleWrite('@@ (28) :(' & @MIN & ':' & @SEC & ') WM_NOTIFY()' & @CR) ;### Function Trace
    Local $tNMHDR, $hWndFrom, $iCode

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

    Switch $hWndFrom
        Case $hTreeView
            Switch $iCode
                Case $NM_CLICK
                    Local $tPOINT = DllStructCreate("int X;int Y")

                    DllStructSetData($tPOINT, "X", MouseGetPos(0))
                    DllStructSetData($tPOINT, "Y", MouseGetPos(1))

                    _ScreenToClient($hTreeView, $tPOINT)

                    Local $iX = DllStructGetData($tPOINT, "X")
                    Local $iY = DllStructGetData($tPOINT, "Y")

                    Local $iItem = _GUICtrlTreeView_HitTestItem($hTreeView, $iX, $iY)

                    If $iItem <> 0 Then
                        $vSelected = _GUICtrlTreeView_GetText($hTreeView, $iItem) & ".pdf"
                        $text = GUICtrlRead($treeview, 1)
                        $text2 = $text & ".pdf"
                        
                        If FileExists(@ScriptDir & "\ematologia\" & $text2) Then
                            _IENavigate($oIE, @ScriptDir & "\ematologia\" & $vSelected, 0)
                        ElseIf FileExists(@ScriptDir & "\biochimica\" & $text2) Then
                        _IENavigate($oIE, @ScriptDir & "\biochimica\" & $vSelected, 0)

                        ElseIf FileExists(@ScriptDir & "\coagulazione\" & $text2) Then
                        _IENavigate($oIE, @ScriptDir & "\coagulazione\" & $vSelected, 0)

                        ElseIf FileExists(@ScriptDir & "\sierologia\" & $text2) Then
                        _IENavigate($oIE, @ScriptDir & "\sierologia\" & $vSelected, 0)

                        ElseIf FileExists(@ScriptDir & "\batteriologia\" & $text2) Then
                        _IENavigate($oIE, @ScriptDir & "\batteriologia\" & $vSelected, 0)

                        Else
                        _IENavigate($oIE, @ScriptDir & "\procedure\" & $vSelected, 0)
                        EndIf
                    EndIf
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc

Func _ScreenToClient($hWnd, $tPOINT)
    ConsoleWrite('@@ (58) :(' & @MIN & ':' & @SEC & ') _ScreenToClient()' & @CR) ;### Function Trace
    Local $aRet = DllCall("user32.dll", "int", "ScreenToClient", "hwnd", $hTreeView, "ptr", DllStructGetPtr($tPOINT))
    Return $aRet[0]
EndFunc   ;==>_ScreenToClient
Edited by ficofico

Share this post


Link to post
Share on other sites
PsaltyDS

The first click only changes focus, so it doesn't send NM_CLICK.

:idea:

P.S. If you want to react to the control receiving focus, monitor for the WM_NOTIFY message with NM_SETFOCUS code in addition to NM_CLICK.

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
exodius

Script work well, but there's something strange....

When I click in some GUICtrlCreateTreeViewItem under "ematologia" or "biochimica" or the other category, I need to double click the first time, but only the first time....each time I click in a new GUICtrlCreateTreeViewItem in a new category..... if I click item under "ematologia" for example there's no problem after the first time, but if I click an item in a new category I need to double click the first time....

Do you know why Exdious?

This is the full code with very simple changes from yours

You really don't need the GuiCtrlRead and all those if statements...

#include <GuiConstants.au3>
#include <GuiTreeView.au3>
#include <ClipBoard.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <File.au3>
#include <Process.au3>
#include <Constants.au3>
#include <String.au3>
#include <array.au3>
#include <TreeViewConstants.au3>
#include <GUIConstantsEx.au3>
#include <IE.au3>
#include <StaticConstants.au3>
;#RequireAdmin

GUICreate("Programma consultazione laboratorio", 1024, 768, 0, 0)

$oIE = _IECreateEmbedded()
$GUIActiveX = GUICtrlCreateObj($oIE, 250, 10, 774, 676)
_IENavigate($oIE, @ScriptDir & "\intro.pdf", 0)

$treeview = GUICtrlCreateTreeView(6, 6, 220, 680, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$hTreeView = GUICtrlGetHandle($treeview) ; <--- This declaration is key for getting the WM_Notify to work

$ematologia = GUICtrlCreateTreeViewItem("Ematologia", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$biochimica = GUICtrlCreateTreeViewItem("Biochimica", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$coagulazione = GUICtrlCreateTreeViewItem("Coagulazione", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$sierologia = GUICtrlCreateTreeViewItem("Sierologia", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$batteriologia = GUICtrlCreateTreeViewItem("Batteriologia", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$procedure = GUICtrlCreateTreeViewItem("Procedure", $treeview)
GUICtrlSetColor(-1, 0x0000C0)

$cerca = FileFindFirstFile(@ScriptDir & "\ematologia\*.pdf")
Dim $arr[1] = [""]
For $numerofile = 1 To 300000 Step +1
    $i = 0
    _ArraySort($arr)
    $file = FileFindNextFile($cerca)
    If @error Then ExitLoop
    _ArrayAdd($arr, $file)
    $trim = StringTrimRight($file, 4)
    $nome = GUICtrlCreateTreeViewItem($trim, $ematologia)
Next

$cerca = FileFindFirstFile(@ScriptDir & "\biochimica\*.pdf")
For $numerofile = 1 To 300000 Step +1
    $i = 0
    $file = FileFindNextFile($cerca)
    If @error Then ExitLoop
    _ArrayAdd($arr, $file)
    $trim = StringTrimRight($file, 4)
    $nome = GUICtrlCreateTreeViewItem($trim, $biochimica)
Next

$cerca = FileFindFirstFile(@ScriptDir & "\coagulazione\*.pdf")
For $numerofile = 1 To 300000 Step +1
    $i = 0
    $file = FileFindNextFile($cerca)
    If @error Then ExitLoop
    _ArrayAdd($arr, $file)
    $trim = StringTrimRight($file, 4)
    $nome = GUICtrlCreateTreeViewItem($trim, $coagulazione)
Next

$cerca = FileFindFirstFile(@ScriptDir & "\sierologia\*.pdf")
For $numerofile = 1 To 300000 Step +1
    $i = 0
    $file = FileFindNextFile($cerca)
    If @error Then ExitLoop
    _ArrayAdd($arr, $file)
    $trim = StringTrimRight($file, 4)
    $nome = GUICtrlCreateTreeViewItem($trim, $sierologia)
Next

$cerca = FileFindFirstFile(@ScriptDir & "\batteriologia\*.pdf")
For $numerofile = 1 To 300000 Step +1
    $i = 0
    $file = FileFindNextFile($cerca)
    If @error Then ExitLoop
    _ArrayAdd($arr, $file)
    $trim = StringTrimRight($file, 4)
    $nome = GUICtrlCreateTreeViewItem($trim, $batteriologia)
Next

$cerca = FileFindFirstFile(@ScriptDir & "\procedure\*.pdf")
For $numerofile = 1 To 300000 Step +1
    $i = 0
    $file = FileFindNextFile($cerca)
    If @error Then ExitLoop
    _ArrayAdd($arr, $file)
    $trim = StringTrimRight($file, 4)
    $nome = GUICtrlCreateTreeViewItem($trim, $procedure)
Next

GUICtrlSetState($ematologia, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
GUICtrlSetState($biochimica, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
GUICtrlSetState($sierologia, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
GUICtrlSetState($batteriologia, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
GUICtrlSetState($coagulazione, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
GUICtrlSetState($procedure, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))


GUISetState()
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit

    EndSelect
WEnd


Func _WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    ConsoleWrite('@@ (28) :(' & @MIN & ':' & @SEC & ') WM_NOTIFY()' & @CR) ;### Function Trace
    Local $tNMHDR, $hWndFrom, $iCode

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

    Switch $hWndFrom
        Case $hTreeView
            Switch $iCode
                Case $NM_CLICK
                    Local $tPOINT = DllStructCreate("int X;int Y")

                    DllStructSetData($tPOINT, "X", MouseGetPos(0))
                    DllStructSetData($tPOINT, "Y", MouseGetPos(1))

                    _ScreenToClient($hTreeView, $tPOINT)

                    Local $iX = DllStructGetData($tPOINT, "X")
                    Local $iY = DllStructGetData($tPOINT, "Y")

                    Local $iItem = _GUICtrlTreeView_HitTestItem($hTreeView, $iX, $iY)

                    If $iItem <> 0 Then
                        $vSelected = _GUICtrlTreeView_GetText($hTreeView, $iItem) & ".pdf"
                        ToolTip($vSelected, 0, 0)

                        If FileExists(@ScriptDir & "\ematologia\" & $vSelected) Then
                            _IENavigate($oIE, @ScriptDir & "\ematologia\" & $vSelected, 0)
                        EndIf
                    EndIf
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc

Func _ScreenToClient($hWnd, $tPOINT)
    ConsoleWrite('@@ (58) :(' & @MIN & ':' & @SEC & ') _ScreenToClient()' & @CR) ;### Function Trace
    Local $aRet = DllCall("user32.dll", "int", "ScreenToClient", "hwnd", $hTreeView, "ptr", DllStructGetPtr($tPOINT))
    Return $aRet[0]
EndFunc   ;==>_ScreenToClient

Share this post


Link to post
Share on other sites
ficofico

Very very thanks!!!!... now it work's very well... but I've added all the if statment :idea:

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  

×