Linda Posted April 29, 2009 Share Posted April 29, 2009 (edited) Hi all, I am trying to understand how AutoIT really works. Is it possible to make part of the main GUI as multiple au3 files, like one for the toolbar,one for the statusbar,treeview etc instead of doing one single script with 10000 lines of code with 53624 cases for msgbox/GUI selections. I guess yes,but then can anyone point me to a tutorial or a topic in the forum on how to do that. Let say i build my main GUI window at mainwindow.au3 So then i would import all my UDF like #include "myToolBar.au3" and within this script _createMyToolBar() GuiSetState() where createMyToolBar() is a function in myToolBar.au3 which starts with the include-once import. But how do i make the GUICtrlCreateToolbar inside this script to points to THIS window(main) in the arguments and not a new parent GUI. I dont get it. thanks! Edited April 29, 2009 by Linda Link to comment Share on other sites More sharing options...
GEOSoft Posted April 30, 2009 Share Posted April 30, 2009 It will work just the way you have it. You just have to make sure that the GUI's and any controls on them are created globally so that you can reference them later. I often use the multi-script method for child GUIs. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
BrettF Posted April 30, 2009 Share Posted April 30, 2009 I'd be intrested to see the reasoning behind 53624 cases for inputs... Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
GEOSoft Posted April 30, 2009 Share Posted April 30, 2009 (edited) Here is a quick example where the GUIs are created in the primary script but the controls (declared Globally) are in another file. This script has a total of 795 controls so I'm only showing a part of it. #include "include/_ctrls.au3" $Frm_Main = GuiCreate ($Ttl & ' ' & $Ver, $Gw, $Gh + 130) GuiSetBkColor ($White) $mHwd = WinGetHandle($Frm_Main) If FileExists($Hlp) Then GUISetHelp ('hh.exe ' & $Hlp) #include "include\_Ctrls.au3" Create_Menu();; This adds 154 controls for the menu GUISetState ();;; ************** Must be at the end of the main form ;; ;; I have a few more windows and controls being created in here ;; ;; Now we create another window that contains 6 tabs and too many controls to figure out. $tW = _GUI_ChildSize($Frm_Main)+2 $ty = _GUI_ChildSize($Frm_Search, 1,_GUI_ChildSize($Frm_Top , 1)) $tH = _GUI_ChildSize($Frm_Main, 1) - ($ty + _GUI_ChildSize($Frm_Btns , 1)) $Frm_Tabs = GuiCreate ("Tabs Window", $tw, $th+3, 0, $ty, $WS_CHILD, -1, $Frm_Main) GUISetBkColor($Bk_Grnd_Clr) Global $Tab_1 = GuiCtrlCreateTab (0, 0, $tw, $tH+3, 0x0010 + 0x0200) For $I = 0 To 6 Create_Tabs($I);; This function knows what controls to create on which tabs according to $i Next $End = GUICtrlCreateDummy ();; The dummy is a control used as a marker, NOT the author GUISetState() Edited April 30, 2009 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Linda Posted April 30, 2009 Author Share Posted April 30, 2009 (edited) Hi George, Kind of you to replay and include a code sample (good comments in it =))..and it make sense to me. However, i still have problem understanding how i can apply a toolbar from the helpfiles to my mainwindow. Lets say i have built a script like this that i want to be my main window (a GUI with a statusbar with some mysql records): expandcollapse popup#include <array.au3> #include "mysql.au3" #include "mytoolbar.au3" #include <GuiConstantsEx.au3> #include <GuiStatusBar.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <guiconstants.au3> #include <constants.au3> ;Opt('MustDeclareVars', 1) ;$Debug_SB = False; Check ClassName being passed to functions, set to True and use a handle to another control to see it work _MySQL_InitLibrary() If @error Then Exit MsgBox(0, '', "") MsgBox(0, "DLL Version:",_MySQL_Get_Client_Version()&@CRLF& _MySQL_Get_Client_Info()) $MysqlConn = _MySQL_Init() $connected = _MySQL_Real_Connect($MysqlConn, "localhost", "root", "", "exampledb") If $connected = 0 Then Exit MsgBox(16, 'Connection Error', _MySQL_Error($MysqlConn)) $query = "SELECT * FROM lag1" _MySQL_Real_Query($MysqlConn, $query) ;------------------------------------------------------ ;------------------------------------------------------ $res = _MySQL_Store_Result($MysqlConn) $fields = _MySQL_Num_Fields($res) $rows = _MySQL_Num_Rows($res) $array = _MySQL_Fetch_Result_StringArray($res) Opt('MustDeclareVars', 1) $Debug_SB = False; Check ClassName being passed to functions, set to True and use a handle to another control to see it work Global $iMemo Local $hGUI, $hIcons[2], $hStatus Local $aParts[4] = [75, 150, 300, 400] ; Create GUI $hGUI = GUICreate("MainWindow", 400, 300) $hStatus = _GUICtrlStatusBar_Create ($hGUI) ; Create memo control $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 274, $WS_VSCROLL) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState() ; Set parts _GUICtrlStatusBar_SetParts ($hStatus, $aParts) _GUICtrlStatusBar_SetText ($hStatus, $array[2][0]) _GUICtrlStatusBar_SetText ($hStatus, "Part 2", 1) ; Set icons $hIcons[0] = _WinAPI_LoadShell32Icon (23) $hIcons[1] = _WinAPI_LoadShell32Icon (40) _GUICtrlStatusBar_SetIcon ($hStatus, 0, $hIcons[0]) _GUICtrlStatusBar_SetIcon ($hStatus, 1, $hIcons[1]) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ; Free icons _WinAPI_DestroyIcon ($hIcons[0]) _WinAPI_DestroyIcon ($hIcons[1]) GUIDelete() ;MsgBox(0, '', "this is the result:" & $array[2][0]) ;_ArrayDisplay($array) ;MsgBox(0, "", $rows & "-" & $fields) ;MsgBox(0, '', "Found " & $users & " user(s) with this yam and PW") ;~; Abfrage freigeben _MySQL_Free_Result($res) ;~; Verbindung beenden _MySQL_Close($MysqlConn) ;~; MYSQL beenden _MySQL_EndLibrary() Now, in the helpfiles there is a script i named mytoolbar. I would like to add this toolbar object to my mainwindow. expandcollapse popup#include-once #include <GuiToolbar.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> Opt('MustDeclareVars', 1) $Debug_TB = False; Check ClassName being passed to functions, set to True and use a handle to another control to see it work Global $hToolbar, $iMemo Global $iItem; Command identifier of the button associated with the notification. Global Enum $idNew = 1000, $idOpen, $idSave, $idHelp _Main() Func _Main() Global $hGUI, $aSize ; Create GUI $hGUI = GUICreate("Toolbar", 600, 400) $hToolbar = _GUICtrlToolbar_Create ($hGUI) $aSize = _GUICtrlToolbar_GetMaxSize ($hToolbar) $iMemo = GUICtrlCreateEdit("", 2, $aSize[1] + 20, 596, 396 - ($aSize[1] + 20), $WS_VSCROLL) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState() GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; Add standard system bitmaps _GUICtrlToolbar_AddBitmap ($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR) ; Add buttons _GUICtrlToolbar_AddButton ($hToolbar, $idNew, $STD_FILENEW) _GUICtrlToolbar_AddButton ($hToolbar, $idOpen, $STD_FILEOPEN) _GUICtrlToolbar_AddButton ($hToolbar, $idSave, $STD_FILESAVE) _GUICtrlToolbar_AddButtonSep ($hToolbar) _GUICtrlToolbar_AddButton ($hToolbar, $idHelp, $STD_HELP) ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>_Main ; Write message to memo Func MemoWrite($sMessage = "") GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite ; WM_NOTIFY event handler Func _WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $tNMHDR, $event, $hwndFrom, $code, $i_idNew, $dwFlags, $lResult, $idFrom, $i_idOld Local $tNMTOOLBAR, $tNMTBHOTITEM $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hwndFrom = DllStructGetData($tNMHDR, "hWndFrom") $idFrom = DllStructGetData($tNMHDR, "IDFrom") $code = DllStructGetData($tNMHDR, "Code") Switch $hwndFrom Case $hToolbar Switch $code Case $NM_LDOWN ;---------------------------------------------------------------------------------------------- MemoWrite("$NM_LDOWN: Clicked Item: " & $iItem & " at index: " & _GUICtrlToolbar_CommandToIndex ($hToolbar, $iItem)) ;---------------------------------------------------------------------------------------------- Case $TBN_HOTITEMCHANGE $tNMTBHOTITEM = DllStructCreate($tagNMTBHOTITEM, $lParam) $i_idOld = DllStructGetData($tNMTBHOTITEM, "idOld") $i_idNew = DllStructGetData($tNMTBHOTITEM, "idNew") $iItem = $i_idNew $dwFlags = DllStructGetData($tNMTBHOTITEM, "dwFlags") If BitAND($dwFlags, $HICF_LEAVING) = $HICF_LEAVING Then MemoWrite("$HICF_LEAVING: " & $i_idOld) Else Switch $i_idNew Case $idNew ;---------------------------------------------------------------------------------------------- MemoWrite("$TBN_HOTITEMCHANGE: $idNew") ;---------------------------------------------------------------------------------------------- Case $idOpen ;---------------------------------------------------------------------------------------------- MemoWrite("$TBN_HOTITEMCHANGE: $idOpen") ;---------------------------------------------------------------------------------------------- Case $idSave ;---------------------------------------------------------------------------------------------- MemoWrite("$TBN_HOTITEMCHANGE: $idSave") ;---------------------------------------------------------------------------------------------- Case $idHelp ;---------------------------------------------------------------------------------------------- MemoWrite("$TBN_HOTITEMCHANGE: $idHelp") ;---------------------------------------------------------------------------------------------- EndSwitch EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY this part is what i dont understand $hGUI = GUICreate("Toolbar", 600, 400) $hToolbar = _GUICtrlToolbar_Create ($hGUI) That will create a new hGUI and the toolbar is not included into my mainwindow. BrettF Edited April 30, 2009 by Linda Link to comment Share on other sites More sharing options...
GEOSoft Posted April 30, 2009 Share Posted April 30, 2009 Unless you need a separate Window for the Toolbar that you can Show/Hide as reguired then you don't meed the second GUI at all. Just eliminate the second GUI and create the Toolbar in the first one. If You want it as a separate window then you will have to rename the second $hGUI ($hGUI2 would be fine) and create it as a child of the first as I showed in my example. If you still don't understand then I'm sure one of us will work something out based on your code. It 04:20 here and I'm not about to sit and write a GUI this instant. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Linda Posted April 30, 2009 Author Share Posted April 30, 2009 (edited) George,I got it now and it works great.I will go for using one GUI in one script and then just like you did create "external" controls in other scripts.Thanks for taking your time to write it down, even if it is 04:20 Have a nice day!....and never stop visiting this forum /LindaUnless you need a separate Window for the Toolbar that you can Show/Hide as reguired then you don't meed the second GUI at all. Just eliminate the second GUI and create the Toolbar in the first one. If You want it as a separate window then you will have to rename the second $hGUI ($hGUI2 would be fine) and create it as a child of the first as I showed in my example.If you still don't understand then I'm sure one of us will work something out based on your code. It 04:20 here and I'm not about to sit and write a GUI this instant. Edited April 30, 2009 by Linda Link to comment Share on other sites More sharing options...
GEOSoft Posted April 30, 2009 Share Posted April 30, 2009 Glad to hear it. Didn't much feel like doing GUI stuff right now anyway. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" 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