Sign in to follow this  
Followers 0
KurogamineNox

GUI Help

31 posts in this topic

Okay, What I want to know is how can I add/attach another GUI window.

Like, when the program first loads it is hidden, then after I push a button it shows up, and after the button is pushed again, It Hides again.

Main Window(Button Not Pushed):

Posted Image

http://i766.photobucket.com/albums/xx305/CorruptPictureProductions/Info/Mainwindow.jpg

Main Window(With Button Pushed:)

Posted Image

Note: For some odd reason this forum thing kept making the W in Window on the first picture lowercase ruining the url, though if I put the url in a code section the W stays Uppercase...wierd.

Share this post


Link to post
Share on other sites



Check out the GUI Reference in the help file, the MessageLoop Mode examples include using multiple windows


1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

Ah use the command GUISetState ;)

You create two GUI, and one with GuiSetState(@SW_Show) = It show the GUI and one with GUISetState(@SW_HIDE)

And when you will press the buton it will send the command GUISetState(@SW_SHOW, $GUI2)

Sorry for my bad english :)

Share this post


Link to post
Share on other sites

Okay I am reading this thing

#include <GUIConstantsEx.au3>

$mainwindow = GUICreate("Hello World", 200, 100)
GUICtrlCreateLabel("Hello world! How are you?", 30, 10)
$okbutton = GUICtrlCreateButton("OK", 70, 50, 60)

$dummywindow = GUICreate("Dummy window for testing ", 200, 100)

GUISwitch($mainwindow)
GUISetState(@SW_SHOW)

While 1
  $msg = GUIGetMsg(1)

  Select
    Case $msg[0] = $okbutton
      MsgBox(0, "GUI Event", "You pressed OK!")

    Case $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $mainwindow
      MsgBox(0, "GUI Event", "You clicked CLOSE on the main window! Exiting...")
      ExitLoop
  EndSelect
WEnd

I think I can adapt its coding, but I still need it to have the window like look as though it is attached to the main window(as in the pictures) and have the windows move at the same time and stay in place. I think right Now I will be able to make the button show and hide that second window. My thoughts on having it follow, I have no clue right now. Is there any parameters that can take the boundary off the second window? or at least the buttons on the top of it like in the pictures?

Share this post


Link to post
Share on other sites

Maybe if I put a WinMove() command for the second window(moving it based on the main windows place though) It could loop it inside the While 1 function. I'm not sure, just thinking things that could possibly work, even if it could I just don't know any of the other stuff I would need at this moment also.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I think I can adapt its coding, but I still need it to have the window like look as though it is attached to the main window(as in the pictures) and have the windows move at the same time and stay in place.

in your while loop, you can add a check like...

$g1pos = WinGetPos($gui1)
$g2pos = WinGetPos($gui2)
If $g2pos[0] <>  $g1pos[0] + $g1pos[2] or $g2pos[1] <> $g1pos[1] Then WinMove($gui2,"",$g1pos[0]+$g1pos[2],$g1pos[1])

Is there any parameters that can take the boundary off the second window? or at least the buttons on the top of it like in the pictures?

Checkout window styles in the help file Edited by cameronsdad

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

Thanks, it works.

I am also experimenting with the styles

GUISetStyle($WS_BORDER, "", $dummyWindow)

Also, didn't know you could use the if statement like the way you did.

If $g2pos[0] <>  $g1pos[0] + $g1pos[2] or $g2pos[1] <> $g1pos[1] Then WinMove($gui2,"",$g1pos[0]+$g1pos[2],$g1pos[1])

Share this post


Link to post
Share on other sites

Thanks, it works.

I am also experimenting with the styles

GUISetStyle($WS_BORDER, "", $dummyWindow)

Also, didn't know you could use the if statement like the way you did.

If $g2pos[0] <>  $g1pos[0] + $g1pos[2] or $g2pos[1] <> $g1pos[1] Then WinMove($gui2,"",$g1pos[0]+$g1pos[2],$g1pos[1])

No problem. Glad i could help

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

No problem. Glad i could help

One more thing, How do I make it so that the second window does not show up in the task bar at the bottom of the screen?

Share this post


Link to post
Share on other sites

