Jump to content

GUI question: how to use the same GUI for different pages?


 Share

Recommended Posts

hi,

I worte the following GUI: look at the question within it.

#include <GUIConstants.au3>
$gui=GUICreate ("test",200,200,100,100)
GUICtrlCreatePic ("C:\WINDOWS\system32\oobe\images\backdown.jpg",30,40,100,100)
GuiCtrlSetState(-1,$GUI_DISABLE)
$input1=GUICtrlCreateInput ("",30,50,70,15)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$buttonnext=GUICtrlCreateButton ("next-page",30,150)

GUISetState ()

Do
    $msg=GUIGetMsg ()
    Select
        case $msg=$buttonnext
    ; I need to use here the same GUI and the picture from the previous, but I need the $input1 to hold different values that 
    ; I will put in for next processing. meaning it will not be $input1 anymore but $input2, and $input3 if next pressed again.
    ; how can I use the same GUI without recreating it again, I don't want to reopen a different GUI for that (another window).
    ;
        
Until $msg=$GUI_EVENT_CLOSE

please help.

Link to comment
Share on other sites

Do this first...

$pic=GUICtrlCreatePic ("C:\WINDOWS\system32\oobe\images\backdown.jpg",30,40,100,100)

Then use GUICtrlSetImage($pic,"location of the pic")

If you want the user to enter in the location of the pic then you would just use GUICtrlSetImage($pic,Guictrlread($input1)) (I would rather browse to it)

Link to comment
Share on other sites

Do this first...

$pic=GUICtrlCreatePic ("C:\WINDOWS\system32\oobe\images\backdown.jpg",30,40,100,100)

Then use GUICtrlSetImage($pic,"location of the pic")

If you want the user to enter in the location of the pic then you would just use GUICtrlSetImage($pic,Guictrlread($input1)) (I would rather browse to it)

ok, got it running without those. I am just overwriting the $input1 when pressing the Next Button:

then I can do this:

first page: $A1=$input1

second page: $B1=$input1

so I will have two inputs of both pages.

Link to comment
Share on other sites

ok, got it running without those. I am just overwriting the $input1 when pressing the Next Button:

then I can do this:

first page: $A1=$input1

second page: $B1=$input1

so I will have two inputs of both pages.

well it does not work well this script does what I want, the problem is that I don't want it to reopen a new windows every time but for the first time you press on "next" a next page will open, and when you press on prev the previous page will opened. the problem is that it does it but reopen a new window every time. why?

#include <GUIConstants.au3>
Global $buttonprev, $i
While 1
    
    $gui = GUICreate("test", 200, 200, 100, 100)
    GUICtrlCreateLabel("page-1", 30, 10)
    $pic = GUICtrlCreatePic("C:\WINDOWS\system32\oobe\images\backdown.jpg", 30, 40, 100, 100)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $input1 = GUICtrlCreateInput("", 30, 50, 70, 15)
    $input2 = GUICtrlCreateInput("", 30, 70, 70, 15)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    $buttonnext = GUICtrlCreateButton("next-page", 30, 150)


    GUISetState()

    While 1
        
        $msg = GUIGetMsg()
        Select
            Case $msg = $buttonnext
                $i = GUICtrlRead($input1)
                $s = GUICtrlRead($input2)
                GUIDelete($gui)
                $gui1 = GUICreate("test1", 200, 200, 100, 100)
                GUICtrlCreateLabel("page-2", 30, 10)
                $pic = GUICtrlCreatePic("C:\WINDOWS\system32\oobe\images\backdown.jpg", 30, 40, 100, 100)
                GUICtrlSetState(-1, $GUI_DISABLE)
                $input1 = GUICtrlCreateInput("", 30, 50, 70, 15)
                $input2 = GUICtrlCreateInput("", 30, 70, 70, 15)
                GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
                $buttonnext = GUICtrlCreateButton("prev-page", 30, 150)
                GUISetState()
                While 1
                    $msg1 = GUIGetMsg()
                    Select
                        Case $msg1 = $buttonnext
                            $p = GUICtrlRead($input1)
                            $r = GUICtrlRead($input2)
                            ExitLoop
                        Case $msg1 = $GUI_EVENT_CLOSE
                    EndSelect
                WEnd
                ExitLoop
                
            Case $msg = $GUI_EVENT_CLOSE
                Exit
        EndSelect
        
        
        
    WEnd
WEnd
MsgBox(0, "this is $i", $i)
MsgBox(0, "this is $s", $s)
Link to comment
Share on other sites

your asking it to create a gui inside a loop, so every time you click it it creates a new one. It would probably be better just to use one gui and one loop if you don't actually need two gui's

I will need to delete the controls within the GUI except for the Picture right in every case right?

Link to comment
Share on other sites

Not necessarily, you could control things with disabling or just reusing in different ways. What are you trying to output?

if you run my script you can see that it opens a GUI with two GUICtrlCreateInput. when pressing on the next page I want it to clear the inputs that the user typed in (before that i will save the inputs using guictrlread to $i and $s) and to get new inputs from the user, but, if the user type on the previous page it should see the first two inputs he made. and if the next page again to see what he typed there. all of that using the first and only one GUI.

