Joboy2k Posted December 16, 2009 Share Posted December 16, 2009 Hey All this is my first go at using gui's and iv ran into a few problems. expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> ;Opt("TrayIconHide", 1) $make = "" $model = "" $widthCell = 100 func Start() GUISetState(@SW_HIDE) GUICreate("Camera Logger", 265, 100, 310, 190,BitOR($WS_POPUP, $WS_SIZEBOX),$BS_PUSHLIKE) GUISetBkColor(0xc0c0c0) $Choice1 = GUICtrlCreateButton("Search", 100, 40, 60) $Choice2 = GUICtrlCreateButton("Log", 25, 40, 60) $exit = GUICtrlCreateButton("Exit", 175, 40, 60) GUISetState(@SW_SHOW) while 1 $msg = GUIGetMsg() If $msg = $exit Then Exit Elseif $msg = $choice2 Then GUISetState(@SW_HIDE) GUICreate("Camera Logger", 265, 175, 310, 190,BitOR($WS_POPUP, $WS_SIZEBOX),$BS_PUSHLIKE) GUISetBkColor(0xc0c0c0) $CMake = GUICtrlCreateInput("Make", 25, 10, 217, 21) $Cmodel = GUICtrlCreateInput("Model", 25, 40, 217, 21) $opt1 = GUICtrlCreateCheckbox("Sold", 25, 70) $opt2 = GUICtrlCreateCheckbox("Bought / Gained", 25, 100) $exit = GUICtrlCreateButton("Back", 140, 145, 60) $Option = GUICtrlCreateButton("Start", 65, 145, 60) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() $currentnumber = iniread("camera.ini",GUICtrlRead($cmake)&";"&GUICtrlRead($cmodel),0,0) If $msg = $exit Then start() Elseif $msg = $Option Then If GUICtrlRead($opt1) = 1 Then if GUICtrlRead($opt2) = 1 Then msgbox(0, "Error", "Sold And Bought Both Selected Please Remove 1 Option") else if GUICtrlRead($cmake) = "make" Then GUISetState(@SW_HIDE) GUICreate("Camera Logger", 265, 175, 310, 190,BitOR($WS_POPUP, $WS_SIZEBOX),$BS_PUSHLIKE) GUISetBkColor(0xc0c0c0) $CMake = GUICtrlCreateInput("Make", 25, 10, 217, 21) GUICtrlSetColor(-1, 0xFF0000) $Cmodel = GUICtrlCreateInput(GUICtrlRead($cmodel), 25, 40, 217, 21) $opt1 = GUICtrlCreateCheckbox("Sold", 25, 70) $opt2 = GUICtrlCreateCheckbox("Bought / Gained", 25, 100) $exit = GUICtrlCreateButton("Back", 140, 145, 60) $Option = GUICtrlCreateButton("Start", 65, 145, 60) GUISetState(@SW_SHOW) Else if stringlen(GUICtrlRead($cmake)) < 2 Then GUISetState(@SW_HIDE) GUICreate("Camera Logger", 265, 175, 310, 190,BitOR($WS_POPUP, $WS_SIZEBOX),$BS_PUSHLIKE) GUISetBkColor(0xc0c0c0) $CMake = GUICtrlCreateInput("Make", 25, 10, 217, 21) GUICtrlSetColor(-1, 0xFF0000) $Cmodel = GUICtrlCreateInput(GUICtrlRead($cmodel), 25, 40, 217, 21) $opt1 = GUICtrlCreateCheckbox("Sold", 25, 70) $opt2 = GUICtrlCreateCheckbox("Bought / Gained", 25, 100) $exit = GUICtrlCreateButton("Back", 140, 145, 60) $Option = GUICtrlCreateButton("Start", 65, 145, 60) GUISetState(@SW_SHOW) Else if GUICtrlRead($cmodel) = "Model" Then GUISetState(@SW_HIDE) GUICreate("Camera Logger", 265, 175, 310, 190,BitOR($WS_POPUP, $WS_SIZEBOX),$BS_PUSHLIKE) GUISetBkColor(0xc0c0c0) $CMake = GUICtrlCreateInput(GUICtrlRead($cmake), 25, 10, 217, 21) $Cmodel = GUICtrlCreateInput("Model", 25, 40, 217, 21) GUICtrlSetColor(-1, 0xFF0000) $opt1 = GUICtrlCreateCheckbox("Sold", 25, 70) $opt2 = GUICtrlCreateCheckbox("Bought / Gained", 25, 100) $exit = GUICtrlCreateButton("Back", 140, 145, 60) $Option = GUICtrlCreateButton("Start", 65, 145, 60) GUISetState(@SW_SHOW) Else if stringlen(GUICtrlRead($cmodel)) < 2 Then GUISetState(@SW_HIDE) GUICreate("Camera Logger", 265, 175, 310, 190,BitOR($WS_POPUP, $WS_SIZEBOX),$BS_PUSHLIKE) GUISetBkColor(0xc0c0c0) $CMake = GUICtrlCreateInput(GUICtrlRead($cmake), 25, 10, 217, 21) $Cmodel = GUICtrlCreateInput("Model", 25, 40, 217, 21) GUICtrlSetColor(-1, 0xFF0000) $opt1 = GUICtrlCreateCheckbox("Sold", 25, 70) $opt2 = GUICtrlCreateCheckbox("Bought / Gained", 25, 100) $exit = GUICtrlCreateButton("Back", 140, 145, 60) $Option = GUICtrlCreateButton("Start", 65, 145, 60) GUISetState(@SW_SHOW) Else GUISetState(@SW_HIDE) iniwrite("camera.ini",GUICtrlRead($cmake)&";"&GUICtrlRead($cmodel),0,$currentnumber - 1) $currentnumber = iniread("camera.ini",GUICtrlRead($cmake)&";"&GUICtrlRead($cmodel),0,0) if $currentnumber < 0 Then iniwrite("camera.ini",GUICtrlRead($cmake)&";"&GUICtrlRead($cmodel),0,0) EndIf $currentnumber = iniread("camera.ini",GUICtrlRead($cmake)&";"&GUICtrlRead($cmodel),0,0) sleep(200) GUICreate("Camera Logger", 265, 175, 310, 190,BitOR($WS_POPUP, $WS_SIZEBOX),$BS_PUSHLIKE) GUISetBkColor(0xc0c0c0) GUICtrlCreateLabel("Sold", 25, 40, $widthCell) GUICtrlCreateLabel("Make: "& GUICtrlRead($cmake), 25, 70, $widthCell) GUICtrlCreateLabel("Model: "& GUICtrlRead($cmodel), 25, 100, $widthCell,$SS_CENTERIMAGE) GUICtrlCreateLabel("Instock: "& $currentnumber, 25, 130, $widthCell,$SS_CENTERIMAGE) GUISetState(@SW_show) SLEEP(1500) start() EndIf EndIf EndIf EndIf endif EndIf If GUICtrlRead($opt2) = 1 Then If GUICtrlRead($opt1) = 1 Then Else if GUICtrlRead($cmake) = "make" Then GUISetState(@SW_HIDE) GUICreate("Camera Logger", 265, 175, 310, 190,BitOR($WS_POPUP, $WS_SIZEBOX),$BS_PUSHLIKE) GUISetBkColor(0xc0c0c0) $CMake = GUICtrlCreateInput("Make", 25, 10, 217, 21) GUICtrlSetColor(-1, 0xFF0000) $Cmodel = GUICtrlCreateInput(GUICtrlRead($cmodel), 25, 40, 217, 21) $opt1 = GUICtrlCreateCheckbox("Sold", 25, 70) $opt2 = GUICtrlCreateCheckbox("Bought / Gained", 25, 100) $exit = GUICtrlCreateButton("Back", 140, 145, 60) $Option = GUICtrlCreateButton("Start", 65, 145, 60) GUISetState(@SW_SHOW) Else if stringlen(GUICtrlRead($cmake)) < 2 Then GUISetState(@SW_HIDE) GUICreate("Camera Logger", 265, 175, 310, 190,BitOR($WS_POPUP, $WS_SIZEBOX),$BS_PUSHLIKE) GUISetBkColor(0xc0c0c0) $CMake = GUICtrlCreateInput("Make", 25, 10, 217, 21) GUICtrlSetColor(-1, 0xFF0000) $Cmodel = GUICtrlCreateInput(GUICtrlRead($cmodel), 25, 40, 217, 21) $opt1 = GUICtrlCreateCheckbox("Sold", 25, 70) $opt2 = GUICtrlCreateCheckbox("Bought / Gained", 25, 100) $exit = GUICtrlCreateButton("Back", 140, 145, 60) $Option = GUICtrlCreateButton("Start", 65, 145, 60) GUISetState(@SW_SHOW) Else if GUICtrlRead($cmodel) = "Model" Then GUISetState(@SW_HIDE) GUICreate("Camera Logger", 265, 175, 310, 190,BitOR($WS_POPUP, $WS_SIZEBOX),$BS_PUSHLIKE) GUISetBkColor(0xc0c0c0) $CMake = GUICtrlCreateInput(GUICtrlRead($cmake), 25, 10, 217, 21) $Cmodel = GUICtrlCreateInput("Model", 25, 40, 217, 21) GUICtrlSetColor(-1, 0xFF0000) $opt1 = GUICtrlCreateCheckbox("Sold", 25, 70) $opt2 = GUICtrlCreateCheckbox("Bought / Gained", 25, 100) $exit = GUICtrlCreateButton("Back", 140, 145, 60) $Option = GUICtrlCreateButton("Start", 65, 145, 60) GUISetState(@SW_SHOW) Else if stringlen(GUICtrlRead($cmodel)) < 2 Then GUISetState(@SW_HIDE) GUICreate("Camera Logger", 265, 175, 310, 190,BitOR($WS_POPUP, $WS_SIZEBOX),$BS_PUSHLIKE) GUISetBkColor(0xc0c0c0) $CMake = GUICtrlCreateInput(GUICtrlRead($cmake), 25, 10, 217, 21) $Cmodel = GUICtrlCreateInput("Model", 25, 40, 217, 21) GUICtrlSetColor(-1, 0xFF0000) $opt1 = GUICtrlCreateCheckbox("Sold", 25, 70) $opt2 = GUICtrlCreateCheckbox("Bought / Gained", 25, 100) $exit = GUICtrlCreateButton("Back", 140, 145, 60) $Option = GUICtrlCreateButton("Start", 65, 145, 60) GUISetState(@SW_SHOW) Else GUISetState(@SW_HIDE) iniwrite("camera.ini",GUICtrlRead($cmake)&";"&GUICtrlRead($cmodel),0,$currentnumber + 1) $currentnumber = iniread("camera.ini",GUICtrlRead($cmake)&";"&GUICtrlRead($cmodel),0,0) sleep(200) GUICreate("Camera Logger", 265, 175, 310, 190,BitOR($WS_POPUP, $WS_SIZEBOX),$BS_PUSHLIKE) GUISetBkColor(0xc0c0c0) GUICtrlCreateLabel("Bought / Gained", 25, 40, $widthCell) GUICtrlCreateLabel("Make: "& GUICtrlRead($cmake), 25, 70, $widthCell) GUICtrlCreateLabel("Model: "& GUICtrlRead($cmodel), 25, 100, $widthCell,$SS_CENTERIMAGE) GUICtrlCreateLabel("Instock: "& $currentnumber, 25, 130, $widthCell,$SS_CENTERIMAGE) GUISetState(@SW_show) ProcessWaitClose("2") sleep(1500) start() EndIf EndIf EndIf EndIf EndIf EndIf EndIf WEnd ElseIf $msg = $choice1 Then GUISetState(@SW_HIDE) GUICreate("Camera Search", 265, 100, 310, 190,BitOR($WS_POPUP, $WS_SIZEBOX)) GUISetBkColor(0xc0c0c0) $CMake = GUICtrlCreateInput("Make / Model", 25, 25, 217, 21) ;$Cmodel = GUICtrlCreateInput("Model", 25, 40, 217, 21) $exit = GUICtrlCreateButton("Back", 140, 70, 60) $search = GUICtrlCreateButton("Search", 65, 70, 60) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() If $msg = $exit Then start() Elseif $msg = $search Then If GUICtrlRead($cmake) = "Make / Model" Then Else $var = inireadsectionnames("camera.ini") If @error Then MsgBox(4096, "", "Error occurred, probably none on record.") Else For $i = 1 To $var[0] if stringinstr($var[$i],GUICtrlRead($cmake)) Then $array = stringsplit($var[$i],";") $make = $array[1] $model = $array[2] $instock = iniread("camera.ini",$make&";"&$model,0,0) msgBox(4096, "", "Camera: " & $make & @CRLF & "Model "& $model & @CRLF & "Instock: " &$instock) Else EndIf Next endif EndIf EndIf WEnd EndIf WEnd endfunc while 1 start() WEnd this is what iv done so far. its a program to logg cameras in and out.(friend owns a camera shop) but the problems im hitting is. 1) you cant move the gui it just starts resizing. i know its because of this line "GUICreate("Camera Search", 265, 100, 310, 190,BitOR($WS_POPUP, $WS_SIZEBOX))" but i need it so you dont get the title bar up 2) i cant figure out when i search for a camera name how to get it to all come up in a gui. i had to result in it just using msg boxes which ruins it. 3) i tried to make adrop down box so that when loggin in a camera, if i type "n" it would bring up a drop down box with the name "nikon" or any other names that start with. i understand i may be doing everything in a stupidly long way but im still learning. it'll be much appreciated if you could help me along. thank you Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 16, 2009 Moderators Share Posted December 16, 2009 joboy2k,That made my head hurt! I do not understand why you were continually creating new GUIs - it is much easier to work with just one! I have seriously reworked your script, although I have tried to retain the same flow. I have added lots of comments, so I hope you can follow:expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <SendMessage.au3> #include <GUIComboBox.au3> #include <ComboConstants.au3> ; We need this to move a pop-up GUI Global Const $SC_DRAGMOVE = 0xF012 ; Set no resizing for controls Opt("GUIResizeMode", $GUI_DOCKALL) ; Set your ini file path once - it is easier to maintain Global $sIniFile = @ScriptDir & "\camera.ini" Start() Func Start() ; create a GUI $hGUI_Main = GUICreate("Camera Logger", 265, 100, 310, 190, $WS_POPUP) GUISetBkColor(0xc0c0c0) $hSearch_Button = GUICtrlCreateButton("Search", 100, 40, 60) $hLog_Button = GUICtrlCreateButton("Log", 25, 40, 60) $hExit_Button = GUICtrlCreateButton("Exit", 175, 40, 60) GUISetState(@SW_SHOW) While 1 ; this is the best way to look for events Switch GUIGetMsg() ; the mouse has been pressed - if we are on our GUI - move it Case $GUI_EVENT_PRIMARYDOWN _SendMessage($hGUI_Main, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) ; The exit button has been pressed so exit Case $hExit_Button Exit ; The log button has been pressed Case $hLog_Button ; Let us resize the GUI to show the new controls WinMove($hGUI_Main, "", Default, Default, 265, 290) $CMake = GUICtrlCreateInput("Make", 25, 110, 217, 21) $Cmodel = GUICtrlCreateInput("Model", 25, 140, 217, 21) $hSold_Check = GUICtrlCreateCheckbox("Sold", 25, 170) $hBought_Check = GUICtrlCreateCheckbox("Bought / Gained", 25, 200) $hBack_Button = GUICtrlCreateButton("Back", 140, 245, 60) $hStart_Button = GUICtrlCreateButton("Start", 65, 245, 60) ; See what controls are pressed here While 1 Switch GUIGetMsg() ; back button pressed Case $hBack_Button ; delete additional controls For $i = $CMake To $hStart_Button GUICtrlDelete($i) Next ; Put GUI back to original size WinMove($hGUI_Main, "", Default, Default, 265, 100) ; return to main loop ExitLoop ; Start button pressed Case $hStart_Button ; Run checks on the inputs and checkboxes ; Check we are not "Sold" and "Bought" If GUICtrlRead($hSold_Check) = 1 And GUICtrlRead($hBought_Check) = 1 Then MsgBox(0, "Error", "Sold And Bought Both Selected Please Remove 1 Option") ; Check we have at least one! ElseIf GUICtrlRead($hSold_Check) = 4 And GUICtrlRead($hBought_Check) = 4 Then MsgBox(0, "Error", "Please Select Either Sold Or Bought Option") ; Check Make Input ElseIf GUICtrlRead($CMake) = "Make" Or StringLen(GUICtrlRead($CMake)) < 2 Then MsgBox(0, "Error", "Pleas Enter Camera Make") ; Check Model Input ElseIf GUICtrlRead($Cmodel) = "Model" Or StringLen(GUICtrlRead($Cmodel)) < 2 Then MsgBox(0, "Error", "Pleas Enter Camera Model") ; We are good to go Else ; read current stock number $currentnumber = IniRead($sIniFile, GUICtrlRead($CMake), GUICtrlRead($Cmodel), 0) ; Is "Sold" checked? If GUICtrlRead($hSold_Check) = 1 Then If $currentnumber = 0 Then ; if current stock is zero we have a problem! MsgBox(0, "Error", "You Have Just Sold A Non-Existent Camera!") Else ; write new stock number IniWrite($sIniFile, GUICtrlRead($CMake), GUICtrlRead($Cmodel), $currentnumber - 1) MsgBox(0, "Completed", "You Have Just Sold A " & GUICtrlRead($CMake) & " " & GUICtrlRead($Cmodel) & " Camera!") EndIf ; This has to be Bought because we have checked all the other possibilities Else ; write new stock number IniWrite($sIniFile, GUICtrlRead($CMake), GUICtrlRead($Cmodel), $currentnumber + 1) MsgBox(0, "Completed", "You Have Just Added A " & GUICtrlRead($CMake) & " " & GUICtrlRead($Cmodel) & " Camera!") EndIf ; delete additional controls For $i = $CMake To $hStart_Button GUICtrlDelete($i) Next ; Put GUI back to original size WinMove($hGUI_Main, "", Default, Default, 265, 100) ExitLoop EndIf EndSwitch WEnd ; the search button was pressed Case $hSearch_Button ; Let us resize the GUI to show the new controls WinMove($hGUI_Main, "", Default, Default, 265, 250) $CMake = GUICtrlCreateCombo("", 25, 125, 217, 21, $CBS_DROPDOWNLIST) $hStart_Button = GUICtrlCreateButton("Start", 65, 170, 60) $hBack_Button = GUICtrlCreateButton("Back", 140, 170, 60) $hCombo = GUICtrlCreateCombo("", 25, 210, 217, 21, $CBS_DROPDOWNLIST) GUICtrlSetState(-1, $GUI_HIDE) ; get a list of the makes available $aList = IniReadSectionNames($sIniFile) If @error Then MsgBox(4096, "", "Error occurred, check the ini file.") ; We have a list Else ; get the list into the Make combo Local $sComboList = "" For $i = 1 To $aList[0] $sComboList &= $aList[$i] & "|" Next GUICtrlSetData($CMake, $sComboList) EndIf ; See what happens now While 1 Switch GUIGetMsg() Case $hBack_Button ; delete additional controls For $i = $CMake To $hExit_Button GUICtrlDelete($i) Next ; Put GUI back to original size WinMove($hGUI_Main, "", Default, Default, 265, 100) ExitLoop Case $hStart_Button ; Run check on the input ConsoleWrite(GUICtrlRead($CMake) & @CRLF) If GUICtrlRead($CMake) = "Make" Or StringLen(GUICtrlRead($CMake)) < 2 Then MsgBox(0, "Error", "Pleas Enter Camera Make") ; Good to go Else $aList = IniReadSection($sIniFile, GUICtrlRead($CMake)) If @error Then MsgBox(4096, "", "Error occurred, probably none on record.") ; We have a list Else ; get the list into a combo Local $sComboList = "" For $i = 1 To $aList[0][0] $sComboList &= $aList[$i][0] & "|" Next GUICtrlSetData($hCombo, $sComboList) GUICtrlSetState($hCombo, $GUI_SHOW) ; Wait until something is selected in the combo While GUICtrlRead($hCombo) = "" Or _GUICtrlComboBox_GetDroppedState($hCombo) = True Sleep(10) WEnd $currentnumber = IniRead($sIniFile, GUICtrlRead($CMake), GUICtrlRead($hCombo), "Error") MsgBox(0, "Stock", "There Are This Many " & GUICtrlRead($CMake) & " " & GUICtrlRead($hCombo) & " Cameras in Stock" & @CRLF & @CRLF & $currentnumber) EndIf ; delete additional controls For $i = $CMake To $hCombo GUICtrlDelete($i) Next ; Put GUI back to original size WinMove($hGUI_Main, "", Default, Default, 265, 100) ExitLoop EndIf EndSwitch WEnd EndSwitch WEnd EndFunc ;==>StartOne thing I did change was the format of your ini file. It made creating the drop down lists much simpler. This is what it looks like now:[Canon] 123=2 456=1 789=1 [Kodak] 123=1 456=1 789=1Each make has its own section and the models are listed within, together with the stock number. Sorry if this casues big problems, but the way you had them stored wasted a value in the file and made the code that much more difficult. Please ask if there is anything you do not understand. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Joboy2k Posted December 16, 2009 Author Share Posted December 16, 2009 hey that is great thank you. i did notice 1 mistake in your coding but i put it straight. if i went into search mode then pressed back then went in to log mode i would still have the combo box and stuff up. as i had never used gui's before i looked at why it was still coming up because i didnt get the same effect if i pressed back in log and went in to search. but i changed this Case $hBack_Button ; delete additional controls For $i = $CMake To $hExit_Button GUICtrlDelete($i) Next TO Case $hBack_Button ; delete additional controls For $i = $CMake To $hCombo GUICtrlDelete($i) Next thanks for all the work mate. it looks great now. 1 more question though. you changed the ini file so it goes "make" then "model" then "number" i did have it as "make;model" then "0" then "number" because so of the receptionists cant remember the make of certian cameras but remember then name like "canon 400D" but would only remember "400D" is there any was i can get it to search for the "400D" part without knowing the make of the camera. so can i get it to search for the key without it knowing the section name? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 16, 2009 Moderators Share Posted December 16, 2009 joboy2k,i changed thisGood for you - why am I doing the coding for you? I will look into the "Model" search tomorrow, if I have the time.Glad you like it so far. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 17, 2009 Moderators Share Posted December 17, 2009 (edited) joboy2k,New version. Search can be by make or model. Log can enter a new make and/or model if required.expandcollapse popup#Region ; Includes #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <SendMessage.au3> #include <GUIComboBox.au3> #include <ComboConstants.au3> #EndRegion #Region ; Initialise ; We need this to move a pop-up GUI Global Const $SC_DRAGMOVE = 0xF012 ; Declare these because they are used in multiple functions Global $hGUI_Main, $hMake_Combo, $hModel_Combo Global $hLog_Button, $hSearch_Button, $hExit_Button Global $sMakeComboList, $sMakeModelComboList, $sFullModelComboList ; Set no resizing for controls in initial GUI Opt("GUIResizeMode", $GUI_DOCKALL) ; Set ini file path once - it is easier to maintain Global $sIniFile = @ScriptDir & "\camera.ini" #EndRegion Start() #Region ; Start Func Start() ; create a GUI $hGUI_Main = GUICreate("Camera Logger", 265, 100, 310, 190, $WS_POPUP) GUISetBkColor(0xc0c0c0) $hLog_Button = GUICtrlCreateButton("Log", 25, 40, 60) $hSearch_Button = GUICtrlCreateButton("Search", 100, 40, 60) $hExit_Button = GUICtrlCreateButton("Exit", 175, 40, 60) GUISetState(@SW_SHOW) While 1 ; Look for events Switch GUIGetMsg() ; the mouse has been pressed - if we are on our GUI - move it Case $GUI_EVENT_PRIMARYDOWN _SendMessage($hGUI_Main, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) ; The exit button has been pressed so exit Case $hExit_Button Exit ; The log button has been pressed Case $hLog_Button _MainButtons($GUI_DISABLE) _Log() _MainButtons($GUI_ENABLE) ; the search button was pressed Case $hSearch_Button _MainButtons($GUI_DISABLE) _Search() _MainButtons($GUI_ENABLE) EndSwitch WEnd EndFunc ;==>Start #EndRegion #Region ;Search Func _Search() ; Resize the GUI to show the new controls WinMove($hGUI_Main, "", Default, Default, 265, 250) ; Create new controls GUIStartGroup($hGUI_Main) $hMake_Radio = GUICtrlCreateRadio("Make", 60, 110) GUICtrlSetState(-1, $GUI_CHECKED) $hModel_Radio = GUICtrlCreateRadio("Model", 145, 110) $hMake_Combo = GUICtrlCreateCombo("", 25, 140, 217, 21, BitOR($CBS_DROPDOWNLIST, $CBS_SORT)) $hModel_Combo = GUICtrlCreateCombo("", 25, 170, 217, 21, BitOR($CBS_DROPDOWNLIST, $CBS_SORT)) GUICtrlSetState(-1, $GUI_HIDE) $hBack_Button = GUICtrlCreateButton("Back", 105, 200, 60) ; See what happens now While 1 ; back button pressed Switch GUIGetMsg() Case $hBack_Button _Back($hMake_Radio, $hBack_Button) Return EndSwitch ; ifmake radio selected If BitAND(GUICtrlRead($hMake_Radio), $GUI_CHECKED) = $GUI_CHECKED Then ; get list of makes into combo _MakeList($hMake_Combo) ; Wait until a make is chosen While 1 ; Check make radio still selected If BitAND(GUICtrlRead($hMake_Radio), $GUI_CHECKED) <> $GUI_CHECKED Then ExitLoop ; Check for Back button Switch GUIGetMsg() Case $hBack_Button _Back($hMake_Radio, $hBack_Button) Return EndSwitch ; a make is chosen in the combo If GUICtrlRead($hMake_Combo) <> "" And _GUICtrlComboBox_GetDroppedState($hMake_Combo) = False Then ; get list of that make's models into the second combo which becomes visible _MakeModelList($hMake_Combo, $hModel_Combo) GUICtrlSetState($hModel_Combo, $GUI_SHOW) While 1 ; Check make radio still selected If BitAND(GUICtrlRead($hMake_Radio), $GUI_CHECKED) <> $GUI_CHECKED Then GUICtrlSetState($hModel_Combo, $GUI_HIDE) ExitLoop 2 EndIf ; Check back button Switch GUIGetMsg() Case $hBack_Button _Back($hMake_Radio, $hBack_Button) Return EndSwitch ; Wait until a model is chosen If GUICtrlRead($hModel_Combo) <> "" And _GUICtrlComboBox_GetDroppedState($hModel_Combo) = False Then ; read current stock number $currentnumber = IniRead($sIniFile, GUICtrlRead($hMake_Combo), GUICtrlRead($hModel_Combo), 0) MsgBox(0, "Stock", "There Are This Many " & GUICtrlRead($hMake_Combo) & " " & GUICtrlRead($hModel_Combo) & " Cameras in Stock" & @CRLF & @CRLF & $currentnumber) ; Return to main gui _Back($hMake_Radio, $hBack_Button) Return EndIf WEnd EndIf WEnd ; we are searching models Else ; get full model list into combo _FullModelList($hMake_Combo) ; Wait until a model is chosen While 1 ; Check model radio still selected If BitAND(GUICtrlRead($hModel_Radio), $GUI_CHECKED) <> $GUI_CHECKED Then ExitLoop ; Check for Back button Switch GUIGetMsg() Case $hBack_Button _Back($hMake_Radio, $hBack_Button) Return EndSwitch ; a model is chosen If GUICtrlRead($hMake_Combo) <> "" And _GUICtrlComboBox_GetDroppedState($hMake_Combo) = False Then ; read current stock number $aName = StringSplit(GUICtrlRead($hMake_Combo), " - ", 1) $currentnumber = IniRead($sIniFile, $aName[2], $aName[1], 0) MsgBox(0, "Stock", "There Are This Many " & $aName[2] & " " & $aName[1] & " Cameras in Stock" & @CRLF & @CRLF & $currentnumber) ; Return to main gui _Back($hMake_Radio, $hBack_Button) Return EndIf WEnd EndIf WEnd EndFunc #EndRegion #Region ; Log Func _Log() ; Resize the GUI to show the new controls WinMove($hGUI_Main, "", Default, Default, 265, 260) ; Create new controls $hMake_Combo = GUICtrlCreateCombo("", 25, 110, 217, 21, BitOR($CBS_DROPDOWNLIST, $CBS_SORT)) $hModel_Combo = GUICtrlCreateCombo("", 25, 140, 217, 21, BitOR($CBS_DROPDOWNLIST, $CBS_SORT)) GUICtrlSetState(-1, $GUI_DISABLE) GUIStartGroup($hGUI_Main) $hSold_Radio = GUICtrlCreateRadio("Sold", 40, 170) GUICtrlSetState(-1, $GUI_CHECKED) $hBought_Radio = GUICtrlCreateRadio("Bought / Gained", 125, 170) $hBack_Button = GUICtrlCreateButton("Back", 25, 215, 60) $hNew_Button = GUICtrlCreateButton("New", 100, 215, 60) $hAccept_Button = GUICtrlCreateButton("Accept", 175, 215, 60) GUICtrlSetState(-1, $GUI_DISABLE) ; get list of makes into combo _MakeList($hMake_Combo) ; See what controls are pressed here While 1 ; Check for buttons Switch GUIGetMsg() Case $hBack_Button _Back($hMake_Combo, $hAccept_Button) Return Case $hNew_Button ; Enters a new make/model into the ini file GUICtrlSetState($hNew_Button, $GUI_DISABLE) ; Replace combos with inputs so user can write GUICtrlDelete($hMake_Combo) $hMake_Combo = GUICtrlCreateInput("", 25, 110, 217, 21) GUICtrlDelete($hModel_Combo) $hModel_Combo = GUICtrlCreateInput("", 25, 140, 217, 21) While 1 Switch GUIGetMsg() ; back button pressed Case $hBack_Button _Back($hMake_Combo, $hAccept_Button) Return ; accept button pressed Case $hAccept_Button ; write new stock number IniWrite($sIniFile, GUICtrlRead($hMake_Combo), GUICtrlRead($hModel_Combo), 1) MsgBox(0, "Completed", "You Have Just Added A " & GUICtrlRead($hMake_Combo) & " " & GUICtrlRead($hModel_Combo) & " Camera!") _Back($hMake_Combo, $hAccept_Button) Return EndSwitch ; Enable Accept button once both inputs have something entered If (GUICtrlRead($hMake_Combo) <> "" And GUICtrlRead($hModel_Combo) <> "") And _ BitAND(GUICtrlGetState($hAccept_Button), $GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($hAccept_Button, $GUI_ENABLE) WEnd EndSwitch ; Enable New button when Bought is selected - Disable for Sold If GUICtrlRead($hSold_Radio) = 1 Then If BitAND(GUICtrlGetState($hNew_Button), $GUI_ENABLE) = $GUI_ENABLE Then GUICtrlSetState($hNew_Button, $GUI_DISABLE) Else If BitAND(GUICtrlGetState($hNew_Button), $GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($hNew_Button, $GUI_ENABLE) EndIf ; A make has been chosen If GUICtrlRead($hMake_Combo) <> "" And _GUICtrlComboBox_GetDroppedState($hMake_Combo) = False Then ; get a list of that make's models in to the second combo and enable it _MakeModelList($hMake_Combo, $hModel_Combo) GUICtrlSetState($hModel_Combo, $GUI_ENABLE) While 1 ; Check for Back button Switch GUIGetMsg() Case $hBack_Button _Back($hMake_Combo, $hAccept_Button) Return EndSwitch ; A model has been chosen If GUICtrlRead($hModel_Combo) <> "" And _GUICtrlComboBox_GetDroppedState($hModel_Combo) = False Then ; enable Accept button GUICtrlSetState($hAccept_Button, $GUI_ENABLE) While 1 Switch GUIGetMsg() ; back button pressed Case $hBack_Button _Back($hMake_Combo, $hAccept_Button) Return ; accept button pressed Case $hAccept_Button ; read current stock number $currentnumber = IniRead($sIniFile, GUICtrlRead($hMake_Combo), GUICtrlRead($hModel_Combo), 0) ; Is "Sold" checked? If GUICtrlRead($hSold_Radio) = 1 Then If $currentnumber = 0 Then ; if current stock is zero we have a problem! MsgBox(0, "Error", "You Have Just Sold A Non-Existent Camera!") Else ; write new stock number IniWrite($sIniFile, GUICtrlRead($hMake_Combo), GUICtrlRead($hModel_Combo), $currentnumber - 1) MsgBox(0, "Completed", "You Have Just Sold A " & GUICtrlRead($hMake_Combo) & " " & GUICtrlRead($hModel_Combo) & " Camera!") EndIf ; "Bought" is checked Else ; write new stock number IniWrite($sIniFile, GUICtrlRead($hMake_Combo), GUICtrlRead($hModel_Combo), $currentnumber + 1) MsgBox(0, "Completed", "You Have Just Added A " & GUICtrlRead($hMake_Combo) & " " & GUICtrlRead($hModel_Combo) & " Camera!") EndIf ; Clear up _Back($hMake_Combo, $hAccept_Button) Return EndSwitch WEnd EndIf WEnd EndIf WEnd EndFunc ;==>Log #EndRegion #Region ; Lists Func _MakeList($hSet_Combo) ; get a list of the makes available into the combo $aMakeList = IniReadSectionNames($sIniFile) If @error Then MsgBox(4096, "Make", "Error occurred, check the ini file.") ; We have a list Else ; get the list into the Make combo Local $sMakeComboList = "|" For $i = 1 To $aMakeList[0] $sMakeComboList &= $aMakeList[$i] & "|" Next GUICtrlSetData($hSet_Combo, $sMakeComboList) EndIf EndFunc ;==>MakeList Func _MakeModelList($hRead_Combo, $hSet_Combo) ; make selected so get list of models $aMakeModelList = IniReadSection($sIniFile, GUICtrlRead($hRead_Combo)) If @error Then MsgBox(4096, "MakeModel", "Error occurred, check the ini file.") ; we have a list Else ; get the list into the Model combo Local $sMakeModelComboList = "|" For $i = 1 To $aMakeModelList[0][0] $sMakeModelComboList &= $aMakeModelList[$i][0] & "|" Next GUICtrlSetData($hSet_Combo, $sMakeModelComboList) EndIf EndFunc ;==>MakeModelList Func _FullModelList($hSet_Combo) ; get a list of the makes available $aFullMakeList = IniReadSectionNames($sIniFile) If @error Then MsgBox(4096, "", "Error occurred, check the ini file.") ; We have a list Else Local $sFullModelComboList = "|" For $i = 1 To $aFullMakeList[0] $aPartList = IniReadSection($sIniFile, $aFullMakeList[$i]) If @error Then MsgBox(4096, "", "Error occurred, check the ini file.") ; We have a list Else For $j = 1 To $aPartList[0][0] $sFullModelComboList &= $aPartList[$j][0] & " - " & $aFullMakeList[$i] & "|" Next EndIf Next GUICtrlSetData($hSet_Combo, $sFullModelComboList) EndIf EndFunc #EndRegion #Region ; Hide Func _MainButtons($iState) GUICtrlSetState($hLog_Button, $iState) GUICtrlSetState($hSearch_Button, $iState) GUICtrlSetState($hExit_Button, $iState) EndFunc Func _Back($hStart, $hEnd) ; delete additional controls For $i = $hStart To $hEnd GUICtrlDelete($i) Next ; Put GUI back to original size WinMove($hGUI_Main, "", Default, Default, 265, 100) EndFunc ;==>Back #EndRegionI have split the script into several functions - it was getting way too big for a single one. I have used Regions so you can hide the functions you are not looking at by clickong on the [+] #Region or by using the <View - Toggle All Folds> menu item.I have tested it a fair bit, but I am sure it is not perfect. Please ask if anything is unclear.M23Edit: Minor code change Edited December 17, 2009 by Melba23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  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