Ontosy Posted September 18, 2021 Share Posted September 18, 2021 In Wiki Local $g_idButton3 = GUICtrlCreateButton("MsgBox 2", 10, 10, 80, 30) is wrong. Correct is: $g_idButton3 = GUICtrlCreateButton("MsgBox 2", 10, 10, 80, 30) mLipok 1 Link to comment Share on other sites More sharing options...
Danp2 Posted September 18, 2021 Share Posted September 18, 2021 Are you sure? I think the intent is to avoid overwriting the global variable of the same name. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Ontosy Posted September 18, 2021 Author Share Posted September 18, 2021 If avoid overwriting the global variable then "Case $g_idButton3" event in function gui() not fire and example not work. Link to comment Share on other sites More sharing options...
mLipok Posted September 18, 2021 Share Posted September 18, 2021 1 hour ago, Ontosy said: Correct is: $g_idButton3 = GUICtrlCreateButton("MsgBox 2", 10, 10, 80, 30) Fixed. Thanks. 29 minutes ago, Danp2 said: I think the intent is to avoid overwriting the global variable of the same name. No. It was my mistake. Danyfirex 1 Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
Danp2 Posted September 18, 2021 Share Posted September 18, 2021 Ok... I guess I didn't look at it close enough because I was thinking that $g_idButton3 was being used in both GUIs. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
mikell Posted September 18, 2021 Share Posted September 18, 2021 @mLipok There are other strange things in the examples on this page, but they are easy to detect because of the notation : Local $g_idButton2 , etc Danyfirex 1 Link to comment Share on other sites More sharing options...
mLipok Posted September 18, 2021 Share Posted September 18, 2021 (edited) @mikell take a look I hope this is fixed now Edited September 19, 2021 by mLipok typo Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
mLipok Posted September 18, 2021 Share Posted September 18, 2021 Please check also last example for MessageLoop_Mode section Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
JockoDundee Posted September 19, 2021 Share Posted September 19, 2021 1 hour ago, mLipok said: Please check also last example for MessageLoop_Mode section What does initializing to 9999 do? Global $g_hGUI1 = 9999, $g_idButton1 = 9999, $g_idButton2 = 9999, $g_hGUI2 = 9999, $g_idButton3 = 9999 ; Predeclare the variables with dummy values to prevent firing the Case statements, only for GUI this time Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Nine Posted September 19, 2021 Share Posted September 19, 2021 29 minutes ago, JockoDundee said: What does initializing to 9999 do? If you don't assign a value to those controls, they are by default equal to zero. $GUI_EVENT_NONE is also equal to zero. So the Switch Case of any of the controls not preset will be triggered at each round of the loop. Not a good idea... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
JockoDundee Posted September 19, 2021 Share Posted September 19, 2021 1 hour ago, Nine said: If you don't assign a value to those controls, they are by default equal to zero. Ok, but in the code in question all the gui1 variables are assigned to their controls before any event loop is queried. So maybe it’s not always strictly necessary, but just a good practice to get in the habit of doing in case you leave them unassigned? Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
JockoDundee Posted September 19, 2021 Share Posted September 19, 2021 3 hours ago, Nine said: So the Switch Case of any of the controls not preset will be triggered at each round of the loop. What about instead of setting numerous variables to 9999 just doing it like this: Switch GUIGetMsg() Case $GUI_EVENT_NONE ContinueLoop ; or do nothing Case $GUI_EVENT_CLOSE ExitLoop Case $idButton1 MsgBox($MB_OK, "MsgBox 1", "Test from Gui 1") Case $idButton2 GUICtrlSetState($idButton2, $GUI_DISABLE) gui2() Case $g_idButton3 MsgBox($MB_OK, "MsgBox 2", "Test from Gui 2") EndSwitch mikell and Musashi 2 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Nine Posted September 19, 2021 Share Posted September 19, 2021 @JockoDundee Yep, that is just another way to prevent t;his from happening. But I agree, your approach is more elegant than initializing every controls to 9999. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
mikell Posted September 19, 2021 Share Posted September 19, 2021 (edited) I agree , otherwise I can't see any reason why this $GUI_EVENT_NONE constant exists (and is mentioned in the helpfile as an Event ID) Edit BTW this 9999 method is a bit confusing. These examples are intended for 'new coders' so they should be as simple / clear / understandable as possible Edited September 19, 2021 by mikell Link to comment Share on other sites More sharing options...
mLipok Posted September 19, 2021 Share Posted September 19, 2021 I'v just "added Case $GUI_EVENT_NONE to prevent declaring Button = 9999" Take a look:https://www.autoitscript.com/w/index.php?title=Managing_Multiple_GUIs&type=revision&diff=14576&oldid=14575 And then a question popped up in my head: Why to use the same method "9999" for GUI ? For this reason I also added:If Not IsHWnd($aMsg[1]) for preventing subsequent lines from processing when nothing happens Take a look:https://www.autoitscript.com/w/index.php?title=Managing_Multiple_GUIs&type=revision&diff=14577&oldid=14576 ... or just simply here:https://www.autoitscript.com/wiki/Managing_Multiple_GUIs btw. The "9999" has been there since the beginning, I mean since 2012 when @Melba23 created this document. Maybe @Melba23 will want to express his opinion in this discussion. I hope he will like the current form of the WiKi examples. Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
mikell Posted September 19, 2021 Share Posted September 19, 2021 IMHO these new versions are nice About "If Not IsHWnd($aMsg[1])" it's clean, though honestly I'm not sure that it is (in practice) such important. The help file says : "If no cases match the Switch value, then the Case Else section, if present, is executed. If no cases match and Case Else is not defined, then none of the code inside the Switch structure, other than the initial expression, will be executed." and I don't think that checking $aMsg[1] in a Switch statement consumes a lot more resources than the IsHWnd() condition Link to comment Share on other sites More sharing options...
mLipok Posted September 19, 2021 Share Posted September 19, 2021 (edited) Why we was doing change in case of Global $g_idButton3 = 9999 To use $GUI_EVENT_NONE ? 14 hours ago, mikell said: I agree , otherwise I can't see any reason why this $GUI_EVENT_NONE constant exists (and is mentioned in the helpfile as an Event ID) and you also said: 14 hours ago, mikell said: this 9999 method is a bit confusing. These examples are intended for 'new coders' so they should be as simple / clear / understandable as possible I agree, but I would also say that this should be not only: 14 hours ago, mikell said: as simple / clear / understandable as possible but also as properly writen as it is possible, esepecially when it comes to the last example in the "MessageLoop Mode" section which should show all the tricks. So I do some checking and finnaly: Case $GUI_EVENT_NONE ; it will not be necessary as we already check: If Not IsHWnd($aMsg[1]) Then Simply check current version:https://www.autoitscript.com/wiki/Managing_Multiple_GUIs and btw. 1 hour ago, mikell said: I don't think that checking $aMsg[1] in a Switch statement consumes a lot more resources than the IsHWnd() condition Ten years ago I would have been worried about it, now I care more about the correctness of the code. In what sense? I try to follow the motto: Quote "Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Translating it into this case, first check if there is anything to process and then take action. So current version is: expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Global $g_hGUI1, $g_idButton1, $g_idButton2, $g_hGUI2, $g_idButton3 example() Func example() gui1() Local $aMsg While 1 $aMsg = GUIGetMsg(1) ; Use advanced parameter to get array If Not IsHWnd($aMsg[1]) Then ContinueLoop ; preventing subsequent lines from processing when nothing happens Switch $aMsg[1] ; check which GUI sent the message Case $g_hGUI1 Switch $aMsg[0] ; Now check for the messages for $g_hGUI1 Case $GUI_EVENT_CLOSE ; If we get the CLOSE message from this GUI: $g_hGUI1 ... ExitLoop ; ... exit the loop and thus exit the program Case $g_idButton1 MsgBox($MB_OK, "MsgBox 1", "Test from GUI 1") Case $g_idButton2 GUICtrlSetState($g_idButton2, $GUI_DISABLE) gui2() EndSwitch Case $g_hGUI2 Switch $aMsg[0] ; Now check for the messages for $g_hGUI2 Case $GUI_EVENT_CLOSE ; If we get the CLOSE message from this GUI : $g_hGUI2 ... GUIDelete($g_hGUI2) ; ... just delete the GUI ... GUICtrlSetState($g_idButton2, $GUI_ENABLE) ; ... enable button (previously disabled) Case $g_idButton3 MsgBox($MB_OK, "MsgBox", "Test from GUI 2") EndSwitch EndSwitch WEnd EndFunc ;==>example Func gui1() $g_hGUI1 = GUICreate("GUI 1", 200, 200, 100, 100) $g_idButton1 = GUICtrlCreateButton("Msgbox 1", 10, 10, 80, 30) $g_idButton2 = GUICtrlCreateButton("Show GUI 2", 10, 60, 80, 30) GUISetState() EndFunc ;==>gui1 Func gui2() $g_hGUI2 = GUICreate("GUI 2", 200, 200, 350, 350) $g_idButton3 = GUICtrlCreateButton("MsgBox 2", 10, 10, 80, 30) GUISetState() EndFunc ;==>gui2 So instead this following two lines: Case $GUI_EVENT_NONE ; it will not be necessary as we already check: If Not IsHWnd($aMsg[1]) Then ContinueLoop additionally they was used twice in the last examples, currently there is well described single line: If Not IsHWnd($aMsg[1]) Then ContinueLoop ; preventing subsequent lines from processing when nothing happens I think this last example in this WiKi section should be the most universal, the most comprehensive, but at the same time as you said simple and understandable, I think that's exactly what it is now. Do you agree with me on this point? Edited September 19, 2021 by mLipok Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
JockoDundee Posted September 20, 2021 Share Posted September 20, 2021 (edited) @mLipok, although I think you could code this particular example with either the If or the Case, I think it would be better done with the Case. Why? One reason is readability - I think the term Not IsHWnd() is less clear and less descriptive than $GUI_EVENT_NONE. But I think the bigger issue is consistency. Here's the thing - you have two scenarios - single and multiple gui's - in the case of multiple gui's you are getting the array back, and in the single just the event. But you still need a solution for single gui that doesn't require 9999 pre-init. And you won't be getting the array, so the most natural choice is to use $GUI_EVENT_NONE. Then, when moving on to multiple guis, since the learner has already been introduced to the $GUI_EVENT_NONE method, he will already have that test in his GUI1 event handler - if he duplicates the code for gui2, the task is accomplished. Does that make sense? Edited September 20, 2021 by JockoDundee Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
mikell Posted September 20, 2021 Share Posted September 20, 2021 @mLipok Please don't care about my comments. I'm a perverted cat with perverted opinions For example, I never use this wacky "example()" func to put the main gui. I remember the time when this fashion appeared, the purpose was to declare as less global variables as possible, global was evil, $g_var = 666. But where is the consistency when you have to declare all the vars inside this func as global at the top of the script to get it to work ? 22 hours ago, mLipok said: Do you agree with me on this point? Of course I agree, this method is good. Although I agree with everybody, because there are several other ways to skin this cat which seem good too $GUI_EVENT_NONE is also a good way I saw the use of booleans to check gui existence I saw "Global $g_hGUI1 = -1" initial declarations, consistent because $aMsg[1] checks handles and can never be = -1, and btw IMHO "-1" is more understandable than a "9999" coming from nowhere etc And worst of all is the way I personally use to manage multiple guis : #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $g_hGUI1 = GUICreate("GUI 1", 200, 200, 100, 100) $g_idButton1 = GUICtrlCreateButton("Msgbox 1", 10, 10, 80, 30) $g_idButton2 = GUICtrlCreateButton("Show GUI 2", 10, 60, 80, 30) GUISetState(@SW_SHOW, $g_hGUI1) $g_hGUI2 = GUICreate("GUI 2", 200, 200, 350, 350) $g_idButton3 = GUICtrlCreateButton("MsgBox 2", 10, 10, 80, 30) GUISetState(@SW_HIDE, $g_hGUI2) While 1 $aMsg = GUIGetMsg(1) Switch $aMsg[1] ; check which GUI sent the message Case $g_hGUI1 Switch $aMsg[0] ; Now check for the messages for $g_hGUI1 Case $GUI_EVENT_CLOSE ; If we get the CLOSE message from this GUI: $g_hGUI1 ... ExitLoop ; ... exit the loop and thus exit the program Case $g_idButton1 MsgBox($MB_OK, "MsgBox 1", "Test from GUI 1") Case $g_idButton2 GUICtrlSetState($g_idButton2, $GUI_DISABLE) GUISetState(@SW_SHOW, $g_hGUI2) EndSwitch Case $g_hGUI2 Switch $aMsg[0] ; Now check for the messages for $g_hGUI2 Case $GUI_EVENT_CLOSE ; If we get the CLOSE message from this GUI : $g_hGUI2 ... GUISetState(@SW_HIDE, $g_hGUI2) GUICtrlSetState($g_idButton2, $GUI_ENABLE) ; ... enable button (previously disabled) Case $g_idButton3 MsgBox($MB_OK, "MsgBox", "Test from GUI 2") EndSwitch EndSwitch WEnd Link to comment Share on other sites More sharing options...
JockoDundee Posted September 20, 2021 Share Posted September 20, 2021 20 minutes ago, mikell said: global was evil, $g_var = 666 Now that I could get behind… Code hard, but don’t hard code... 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