Jump to content

[SOLVED] Changing GUI which respect to treeviewitem


Recommended Posts

 

My goal is...

Spoiler

I tried to prepare a report file and this file will be created by another program.
And if someone have problem, user will click create report button and will send an .au3 file to developer.
Anyway..


I was trying to build report au3 file gui but I stucked in this way.

I want to change child GUIs when user click treeviewitems or childtreeviewitems but i couldn't do it.. 
Here there is an image of my report GUI

Spoiler

1.png

My codes are here.. IT is realy helpfull if you can look. Thnx.

Spoiler

 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <WinAPI.au3>
#include <GuiTreeView.au3>
Global $FormMain, $form_si, $form_i, $form_L, $form_P,  $TreeViewStyle, $TreeViewExStyle, $g_hMain, $g_hSystemInfos, _
       $g_hSettings, $g_hProblemOfUser, $g_hSettings_Info ,$g_hSettings_Log
guimain()
GUISetState(@SW_SHOW, $FormMain)
GUISetState(@SW_HIDE, $form_si)
GUISetState(@SW_HIDE,$form_i)
GUISetState(@SW_HIDE,$form_P)
GUISetState(@SW_HIDE,$form_L)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
;~ ############################## PROBLEM STARTS HERE #############################
        ;If user click "$g_hSystemInfos" then show $form_si gui and hide other child gui
        ;If user click "$g_hSettings_Log" then show $form_si gui and hide other child gui
        ;If user click "$g_hSettings_Info" then show $form_L gui and hide other child gui
        ;If user click "$g_hProblemOfUser" then show $form_P gui and hide other child gui
;~ ############################## PROBLEM ENDS HERE #############################

        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func guimain()
    $FormMain = GUICreate("Form1", 441, 360, 192, 124,BitOR( $WS_SYSMENU, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_BORDER))
    GUISetBkColor(0xFFFFFF)
    $TreeViewStyle = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_TRACKSELECT)
    $TreeViewExStyle = $WS_EX_CLIENTEDGE
    Local $x, $y
    $x = 5
    $y = 5
    $g_hMain = GUICtrlCreateTreeView($x, $y, 100, 250, $TreeViewStyle, $TreeViewExStyle) ; MainTreeView
    $g_hSystemInfos = _GUICtrlTreeView_Add($g_hMain, 0, "System Infos")
    $g_hSettings = _GUICtrlTreeView_Add($g_hMain, 0, "Settings")
    $g_hProblemOfUser = _GUICtrlTreeView_Add($g_hMain, 0, "Problem of User")
        ;Log
        $g_hSettings_Log = _GUICtrlTreeView_AddChild($g_hMain, $g_hSettings, "Log")
        ;Info
        $g_hSettings_Info = _GUICtrlTreeView_AddChild($g_hMain, $g_hSettings, "Info")

    systeminfo()
    Infos()
    logg()
    Prob()
EndFunc
Func systeminfo()
    $form_si = GUICreate("System Info", 100, 100, 120, 50, BitOR($WS_CHILD, $WS_BORDER), -1, $FormMain)
    $Lblsysteminfo = GUICtrlCreateLabel("systeminfo",0,0,50,-1)
EndFunc
Func Infos()
    $form_i = GUICreate("Info", 100, 100, 120, 50, BitOR($WS_CHILD, $WS_BORDER), -1, $FormMain)
    $Lblinfo = GUICtrlCreateLabel("Info",0,0,50,-1)
EndFunc
Func logg()
    $form_L = GUICreate("Log", 100, 100, 120, 50, BitOR($WS_CHILD, $WS_BORDER), -1, $FormMain)
    $LblLog = GUICtrlCreateLabel("Log",0,0,50,-1)
EndFunc
Func Prob()
    $form_P = GUICreate("Problem", 100, 100, 120, 50, BitOR($WS_CHILD, $WS_BORDER), -1, $FormMain)
    $Lblproblem = GUICtrlCreateLabel("Problem",0,0,50,-1)
EndFunc

 

 

 



Solution : 


Thanx @abberration for quick help

Edited by ratakantez
Link to comment
Share on other sites

There are probably better ways to do it, but here's one that works:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <WinAPI.au3>
#include <GuiTreeView.au3>
#include <Array.au3>