Link to comment
Share on other sites

if you run my script you can see that it opens a GUI with two GUICtrlCreateInput. when pressing on the next page I want it to clear the inputs that the user typed in (before that i will save the inputs using guictrlread to $i and $s) and to get new inputs from the user, but, if the user type on the previous page it should see the first two inputs he made. and if the next page again to see what he typed there. all of that using the first and only one GUI.

That is it!!!!! I am done!!! thank you for creating guictrldelete function!

here is the code for moving between two pages while going "next" and "prev" and maintaining the "strings" within the inputboxes.

thanks for all your help.

#include <GUIConstants.au3>
Local $p,$s,$m,$i
$gui = GUICreate("test", 200, 200, 100, 100)
$lable1 = GUICtrlCreateLabel("page-1", 30, 10)
$pic = GUICtrlCreatePic("C:\WINDOWS\system32\oobe\images\backdown.jpg", 30, 40, 100, 100)
GUICtrlSetState(-1, $GUI_DISABLE)
$input1 = GUICtrlCreateInput("", 30, 50, 70, 15)
$input2 = GUICtrlCreateInput("", 30, 70, 70, 15)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$buttonnext = GUICtrlCreateButton("next-page", 30, 150)
$prev = GUICtrlCreateButton("Prev-page", 100, 150)
$End = GUICtrlCreateButton ("end",30,180)

GUISetState()

While 1
    
    $msg = GUIGetMsg()
    Select
        Case $msg = $buttonnext
            $i = GUICtrlRead($input1)
            $s = GUICtrlRead($input2)
            GUICtrlDelete($lable1)
            $lable2 = GUICtrlCreateLabel("Page-2", 30, 10)
            GUICtrlDelete ($input1)
            GUICtrlDelete ($input2)
            $input1 = GUICtrlCreateInput($p, 30, 50, 70, 15)
            $input2 = GUICtrlCreateInput($m, 30, 70, 70, 15)
        Case $msg = $prev
            $p = GUICtrlRead($input1)
            $m = GUICtrlRead($input2)
            GUICtrlDelete($lable2)
            $lable1 = GUICtrlCreateLabel("Page-1", 30, 10)
            GUICtrlDelete ($input1)
            GUICtrlDelete ($input2)
            $input1 = GUICtrlCreateInput($i, 30, 50, 70, 15)
            $input2 = GUICtrlCreateInput($s, 30, 70, 70, 15)
        Case $msg = $End
            ExitLoop
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
    
WEnd
MsgBox (0,"this are the var",$i & $s & $p & $m)
Link to comment
Share on other sites

Glad to hear. Another way using the same btn could be:

<code>

#include <GUIConstants.au3>

Global $buttonprev, $i

dim $Data[4]

$gui = GUICreate("test", 200, 200, 100, 100)

$lblPageNo = GUICtrlCreateLabel("page-1", 30, 10,70,20)

$pic = GUICtrlCreatePic("C:\WINDOWS\system32\oobe\images\backdown.jpg", 30, 40, 100, 100)

$input1 = GUICtrlCreateInput("", 30, 50, 70, 15)

$input2 = GUICtrlCreateInput("", 30, 70, 70, 15)

GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

$buttonnext = GUICtrlCreateButton("next-page", 30, 150)

GUISetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $buttonnext

If GUICtrlRead($buttonnext) = "next-page" Then

;read the inputs

$Data[0] = GUICtrlRead($input1)

$Data[1] = GUICtrlRead($input2)

;set the text on the button

GUICtrlSetData($buttonnext,"prev-page")

;set the data in the inputs from the previous data

GUICtrlSetData($input1,$Data[2])

GUICtrlSetData($input2,$Data[3])

;set label

GUICtrlSetData($lblPageNo,'page-2')

ElseIf GUICtrlRead($buttonnext) = "prev-page" Then

;read the inputs

$Data[2] = GUICtrlRead($input1)

$Data[3] = GUICtrlRead($input2)

;set the text on the button

GUICtrlSetData($buttonnext,"next-page")

;set the data in the inputs from the previous data

GUICtrlSetData($input1,$Data[0])

GUICtrlSetData($input2,$Data[1])

;set label

GUICtrlSetData($lblPageNo,'page-1')

EndIf

Case $msg = $GUI_EVENT_CLOSE

Exit

EndSelect

WEnd

</code>

Glad to hear you got it working.

Edited by stampy
Link to comment
Share on other sites

@erezlevi...There is no need todo the following:

1. delete and create the input controls. Look in the help file for Hiding and unhiding controls.

2. Instead of deleting and creating the label controls, look in the help file for Guictrlsetdata().

Edited by DjDeep00
Link to comment
Share on other sites

@erezlevi...There is no need todo the following:

1. delete and create the input controls. Look in the help file for Hiding and unhiding controls.

2. Instead of deleting and creating the label controls, look in the help file for Guictrlsetdata().

Thanks, it works, but how can I hide the prev button so only the next button will be availble first? can't find it.

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...