One more thing, How do I make it so that the second window does not show up in the task bar at the bottom of the screen?

i believe the window styles are key on that one too, but i'm certain it's been covered on the forum

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

i believe the window styles are key on that one too, but i'm certain it's been covered on the forum

Found it.

$WS_EX_TOOLWINDOW

Now I have noticed that if I don't minimize the program, switch to a window like say a web browser, and go back to the program the second window doesn't show up(it basicly is still behind the web browser when the main window returns focus).

I tried

If WinActive($mainwindow) = true Then
    WinSetState(@SW_MAXIMiZE, "", "")
EndIf

Which utterly failed...I'm such a beginner. Any thoughts on that?

Share this post


Link to post
Share on other sites

Found it.

$WS_EX_TOOLWINDOW

Now I have noticed that if I don't minimize the program, switch to a window like say a web browser, and go back to the program the second window doesn't show up(it basicly is still behind the web browser when the main window returns focus).

I tried

If WinActive($mainwindow) = true Then
    WinSetState(@SW_MAXIMiZE, "", "")
EndIf

Which utterly failed...I'm such a beginner. Any thoughts on that?

it's not working because you're not telling it what window to set the state on; so it defaults to the last active window, which you already know to be active.... read up on WinSetState in the help file

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

it's not working because you're not telling it what window to set the state on; so it defaults to the last active window, which you already know to be active.... read up on WinSetState in the help file

Yeah, i also tried this

If WinActive($mainwindow) = true Then
    WinSetOnTop($dummywindow, "", 1)
else
    WinSetOnTop($dummywindow, "", 0)
EndIf

Except WinActive only works half the time. It works at times but also at times like I switch to my web browser, the Window might still be set to always on top.

Just half the time WinSetOnTop/WinActive works half the time(Trying my hardest to work these things out).

Share this post


Link to post
Share on other sites

Except WinActive only works half the time. It works at times but also at times like I switch to my web browser, the Window might still be set to always on top.

Just half the time WinSetOnTop/WinActive works half the time(Trying my hardest to work these things out).

Changing the OnTop flag doesn't change the state of the window, if the main isn't active, use WinSetState() to hide the dummy window

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

I know, Maybe misunderstood. Ill be having a button for the WinSetState() Events.

The OnTop stuff is when the window is being shown, as when the main window isn't activated, its not going to be hidden anyways since its open.

If I set WinSetState instead it would mess my program up, as if I had OnTop, if the values would change correctly.

Window Shows, second window is OnTop

Window isnt active, Second window OnTop = false

Basicly it should get behind other windows.

If I replaced it in the If WinActive statements, Clicking on the second window itself would mess up.

Current code im currently modifying

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



$mainwindow = GUICreate("Hello World", 200, 100)
GUICtrlCreateLabel("Hello world! How are you?", 30, 10)
$okbutton = GUICtrlCreateButton("OK", 70, 50, 60)

$dummywindow = GUICreate("Dummy window for testing ", 200, 100)

GUISetState(@SW_SHOW, $mainwindow)
GUISetStyle($WS_BORDER, $WS_EX_TOOLWINDOW, $dummyWindow)
While 1
  $msg = GUIGetMsg(1)
$g1pos = WinGetPos($mainwindow)
$g2pos = WinGetPos($dummywindow)

If WinActive($mainwindow) = true Then
    WinSetOnTop($dummywindow, "", 1)
else
    WinSetOnTop($dummywindow, "", 0)
EndIf

If $g2pos[0] <>  $g1pos[0] + $g1pos[2] or $g2pos[1] <> $g1pos[1] Then WinMove($dummywindow,"",$g1pos[0]+$g1pos[2],$g1pos[1])

  Select
    Case $msg[0] = $okbutton
      MsgBox(0, "GUI Event", "You pressed OK!")
      GUISetState(@SW_SHOW, $dummywindow)

    Case $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $mainwindow
      MsgBox(0, "GUI Event", "You clicked CLOSE on the main window! Exiting...")
      ExitLoop
  EndSelect
WEnd

Only need to fix this

If WinActive($mainwindow) = true Then

WinSetOnTop($dummywindow, "", 1)

else

WinSetOnTop($dummywindow, "", 0)