Global $form_si, $form_i, $form_L, $form_P

    $FormMain = GUICreate("Form1", 441, 360, 192, 124,BitOR( $WS_SYSMENU, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_BORDER))
    GUISetBkColor(0xFFFFFF)
    $TreeViewStyle = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_TRACKSELECT)
    $TreeViewExStyle = $WS_EX_CLIENTEDGE
    Local $x, $y
    $x = 5
    $y = 5
    $g_hMain = GUICtrlCreateTreeView($x, $y, 100, 250, $TreeViewStyle, $TreeViewExStyle) ; MainTreeView
    $g_hSystemInfos = _GUICtrlTreeView_Add($g_hMain, 0, "System Infos")
    $g_hSettings = _GUICtrlTreeView_Add($g_hMain, 0, "Settings")
    $g_hProblemOfUser = _GUICtrlTreeView_Add($g_hMain, 0, "Problem of User")
        ;Log
        $g_hSettings_Log = _GUICtrlTreeView_AddChild($g_hMain, $g_hSettings, "Log")
        ;Info
        $g_hSettings_Info = _GUICtrlTreeView_AddChild($g_hMain, $g_hSettings, "Info")
    $hDummy = GUICtrlCreateDummy()
    GUISetState(@SW_SHOW, $FormMain)
    GUIRegisterMsg($WM_COMMAND, "MyFunc")

    systeminfo()
    Infos()
    logg()
    Prob()
    _ClearGuis()
    GUISetState(@SW_SHOW, $form_si)
    Global $a_Controls[2][4] = [[$g_hSystemInfos,$g_hProblemOfUser,$g_hSettings_Log,$g_hSettings_Info],[$form_si,$form_i,$form_L,$form_P]]

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $GUI_EVENT_PRIMARYDOWN
                _ClearGuis()
                For $i = 0 To 3
                    $h_Focus = _GUICtrlTreeView_GetSelected($g_hMain, $a_Controls[0][$i])
                    If $h_Focus = True Then
                        GUISetState(@SW_SHOW, $a_Controls[1][$i])
                    EndIf
                Next
        EndSwitch
    WEnd


Func _ClearGuis()
    GUISetState(@SW_HIDE, $form_si)
    GUISetState(@SW_HIDE, $form_i)
    GUISetState(@SW_HIDE, $form_L)
    GUISetState(@SW_HIDE, $form_P)
EndFunc

Func systeminfo()
    $form_si = GUICreate("System Info", 100, 100, 120, 50, BitOR($WS_CHILD, $WS_BORDER), -1, $FormMain)
    $Lblsysteminfo = GUICtrlCreateLabel("systeminfo",0,0,50,-1)
EndFunc
Func Infos()
    $form_i = GUICreate("Info", 100, 100, 120, 50, BitOR($WS_CHILD, $WS_BORDER), -1, $FormMain)
    $Lblinfo = GUICtrlCreateLabel("Info",0,0,50,-1)
EndFunc
Func logg()
    $form_L = GUICreate("Log", 100, 100, 120, 50, BitOR($WS_CHILD, $WS_BORDER), -1, $FormMain)
    $LblLog = GUICtrlCreateLabel("Log",0,0,50, -1)
EndFunc
Func Prob()
    $form_P = GUICreate("Problem", 100, 100, 120, 50, BitOR($WS_CHILD, $WS_BORDER), -1, $FormMain)
    $Lblproblem = GUICtrlCreateLabel("Problem",0,0,50,-1)
EndFunc

This could all be condensed into smaller code, specifically, instead of using multiple GUIs that are shown and hidden, you could just use one GUI with only one label and simply update the text in the label. 

I like putting GUI items into arrays so I can cycle them through a loop, which is why there was $a_Controls added. 

If you have any questions about anything, feel free to ask!

Link to comment
Share on other sites

And here's some simpler code like I mentioned:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <WinAPI.au3>
#include <GuiTreeView.au3>
#include <Array.au3>

$FormMain = GUICreate("Form1", 441, 360, 192, 124,BitOR( $WS_SYSMENU, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_BORDER))
GUISetBkColor(0xFFFFFF)
$TreeViewStyle = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_TRACKSELECT)
$TreeViewExStyle = $WS_EX_CLIENTEDGE
Local $x, $y
$x = 5
$y = 5
$g_hMain = GUICtrlCreateTreeView($x, $y, 100, 250, $TreeViewStyle, $TreeViewExStyle) ; MainTreeView
$g_hSystemInfos = _GUICtrlTreeView_Add($g_hMain, 0, "System Infos")
$g_hSettings = _GUICtrlTreeView_Add($g_hMain, 0, "Settings")
$g_hProblemOfUser = _GUICtrlTreeView_Add($g_hMain, 0, "Problem of User")
    ;Log
    $g_hSettings_Log = _GUICtrlTreeView_AddChild($g_hMain, $g_hSettings, "Log")
    ;Info
    $g_hSettings_Info = _GUICtrlTreeView_AddChild($g_hMain, $g_hSettings, "Info")
$hDummy = GUICtrlCreateDummy()
GUISetState(@SW_SHOW, $FormMain)

$sSystemInfo = "System Information"
$sInfo = "Info..."
$sLog = "Logs go here"
$sProb = "This user has a problem."

$form_i = GUICreate("", 100, 100, 120, 50, BitOR($WS_CHILD, $WS_BORDER), -1, $FormMain)
$Lblinfo = GUICtrlCreateLabel($sSystemInfo,0,0,100,100)
GUISetState(@SW_SHOW, $form_i)

Global $a_Controls[2][4] = [[$g_hSystemInfos,$g_hProblemOfUser,$g_hSettings_Log,$g_hSettings_Info],[$sSystemInfo,$sProb,$sLog,$sInfo]]

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            GUICtrlSetData($Lblinfo, "")
            For $i = 0 To 3
                If _GUICtrlTreeView_GetSelected($g_hMain, $a_Controls[0][$i]) = True Then
                    GUICtrlSetData($Lblinfo, $a_Controls[1][$i])
                    ExitLoop
                EndIf
            Next
    EndSwitch
WEnd

 

Edited by abberration
Fixed a little error.
Link to comment
Share on other sites

  • ratakantez changed the title to [SOLVED] Changing GUI which respect to treeviewitem

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...