BatMan22 Posted February 9, 2018 Share Posted February 9, 2018 So I'm trying to design a 'helper' utility that calls other Forms from the main form page with a button click, I look at a bunch of examples and what I wrote below makes sense to me.. I'm hoping there's nothing fundamentally wrong with it.. Can anyone tell me if my setup is flawed? Also once every few clicks for some reason the window goes behind the SciTE window, I even added WinActivate and still no change. Ideas? expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Start() Func Start() Global $Form1 = GUICreate("McCampbell Helper - Main Page", 615, 438, 192, 124) $Button1 = GUICtrlCreateButton("SampleLoopCalc", 24, 96, 265, 65) $Button2 = GUICtrlCreateButton("VolumeConv", 24, 176, 265, 49) $Button3 = GUICtrlCreateButton("SurfaceAreaConv", 32, 240, 257, 49) $Button4 = GUICtrlCreateButton("ConcentrationConv", 32, 304, 257, 49) GUISetState(@SW_SHOW, $Form1) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 SampleLoopCalc() Case $Button2 VolumeConv() Case $Button3 SurfaceAreaConv() Case $Button4 ConcentrationConv() EndSwitch WEnd EndFunc ;==>Start Func SampleLoopCalc() GUISetState(@SW_HIDE, $Form1) GUIDelete($Form1) $Form2 = GUICreate("Sample Loop Volume Calculator", 615, 438, 192, 124) GUISetState(@SW_SHOW, $Form2) WinActivate($Form2) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUISetState(@SW_SHOW, $Form1) GUISetState(@SW_HIDE, $Form2) GUIDelete($Form2) Start() EndSwitch WEnd EndFunc ;==>SampleLoopCalc Func VolumeConv() GUISetState(@SW_HIDE, $Form1) GUIDelete($Form1) $Form3 = GUICreate("Volume Converter", 615, 438, 192, 124) GUISetState(@SW_SHOW, $Form3) WinActivate($Form3) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUISetState(@SW_SHOW, $Form1) GUISetState(@SW_HIDE, $Form3) GUIDelete($Form3) Start() EndSwitch WEnd EndFunc ;==>VolumeConv Func SurfaceAreaConv() GUISetState(@SW_HIDE, $Form1) GUIDelete($Form1) $Form4 = GUICreate("Surface Area Converter", 615, 438, 192, 124) GUISetState(@SW_SHOW, $Form4) WinActivate($Form4) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUISetState(@SW_SHOW, $Form1) GUISetState(@SW_HIDE, $Form4) GUIDelete($Form4) Start() EndSwitch WEnd EndFunc ;==>SurfaceAreaConv Func ConcentrationConv() GUISetState(@SW_HIDE, $Form1) GUIDelete($Form1) $Form5 = GUICreate("Concentration Converter", 615, 438, 192, 124) GUISetState(@SW_SHOW, $Form5) WinActivate($Form5) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUISetState(@SW_SHOW, $Form1) GUISetState(@SW_HIDE, $Form5) GUIDelete($Form5) Start() EndSwitch WEnd EndFunc ;==>ConcentrationConv Link to comment Share on other sites More sharing options...
Subz Posted February 9, 2018 Share Posted February 9, 2018 Just a quick glance but I see that when you click a button, the new form function, you hide $Form1 and then delete $Form1 and then you use GuiSetState(@SW_SHOW, $Form1) during exit, which no longer exists and then call the Start() function which recreates $Form1. So either remove GuiDelete($Form1) and the Start() function from $GUI_EVENT_CLOSE and just use @SW_HIDE/@SW_SHOW for the form or delete the GUISetState(@SW_HIDE, $Form1) at the top of your function and GUISetState(@SW_SHOW, $Form1) from $GUI_EVENT_CLOSE. Hope that makes sense. BatMan22 1 Link to comment Share on other sites More sharing options...
BatMan22 Posted February 9, 2018 Author Share Posted February 9, 2018 @Subz Thanks, nice catch, fixed. I just deleted the GUISetState(@SW_HIDE, $Form1) from the starting of the function and GUISetState(@SW_SHOW, $Form1) from $GUI_EVENT_CLOSE. I attached a GIF of what my window appearance issue is. Can anyone explain this? It won't come back on top until I double click on the title bar... Link to comment Share on other sites More sharing options...
Subz Posted February 9, 2018 Share Posted February 9, 2018 Not sure if your code is the same, but I can't trigger the behaviour although I'm on Windows 10 1703 x64 Enterprise: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Start() Func Start() Global $Form1 = GUICreate("McCampbell Helper - Main Page", 615, 438, 192, 124) $Button1 = GUICtrlCreateButton("SampleLoopCalc", 24, 96, 265, 65) $Button2 = GUICtrlCreateButton("VolumeConv", 24, 176, 265, 49) $Button3 = GUICtrlCreateButton("SurfaceAreaConv", 32, 240, 257, 49) $Button4 = GUICtrlCreateButton("ConcentrationConv", 32, 304, 257, 49) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 GUIDelete($Form1) SampleLoopCalc() Case $Button2 GUIDelete($Form1) VolumeConv() Case $Button3 GUIDelete($Form1) SurfaceAreaConv() Case $Button4 GUIDelete($Form1) ConcentrationConv() EndSwitch WEnd EndFunc ;==>Start Func SampleLoopCalc() $Form2 = GUICreate("Sample Loop Volume Calculator", 615, 438, 192, 124) GUISetState(@SW_SHOW, $Form2) WinActivate($Form2) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete($Form2) Start() EndSwitch WEnd EndFunc ;==>SampleLoopCalc Func VolumeConv() $Form3 = GUICreate("Volume Converter", 615, 438, 192, 124) GUISetState(@SW_SHOW, $Form3) WinActivate($Form3) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete($Form3) Start() EndSwitch WEnd EndFunc ;==>VolumeConv Func SurfaceAreaConv() $Form4 = GUICreate("Surface Area Converter", 615, 438, 192, 124) GUISetState(@SW_SHOW, $Form4) WinActivate($Form4) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete($Form4) Start() EndSwitch WEnd EndFunc ;==>SurfaceAreaConv Func ConcentrationConv() $Form5 = GUICreate("Concentration Converter", 615, 438, 192, 124) GUISetState(@SW_SHOW, $Form5) WinActivate($Form5) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete($Form5) Start() EndSwitch WEnd EndFunc ;==>ConcentrationConv BatMan22 1 Link to comment Share on other sites More sharing options...
BatMan22 Posted February 9, 2018 Author Share Posted February 9, 2018 (edited) @Subz Your code fixed it.. Only difference between your code and my code that I can see is that I had the gui deletes in the function themselves.. Wonder why it mattered... Either way, thanks Fixed. Bad code is below. Nope, your code does the same thing too. One out of every 25 clicks or so.. the window goes to the back. Interesting. I'm on Windows 7 Ultimate x64. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Start() Func Start() Global $Form1 = GUICreate("McCampbell Helper - Main Page", 615, 438, 192, 124) $Button1 = GUICtrlCreateButton("SampleLoopCalc", 24, 96, 265, 65) $Button2 = GUICtrlCreateButton("VolumeConv", 24, 176, 265, 49) $Button3 = GUICtrlCreateButton("SurfaceAreaConv", 32, 240, 257, 49) $Button4 = GUICtrlCreateButton("ConcentrationConv", 32, 304, 257, 49) GUISetState(@SW_SHOW, $Form1) WinActivate($Form1) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 SampleLoopCalc() Case $Button2 VolumeConv() Case $Button3 SurfaceAreaConv() Case $Button4 ConcentrationConv() EndSwitch WEnd EndFunc ;==>Start Func SampleLoopCalc() ;~ GUISetState(@SW_HIDE, $Form1) GUIDelete($Form1) $Form2 = GUICreate("Sample Loop Volume Calculator", 615, 438, 192, 124) GUISetState(@SW_SHOW, $Form2) WinActivate($Form2) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUISetState(@SW_HIDE, $Form2) GUIDelete($Form2) Start() EndSwitch WEnd EndFunc ;==>SampleLoopCalc Func VolumeConv() ;~ GUISetState(@SW_HIDE, $Form1) GUIDelete($Form1) $Form3 = GUICreate("Volume Converter", 615, 438, 192, 124) GUISetState(@SW_SHOW, $Form3) WinActivate($Form3) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUISetState(@SW_HIDE, $Form3) GUIDelete($Form3) Start() EndSwitch WEnd EndFunc ;==>VolumeConv Func SurfaceAreaConv() ;~ GUISetState(@SW_HIDE, $Form1) GUIDelete($Form1) $Form4 = GUICreate("Surface Area Converter", 615, 438, 192, 124) GUISetState(@SW_SHOW, $Form4) WinActivate($Form4) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUISetState(@SW_HIDE, $Form4) GUIDelete($Form4) Start() EndSwitch WEnd EndFunc ;==>SurfaceAreaConv Func ConcentrationConv() ;~ GUISetState(@SW_HIDE, $Form1) GUIDelete($Form1) $Form5 = GUICreate("Concentration Converter", 615, 438, 192, 124) GUISetState(@SW_SHOW, $Form5) WinActivate($Form5) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUISetState(@SW_HIDE, $Form5) GUIDelete($Form5) Start() EndSwitch WEnd EndFunc ;==>ConcentrationConv Edited February 9, 2018 by BatMan22 Link to comment Share on other sites More sharing options...
KickStarter15 Posted February 9, 2018 Share Posted February 9, 2018 @BatMan22, I have Win7 32bit and no issue found doing below code. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Start() Sleep(10) Func Start() Global $Form1 = GUICreate("McCampbell Helper - Main Page", 615, 438, 192, 124) $Button1 = GUICtrlCreateButton("SampleLoopCalc", 24, 96, 265, 65) $Button2 = GUICtrlCreateButton("VolumeConv", 24, 176, 265, 49) $Button3 = GUICtrlCreateButton("SurfaceAreaConv", 32, 240, 257, 49) $Button4 = GUICtrlCreateButton("ConcentrationConv", 32, 304, 257, 49) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 GUIDelete($Form1) SampleLoopCalc() Case $Button2 GUIDelete($Form1) VolumeConv() Case $Button3 GUIDelete($Form1) SurfaceAreaConv() Case $Button4 GUIDelete($Form1) ConcentrationConv() EndSwitch WEnd EndFunc ;==>Start Func SampleLoopCalc() $Form2 = GUICreate("Sample Loop Volume Calculator", 615, 438, 192, 124) GUISetState(@SW_SHOW, $Form2) WinActivate($Form2, "") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete($Form2) Start() EndSwitch WEnd EndFunc ;==>SampleLoopCalc Func VolumeConv() $Form3 = GUICreate("Volume Converter", 615, 438, 192, 124) GUISetState(@SW_SHOW, $Form3) WinActivate($Form3, "") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete($Form3) Start() EndSwitch WEnd EndFunc ;==>VolumeConv Func SurfaceAreaConv() $Form4 = GUICreate("Surface Area Converter", 615, 438, 192, 124) GUISetState(@SW_SHOW, $Form4) WinActivate($Form4, "") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete($Form4) Start() EndSwitch WEnd EndFunc ;==>SurfaceAreaConv Func ConcentrationConv() $Form5 = GUICreate("Concentration Converter", 615, 438, 192, 124) GUISetState(@SW_SHOW, $Form5) WinActivate($Form5, "") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete($Form5) Start() EndSwitch WEnd EndFunc ;==>ConcentrationConv BatMan22 1 Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
BatMan22 Posted February 9, 2018 Author Share Posted February 9, 2018 I wonder why my code was glitching then.. Maybe I'll just sleep for 200ms between screens to allow for re-draw time I guess? Link to comment Share on other sites More sharing options...
Zedna Posted February 9, 2018 Share Posted February 9, 2018 Definitely read this Wiki artickle: https://www.autoitscript.com/wiki/Managing_Multiple_GUIs BatMan22 1 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
KickStarter15 Posted February 10, 2018 Share Posted February 10, 2018 I guess so.... using sleep can control your GUI, but as what I did in your code is just added the below. Start() Sleep(10); sleep here. and Although it's an optional but it matters when I added an empty sting for the text of the window to activate. WinActivate($Form2, "") ; empty string. Then, the glitch is not showing anymore. Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
OldGuyWalking Posted February 11, 2018 Share Posted February 11, 2018 I've had a problem with _ArrayDisplay and MsgBox disappearing behind the SCite screen. I frequently use one or the other of those when I'm debugging something and running an app from Scite using F5. It's most noticeable to me when I setup a MsgBox or use _ArrayDisplay inside a loop. When the dialog appears and the app pauses I'll click the x on the dialog to close it so the loop will continue. The dialog will pop backup with the new info from the loop. Randomly, Scite will lose focus and the next dialog will disappear. I have to click on Scite so it has focus and then on the dialogs icon on the taskbar. I have one app I run and noticed that if I place a from in the spot where MsgBox or _ArrayDisplay will popup, those dialogs never disappear. I'm using SCite Version 3.7.3, AutoIT version 3.3.14.0, Windows 7 sp1. It's a tolerable annoyance. I tried various things to try to fix it but had no luck. Link to comment Share on other sites More sharing options...
TheSaint Posted February 11, 2018 Share Posted February 11, 2018 Only had a quick look at your code, but noticed none of your child windows has the parent window declared in the GUICreate statement. You also don't have any of the GUIs set as ON TOP, in the same GUICreate statement. $Form2 = GUICreate("Sample Loop Volume Calculator", 615, 438, 192, 124, -1, $WS_EX_TOPMOST, $Form1) Further to that, I find that setting the RESTORE state can sometimes be helpful, in place of WinActivate ... or use both. GUISetState(@SW_RESTORE, $Form2) Earthshine 1 Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
Earthshine Posted February 11, 2018 Share Posted February 11, 2018 (edited) I just logged everything to a log file and the console. Log4a.au3 rules I was thinking you could modify log for a two also pop to your message box. That would be sweet because if you capture the right information there’s your debug Edited February 11, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now