Myicq Posted March 8, 2014 Share Posted March 8, 2014 I am developing some input forms (popup) for a touchscreen/ Kiosk style application. Most is done. But I would like to make my input forms more "independent", eventually be usable later in a UDF. My current approach works with global variables, but I feel that this is a wrong way. My idea of how I would like this to work: ; include stuff as needed Opt("GUIOnEventMode", 1) ; ============ MAIN FORM =============== $Form1 = GUICreate("Sample", 1024, 650, 0, 0) ; === Do it button $Button1 = GUICtrlCreateButton("Get value", 736, 8, 250, 137) GUICtrlSetOnEvent(-1, "get_value") GUISetState(@SW_SHOW) func get_value() ; this is what I would LIKE to have ; $returnvalue = pop_get_a_number() endfunc ; ================================ ; in my UDF ; func pop_get_a_number() $form_pop = GUICreate("Popup", 500,500) $popforminput = guictrlcreateInput(...) ; can I just use ; return (guictrlread($popforminput)) endfunc Some code to manage closing, on-top, etc left out here, that part is manageble. Question is if I can just use return(value) from a child form like this ? I did read Wiki on multiple guis, but did not find example about returning values. I am just a hobby programmer, and nothing great to publish right now. Link to comment Share on other sites More sharing options...
FireFox Posted March 8, 2014 Share Posted March 8, 2014 I would inspire myself as much as I can of AOO like >this. expandcollapse popup#include <GUIConstantsEx.au3> #Region Pop Global Enum $__pop_Form, $__pop_Input Func Pop() Local $aPop[2] Return $aPop EndFunc ;==>Pop Func Pop_FormCreate(ByRef $aPop) $aPop[$__pop_Form] = GUICreate("Popup", 500, 500) $aPop[$__pop_Input] = GUICtrlCreateInput("", 10, 10, 500, 500) EndFunc ;==>Pop_FormCreate Func Pop_getForm($aPop) Return $aPop[$__pop_Form] EndFunc ;==>Pop_getForm Func Pop_FormShow($aPop) GUISetState(@SW_SHOW, $aPop[$__pop_Form]) EndFunc Func Pop_FormClose(ByRef $aPop) GUIDelete($aPop[$__pop_Form]) $aPop[$__pop_Form] = 0 $aPop[$__pop_Input] = 0 EndFunc ;==>Pop_FormClose Func Pop_getNumber($aPop) Return GUICtrlRead($aPop[$__pop_Input]) EndFunc ;==>Pop_getNumber #EndRegion Pop Local $aPop1 = Pop() #Region GUI Local $hGUI = GUICreate("MyGUI") Local $iBtn1 = GUICtrlCreateButton("FormCreate", 10, 10, 80, 22) Local $iBtn2 = GUICtrlCreateButton("getNumber", 10, 50, 80, 22) GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iBtn1 Pop_FormCreate($aPop1) Pop_FormShow($aPop1) Case $iBtn2 MsgBox(0, "", "getNumber: " & Pop_getNumber($aPop1)) EndSwitch WEnd If Pop_getForm($aPop1) > 0 Then Pop_FormClose($aPop1) GUIDelete($hGUI) #EndRegion GUI Link to comment Share on other sites More sharing options...
Myicq Posted March 8, 2014 Author Share Posted March 8, 2014 (edited) Firefox - thanks for this code and the link. Although it was not quite what I had in mind, since I don't want to allow parent window active during input. Hope the attached image makes sense. Click input button, child window opens, and user can input. If a value is entered it's stored in an input field. Or (preferably) stored in a variable on call from parent form. What I do now: func opensubform( $editfield, $promptHeadLine = "", $promptText = "" ) ;msgbox(0, "handle", GUICtrlGetHandle($editfield)) global $popdestfield = $editfield ; used in other function to close and store value ; ; gui def here endfunc ; stores value from child form Func btnEnterValueClick() GUICtrlSetData($popdestfield, GUICtrlRead($SubFormInput) ) GUISetState(@SW_SHOW, $Form1) GUISetState(@SW_ENABLE, $Form1) GUISetState(@SW_HIDE, $Form2) EndFunc Edited March 8, 2014 by Myicq I am just a hobby programmer, and nothing great to publish right now. Link to comment Share on other sites More sharing options...
FireFox Posted March 9, 2014 Share Posted March 9, 2014 (edited) Try this :expandcollapse popup#include <GUIConstantsEx.au3> #Region Pop Global Enum $__pop_Form, $__pop_Input, $__pop_Number Func Pop() Local $aPop[3] Return $aPop EndFunc ;==>Pop Func Pop_FormCreate(ByRef $aPop, $hWndParent) $aPop[$__pop_Form] = GUICreate("Popup", 500, 500, -1, -1, -1, -1, $hWndParent) $aPop[$__pop_Input] = GUICtrlCreateInput("", 10, 10, 500, 500) EndFunc ;==>Pop_FormCreate Func Pop_getForm($aPop) Return $aPop[$__pop_Form] EndFunc ;==>Pop_getForm Func Pop_DisposeForm(ByRef $aPop) GUIDelete($aPop[$__pop_Form]) $aPop[$__pop_Form] = 0 $aPop[$__pop_Input] = 0 EndFunc ;==>Pop_FormClose Func Pop_getNumber($aPop) Return $aPop[$__pop_Number] EndFunc ;==>Pop_getNumber Func Pop_setNumber(ByRef $aPop) $aPop[$__pop_Number] = GUICtrlRead($aPop[$__pop_Input]) EndFunc #EndRegion Pop Local $aPop1 = Pop() #Region GUI Local $hGUI = GUICreate("MyGUI") Local $iBtn1 = GUICtrlCreateButton("FormCreate", 10, 10, 80, 22) Local $iBtn2 = GUICtrlCreateButton("getNumber", 10, 50, 80, 22) GUISetState(@SW_SHOW, $hGUI) Local $aMsg = 0 While 1 $aMsg = GUIGetMsg(1) Switch $aMsg[1] Case $hGUI Switch $aMsg[0] Case $GUI_EVENT_CLOSE ExitLoop Case $iBtn1 Pop_FormCreate($aPop1, $hGUI) GUISetState(@SW_SHOW, Pop_getForm($aPop1)) GUISetState(@SW_DISABLE, $hGUI) Case $iBtn2 MsgBox(0, "", "getNumber: " & Pop_getNumber($aPop1)) EndSwitch Case Pop_getForm($aPop1) Switch $aMsg[0] Case $GUI_EVENT_CLOSE Pop_setNumber($aPop1) GUISetState(@SW_ENABLE, $hGUI) Pop_DisposeForm($aPop1) EndSwitch EndSwitch WEnd If Pop_getForm($aPop1) > 0 Then Pop_DisposeForm($aPop1) $aPop1 = 0 GUIDelete($hGUI) #EndRegion GUIBr, FireFox. Edited March 9, 2014 by FireFox Link to comment Share on other sites More sharing options...
guinness Posted March 9, 2014 Share Posted March 9, 2014 Nice FireFox. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
FireFox Posted March 9, 2014 Share Posted March 9, 2014 Thanks guinness Link to comment Share on other sites More sharing options...
guinness Posted March 9, 2014 Share Posted March 9, 2014 Does AOO mean API Object Orientated? I have to say since moving to C#, OO has been a lot easier to grasp than I would've expected. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
FireFox Posted March 9, 2014 Share Posted March 9, 2014 (edited) Object Oriented Analysis (OOA or AOO). I have to say since moving to C#, OO has been a lot easier to grasp than I would've expected.Yes, but there is a few things more complex like how to access elements from other threads the right way.In fact, all the things that other languages brings that AutoIt don't Edited March 9, 2014 by FireFox Link to comment Share on other sites More sharing options...
FireFox Posted March 12, 2014 Share Posted March 12, 2014 I dreamed of using DllStruct last night (who knows why) for this example. No global vars, no ByRef and direct cast. expandcollapse popup#include <GUIConstantsEx.au3> #Region Pop Func Pop() Local $tPOP = DllStructCreate("hwnd Form; uint Input; int Number") Return $tPOP EndFunc ;==>Pop Func Pop_FormCreate($tPOP, $hWndParent) DllStructSetData($tPOP, "Form", GUICreate("Popup", 500, 500, -1, -1, -1, -1, $hWndParent)) DllStructSetData($tPOP, "Input", GUICtrlCreateInput("", 10, 10, 500, 500)) EndFunc ;==>Pop_FormCreate Func Pop_getForm($tPOP) Return DllStructGetData($tPOP, "Form") EndFunc ;==>Pop_getForm Func Pop_DisposeForm($tPOP) GUIDelete(DllStructGetData($tPOP, "Form")) DllStructSetData($tPOP, "Form", 0) DllStructSetData($tPOP, "Input", 0) EndFunc ;==>Pop_FormClose Func Pop_getNumber($tPOP) Return DllStructGetData($tPOP, "Number") EndFunc ;==>Pop_getNumber Func Pop_setNumber($tPOP) DllStructSetData($tPOP, "Number", Number(GUICtrlRead(DllStructGetData($tPOP, "Input")))) EndFunc #EndRegion Pop Local $tPop1 = Pop() #Region GUI Local $hGUI = GUICreate("MyGUI") Local $iBtn1 = GUICtrlCreateButton("FormCreate", 10, 10, 80, 22) Local $iBtn2 = GUICtrlCreateButton("getNumber", 10, 50, 80, 22) GUISetState(@SW_SHOW, $hGUI) Local $aMsg = 0 While 1 $aMsg = GUIGetMsg(1) Switch $aMsg[1] Case $hGUI Switch $aMsg[0] Case $GUI_EVENT_CLOSE ExitLoop Case $iBtn1 Pop_FormCreate($tPop1, $hGUI) GUISetState(@SW_SHOW, Pop_getForm($tPop1)) GUISetState(@SW_DISABLE, $hGUI) Case $iBtn2 MsgBox(0, "", "getNumber: " & Pop_getNumber($tPop1)) EndSwitch Case Pop_getForm($tPop1) Switch $aMsg[0] Case $GUI_EVENT_CLOSE Pop_setNumber($tPop1) GUISetState(@SW_ENABLE, $hGUI) Pop_DisposeForm($tPop1) EndSwitch EndSwitch WEnd If Pop_getForm($tPop1) > 0 Then Pop_DisposeForm($tPop1) $tPop1 = 0 GUIDelete($hGUI) #EndRegion GUI Link to comment Share on other sites More sharing options...
guinness Posted March 12, 2014 Share Posted March 12, 2014 I guess you know this is incorrect usage intended for DllStruct functions? UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
FireFox Posted March 12, 2014 Share Posted March 12, 2014 (edited) huh yeah but why not PS : Dreams do not reflect reality Edited March 12, 2014 by FireFox 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