EndIf

Until I have what I need. Im close, just not there.

You can see what I mean if you mess around with it(hopefully it produces the same results)

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

What about something like this?

#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#NoTrayIcon

Opt("TrayMenuMode", 1)
Opt('MustDeclareVars', 0)
Opt("GUICloseOnESC", 1)     ;1=ESC closes window when ESC is pressed

;main window global variables
    Global $msgMain, $mainWindow, $mainWidth = 460, $mainHeight = 350   ;main window width & height
    Global $childOpen                       ;Group Pro Version

;child window global positioning variables
Global $childWidth = 300    ;reg window width
Global $childHeight = 150   ;reg window height
Global $childLeft = ($mainWidth - $childWidth)/2 ;child left position from main window
Global $childTop = ($mainHeight - $childHeight)/2 ;child top position from main window


MainGui()


Func MainGui()
    $mainWindow = GUICreate("Main Window", $mainWidth, $mainHeight) ; will create a dialog box that when displayed is centered
    GUISetBkColor(0xE0FFFF) ; will change background color
    
    $childOpen  = GuiCtrlCreateButton   ("Open", 180, 160, 100, 25)
    
    GUISetState(@SW_SHOW)

    ; Run the GUI until the window is closed
    While 1
        $msgMain = GUIGetMsg()
        Select
        Case $msgMain = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msgMain = $childOpen
            Child_Window()
            
        EndSelect
    WEnd
    GUIDelete()
    Exit            
EndFunc ;==>MainGui


Func Child_Window()
Local $pos = WinGetPos("Main Window") ;get position of main window
    Local $x = $pos[0] + $childLeft ;set child x position
    Local $y = $pos[1] + $childTop ;set child y position
Global $childWindow = GUICreate("Child Window", $childWidth, $childHeight, $x, $y, $GUI_SS_DEFAULT_GUI, $WS_EX_TOOLWINDOW, $mainWindow)
GUISetBkColor(0xE0FFbb) ; will change background color
        
Global $cmdCancel = GUICtrlCreateButton("&Cancel"   , 125, 115, 80, 25)
    
    GUISetState(@SW_DISABLE, $childWindow)
    GUISetState(@SW_SHOW, $childWindow)
    _GUICtrlButton_Enable($cmdCancel, True)
    GUISetState(@SW_ENABLE, $childWindow)   

    While 1
    $msgChild = GuiGetMsg($childWindow)
    Select
    Case $msgChild = $GUI_EVENT_CLOSE
        GUISetState(@SW_HIDE, $childWindow)
        ExitLoop
    Case $msgChild = $cmdCancel
        GUISetState(@SW_HIDE, $childWindow)
        ExitLoop
            
    EndSelect
    WEnd

EndFunc ;==>Child window
Edited by ALTIN

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

If WinActive($mainwindow) = true Then
    WinSetOnTop($dummywindow, "", 1)
WinSetState($dummywindow,"",@SW_Show)
else
    WinSetOnTop($dummywindow, "", 0)
WinSetState($dummywindow,"",@SW_Hide)
EndIf

Edited by cameronsdad

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

If WinActive($mainwindow) = true Then
    WinSetOnTop($dummywindow, "", 1)
WinSetState($dummywindow,"",@SW_Show)
else
    WinSetOnTop($dummywindow, "", 0)
WinSetState($dummywindow,"",@SW_Hide)
EndIf

Doesn't work. Remember,

If you set a WinSetState(), WinActive() gets all buggy.

Basicly, if $mainwindow is active, it will set state for $dummywindow

But

that would also unactivate the main window which the else statement would then activate making the dummy window hide.

Returning Focus to the main window and its an infinite loop basicly.

Share this post


Link to post
Share on other sites

Could not try your example.

I recieve an error

*blocked out*\Test2.au3(68,43) : WARNING: $cmdRegister: possibly used before declaration.
        _GUICtrlButton_Enable($cmdRegister,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
*blocked out*\Test2.au3(68,43) : ERROR: $cmdRegister: undeclared global variable.
        _GUICtrlButton_Enable($cmdRegister,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
*blocked out*\Test2.au3 - 1 error(s), 1 warning(s)

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  
Followers 0