Jump to content

Is this structure ok? and listview problem


 Share

Recommended Posts

Hi all,

So I'm building my first gui app, and I'm having a few doubts about the structure of it. I've replicated it in very basic form below, and I'd really like to know if I'm doing it correctly, or whether I'm screwing things up in ways I can't foresee.

My second question, is about the listview window. How can I get data from one list to the other? I thought drag/drop, but a button would be good too. Maybe better? And how can I make it so that the user can use ctrl to multiselect?

Any help appreciated - I'd rather get it right now, than plough through to the end and discover I've missed something fundamental... :)

; testing gui structure
#include <guiconstants.au3>

Global $guiMain = GUICreate("Main Window")

GUICtrlCreateGroup("All Combos", 5, 5, 255, 85)
Global $lblLabel = GUICtrlCreateLabel("Here's a label", 10, 20, 100, 25)
Global $cmbCombo = GUICtrlCreateCombo("Test", 120, 20)
Global $lblLabel2 = GUICtrlCreateLabel("Here's a label 2", 10, 55, 100, 25)
Global $cmbCombo2 = GUICtrlCreateCombo("Test 2", 120, 55)

Global $btnButton = GUICtrlCreateButton("Open New Window", 265, 20, 50, 50, BitOR($BS_TOP, $BS_MULTILINE))
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $btnButton
            _ShowWindow2()
    EndSelect
WEnd

Func _ShowWindow2()
    Local $guiShowWindow2 = GUICreate("Buttons")
    Local $array[3] = ["One", "Two", "Three"]
    Local $aBtns[UBound($array)]
    GUICtrlCreateGroup("All Buttons", 5, 5, 255, 85)
    For $i = 0 To Ubound($array)-1
        $aBtns[$i] = GUICtrlCreateButton($array[$i], 10, 15+25*$i, 50, 20)
    Next

    Local $btnButton = GUICtrlCreateButton("Open New Window", 265, 20, 50, 50, BitOR($BS_TOP, $BS_MULTILINE))
    GUISetState()

    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit
            Case $msg = $btnButton
                _ShowWindow3()
            Case Else
                For $iMsg = 0 To UBound($aBtns)-1
                    If $msg = $aBtns[$iMsg] Then
                        MsgBox(0, "Button", GUICtrlRead($aBtns[$iMsg]))
                    EndIf
                Next
        EndSelect
    WEnd
EndFunc

Func _ShowWindow3()
    Local $guiShowWindow3 = GUICreate("Umm, listboxes?")
    Local $lstListBox1 = GUICtrlCreateListView("One thing", 10, 10, 100)
    Local $item11 = GUICtrlCreateListViewItem("lstbox 1.1",$lstListBox1)
    Local $item12 = GUICtrlCreateListViewItem("lstbox 1.2",$lstListBox1)
    Local $item13 = GUICtrlCreateListViewItem("lstbox 1.3",$lstListBox1)
    GuiCtrlSetState(-1,$GUI_DROPACCEPTED) 
    Local $lstListBox2 = GUICtrlCreateListView("Another thing", 120, 10, 100)
    Local $item21 = GUICtrlCreateListViewItem("lstbox 2.1",$lstListBox2)
    Local $item22 = GUICtrlCreateListViewItem("lstbox 2.2",$lstListBox2)
    Local $item23 = GUICtrlCreateListViewItem("lstbox 2.3",$lstListBox2)
    GuiCtrlSetState(-1,$GUI_DROPACCEPTED) 
    Local $btnButton = GUICtrlCreateButton("Exit", 265, 20, 50, 50, BitOR($BS_TOP, $BS_MULTILINE))
    GUISetState()

    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit
            Case $msg = $btnButton
                Exit
        EndSelect
    WEnd
EndFunc
Link to comment
Share on other sites

Why need to use several "GUIGetMsg() loop", use one main loop. Don`t need to create child GUI in function, create them in a script begining, then show or hide when function calling.

Link to comment
Share on other sites

nikink

At this forum you can find a many example about "how create a multi GUI".

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

$guiMain = GUICreate("Main Window", 400, 300, -1, -1, $GUI_SS_DEFAULT_GUI, $WS_EX_ACCEPTFILES)

GUICtrlCreateGroup("All Combos", 5, 5, 255, 85)

$lblLabel = GUICtrlCreateLabel("Here's a label", 10, 20, 100, 25)
$cmbCombo = GUICtrlCreateCombo("Test", 120, 20)
$lblLabel2 = GUICtrlCreateLabel("Here's a label 2", 10, 55, 100, 25)
Global $cmbCombo2 = GUICtrlCreateCombo("Test 2", 120, 55)

GUICtrlCreateGroup("", -99, -99, 1, 1)

$hInput = GUICtrlCreateInput("Drop file here", 10, 100, 200, 20)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)

Global $btnButton1 = GUICtrlCreateButton("Open New Window", 275, 20, 50, 50, BitOR($BS_TOP, $BS_MULTILINE))

;Child GUI
$guiShowWindow2 = GUICreate("Buttons", 400, 300, -1, -1, -1, -1, $guiMain)

Dim $array[3] = ["One", "Two", "Three"]

Dim $aBtns[UBound($array)]

GUICtrlCreateGroup("All Buttons", 5, 5, 255, 85)

For $i = 0 To Ubound($array) - 1
    $aBtns[$i] = GUICtrlCreateButton($array[$i], 10, 15 + 25 * $i, 50, 20)
Next

GUICtrlCreateGroup("", -99, -99, 1, 1)

$btnButton2 = GUICtrlCreateButton("Open New Window", 275, 20, 50, 50, BitOR($BS_TOP, $BS_MULTILINE))

GUISetState(@SW_SHOW, $guiMain)

While 1
    $msg = GUIGetMsg(1)
    Select
        Case ($msg[0] = $GUI_EVENT_CLOSE) And ($msg[1] = $guiMain)
            Exit
        Case ($msg[0] = $GUI_EVENT_CLOSE) And ($msg[1] = $guiShowWindow2)
            _ShowWindow2(2)
        Case $msg[0] = $btnButton1
            _ShowWindow2(1)
    EndSelect
WEnd

Func _ShowWindow2($sFlag)
    If $sFlag = 1 Then
        GUISetState(@SW_DISABLE, $guiMain)
        GUISetState(@SW_SHOW, $guiShowWindow2)
    Else
        GUISetState(@SW_ENABLE, $guiMain)
        GUISetState(@SW_HIDE, $guiShowWindow2)
    EndIf
EndFunc   ;==>_ShowWindow2
:)
Link to comment
Share on other sites

Ahh, thankyou very much.

I have seen lots of multiwindow gui examples on these forums, but they just confuse me, and so many lines of code I start going crosseyed trying to follow them! :)

And I created my example the best way I could think of, using the help file as a guide.

Is there a reason to prefer your example's way, than mine? Efficiency or ease of maintenance? Or is a case of your way is standard, so that's the way it should be done?

I am trying to understand, but like I said, I'm new to gui programming.

(I'd guess my way would endup using too much cpu once a dozen or more windows are open and all the while loops are operating...? And multiple while loops would also be needless wasted lines of code?)

Link to comment
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
 Share

  • Recently Browsing   0 members

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