Maffe811 Posted June 14, 2011 Posted June 14, 2011 I am trying to create a gui(settings gui) inside another gui(the main program) and when i open the settings gui i want it to fetch a true/false variable in a ini file.if its true, check the checkbox, if its false then uncheck it.Then i want different things to work and exist if its true or do neither if its false.Currently im trying to do this to test it out, but im all out of you-can-do-it spirit.The code semi-works. It doesnt hide the tray elements when its suposed to, and doesnt show em at all sometimes.If you wonder why its in a separate function, its because it first have to call the ini variables at program start, and then it has to call it again, everytime the settings gui come up... i think...Code so far:expandcollapse popup#AutoIt3Wrapper_Icon=GrooveShark.Ico #AutoIt3Wrapper_UseX64=n ;Hides the trayicon while starting up ;~ #NoTrayIcon ;Not working... #include<ie.au3> #include<splash.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt('GuiOnEventMode', 1) Opt('GUIResizeMode', 102) Opt("TrayAutoPause", 0) Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 3) ;Create tray items. $Dummy = TrayCreateItem('Nothing playing') ;TraySetToolTip('Nothing playing') TraySetToolTip("GrooveShark") TrayItemSetState($Dummy, 128) TrayCreateItem('') $sStr = StringSplit('Play|Next|Previous||Shuffle|Repeat', '|') For $i = 1 To $sStr[0] TrayCreateItem($sStr[$i]) If $sStr[$i] Then TrayItemSetOnEvent(-1, '_' & $sStr[$i]) Next $TrayHide = TrayCreateItem("Hide",-1,9) TrayItemSetOnEvent($TrayHide,"_Hide") TrayCreateItem("") $TrayExit = TrayCreateItem("Exit") TrayItemSetOnEvent($TrayExit,"_Exit") TraySetClick(8) TraySetOnEvent(-8, '_Hide') TraySetIcon("GrooveShark.Ico") ;Hides the tray while starting up ;~ Opt("TrayIconHide", 1) ;Settings handler _SettingsHandler() ;Load and shows splash image _GUI_Image() _GUI_Image_Show() ;Set hotkeys. ;HotKeySet('!d', '_Debug') ;HotKeySet('{ESC}', '_Exit2') HotKeySet('{MEDIA_PLAY_PAUSE}', '_Play') HotKeySet('{MEDIA_NEXT}', '_Next') HotKeySet('{MEDIA_PREV}', '_Prev') HotKeySet("{F5}","_SettingsDebug") HotKeySet("{F1}","_Info") HotKeySet("{F2}","_Hide") HotKeySet("{F3}","_WhatsPlaying") ;Variables. Global $oIE, $hGUI, $bActive = False, $oArtist = 'Artist', $oSong = 'Song', $sCurrent Global Const $iWidth = (@DesktopWidth/2 + @DesktopWidth/100*25), $iHeight = (@DesktopHeight/2 + @DesktopHeight/100*25), $iPid = @AutoItPID ;Create Gui. $oIE = _IECreateEmbedded() $hGUI = GUICreate('Grooveshark', $iWidth, $iHeight, -1, -1, BitOR(0x00010000, 0x00020000)) $oCtrl = GUICtrlCreateObj($oIE, -2, -2, $iWidth + 178, $iHeight - 24) GUISetOnEvent(-3, '_Exit') ;GUISetOnEvent(-4, '_GuiMini') _IENavigate($oIE, 'http://grooveshark.com') ;Wait for page to load _IELoadWait ($oIE) ;Wait for everyting else to load Sleep (4500) ;Hides the splash image _GUI_Image_Hide() ;Gives the splash time to disapear before showing the GUI Sleep (200) ;Show trayicon Opt("TrayIconHide", 0) ;Show GUI GUISetState(@SW_SHOW, $hGUI) ;Settings variables Global $IniHide, $IniBubble, $IniDisabled ;~ Global $IniHide = "true" ;IniRead($FileName,$Section,"CheckboxHide","True") Global $IniBubble = "true";IniRead($FileName,$Section,"CheckboxBubble","True") Global $IniDisabled = "true" ;IniRead($FileName,$Section,"CheckboxDisabled","True") ;Settings handler function Func _SettingsHandler() Global $IniHide = "True" If $IniHide= "True" and TrayItemGetState($TrayHide) = 1 then ;~ $TrayHide = TrayCreateItem("Hide",-1,9) $TrayHide = TrayCreateItem("Hide") ElseIf $IniHide = "false" Then TrayItemDelete($TrayHide) EndIf EndFunc Func _SettingsDebug() If $IniHide = "true" Then $IniHide = "false" ConsoleWrite("$IniHide is now " & $IniHide & @CRLF) ElseIf $IniHide = "false" Then $IniHide = "true" ConsoleWrite("$IniHide is now " & $IniHide & @CRLF) EndIf EndFunc ;Media control. Func _Next() ;~ TrayItemSetState(@TRAY_ID, 4) $oNext = _IEGetObjByName($oIE, 'player_next') _IEAction($oNext, 'click') EndFunc ;==>_Next Func _Play() ;~ TrayItemSetState(@TRAY_ID, 4) $oPlay = _IEGetObjByName($oIE, 'player_play_pause') _IEAction($oPlay, 'click') EndFunc ;==>_Play Func _Prev() ;~ TrayItemSetState(@TRAY_ID, 4) $oPrev = _IEGetObjByName($oIE, 'player_previous') _IEAction($oPrev, 'click') EndFunc ;==>_Prev Func _Shuffle() $oShuffle = _IEGetObjByName($oIE, 'player_shuffle') _IEAction($oShuffle, 'click') EndFunc ;==>_Shuffle Func _Repeat() ;~ TrayItemSetState(@TRAY_ID, 4) $oRepeat = _IEGetObjByName($oIE, 'player_loop') _IEAction($oRepeat, 'click') EndFunc ;==>_Repeat Func _GetVolume() ;~ <A style="BOTTOM: 0%" class="ui-slider-handle ui-state-default ui-corner-all" href="#" jQuery15107891455831978822="11"></A> $hfind = _IETagNameGetCollection($oIE, "A") For $h In $hfind If String($h.className) = "ui-slider-handle ui-state-default ui-corner-all" Then $iVol = StringRegExp(_IEPropertyGet($h, 'outerhtml'), '["]BOTTOM:.(.*?)%["]', 1) If IsArray($iVol) Then $iVol = $iVol[0] ConsoleWrite($iVol & @CRLF) Return $iVol Else Return -1 EndIf ExitLoop EndIf Next Return -1 EndFunc ;==>_GetVolume Func _SetVolume($iVol) $oTags = _IETagNameGetCollection($oIE, "div") For $oTag In $oTags If String($oTag.id) = "volumeSlider" Then $iVol = StringRegExpReplace(StringRegExpReplace(_IEPropertyGet($oTag, 'outerhtml'), '["]BOTTOM:.(.*?)%["]', '"BOTTOM: ' & $iVol & '%";', 1), '["]HEIGHT:.(.*?)%["]', '"HEIGHT: ' & $iVol & '%";', 1) _IEPropertySet($oTag, 'outerhtml', $iVol) ConsoleWrite($iVol & @CRLF) ExitLoop EndIf Next Return -1 EndFunc ;==>_SetVolume ;Hides the GUI into the tray. Func _Hide() $bActive = ($bActive = False) If $bActive Then GUISetState(@SW_HIDE, $hGUI) TrayItemSetText($TrayHide,"Show") Else GUISetState(@SW_SHOW, $hGUI) TrayItemSetText($TrayHide,"Hide") EndIf EndFunc ;==>_Hide ;Misc. Func _Debug() ;~ _SetVolume(50) EndFunc ;==>_Debug Func _Exit() Exit EndFunc ;==>_Exit Func _Exit2() If WinActive($hGUI) Then Exit EndFunc ;==>_Exit2 Func _RM() Local $ai = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $iPid) $ai = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai[0]) DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai[0]) EndFunc ;==>_RM Func _Info() MsgBox(64,"Info", "Grooveshark Player Info" & @CRLF & "You are currently using v2.5 " & @CRLF & "Program author: Maffe811" ) EndFunc Func _AntiFlash() If WinActivate("Adobe Flash Player 10") Then ControlClick("Adobe Flash Player 10","","[CLASS:Button; INSTANCE:1]") EndIf EndFunc Func _WhatsPlaying() If $sCurrent = "Song ~ Artist" Then TrayTip("GrooveShark", "Nothing playing",5) Else TrayTip("GrooveShark", $sCurrent,5) EndIf EndFunc Func _FakeActivity() ControlClick($hGUI, '', 'Internet Explorer_Server1', 'Primary', 1, 1, 1) EndFunc ;Reduce memory usage every 60 seconds. AdlibRegister('_RM', 60000) ;Fake activity every 15 minutes. AdlibRegister('_FakeActivity', 900000);Not sure if this works, but i will have my minions test! ;Remove flash window AdlibRegister("_AntiFlash", 5000) ;Settings Handler AdlibRegister("_SettingsHandler", 10000) ;Main Loop. $oTags = _IETagNameGetCollection($oIE, "A") While 1 ;~ _AntiFlash() For $oTag In $oTags If StringInStr($oTag.className, 'currentSongLink') Then $oSong = String($oTag.title) ElseIf StringInStr($oTag.className, 'artist') Then $oArtist = String($oTag.title) ExitLoop EndIf Next If $oSong & ' ~ ' & $oArtist <> $sCurrent Then $sCurrent = $oSong & ' ~ ' & $oArtist If $sCurrent = "Song ~ Artist" Then WinSetTitle ($hGUI, "", "GrooveShark") TrayItemSetText ($dummy,"Nothing playing") ;TraySetToolTip("Nothing playing") Else WinSetTitle($hGUI, '', 'GrooveShark ~ ' & $sCurrent) TrayItemSetText($dummy, $sCurrent) ;TraySetToolTip($sCurrent) ;Toast? If Not WinActive($hGUI) Then TrayTip("GrooveShark", $sCurrent,5) EndIf EndIf EndIf Sleep(1000) WEnd [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]
guinness Posted June 14, 2011 Posted June 14, 2011 if its true, check the checkbox, if its false then uncheck it. One Example. expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> _Main() Func _Main() Local $iCheckbox, $sData GUICreate("Quick Example Using GUIGetMsg()") $iCheckbox = GUICtrlCreateCheckbox("Hide TrayIcon", 10, 10, 120, 20) _SetCheckbox($iCheckbox, "Open Window") GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $iCheckbox ConsoleWrite("_IsChecked Shows >> " & _IsChecked($iCheckbox) & @CRLF) If _IsChecked($iCheckbox) Then $sData = "I'm Checked!, So I Window Is OnTop" TraySetState(2) Else $sData = "I'm NOT Checked!, So I Window Is Not OnTop" TraySetState(1) EndIf MsgBox(64, "What Is The State?", $sData) EndSwitch WEnd EndFunc ;==>_Main Func _IsChecked($iControlID) Return BitAND(GUICtrlRead($iControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked Func _SetCheckbox($iControlID, $sKey) Local $iState = $GUI_UNCHECKED If IniRead(@ScriptDir & "\Settings.ini", "General", $sKey, "False") = "True" Then $iState = $GUI_CHECKED EndIf Return GUICtrlSetState($iControlID, $iState) EndFunc ;==>_SetChecbox Also the Example in your post is missing custom UDF's so of course I couldn't run it, therefore I just used a previous Example I had. 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
Maffe811 Posted June 14, 2011 Author Posted June 14, 2011 Uhm, i think i posted the wrong code I had two files open and copied the wrong one But as far as your example, its easy enough to hide the tray icon, but i need one checkbox to disable a hide function and one to disable a what-is-playing traytip bubble.The hide function includes clicking on the tray to activate, clicking on a tray menu element and clicking a hot key.All those needs to be disabled when the checkbox is un-checked.The bubble function needs to only disable the tray tip.Correct code:expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;~ #NoTrayIcon Opt("GUIOnEventMode", 1) Opt("TrayMenuMode",1) Global $CheckboxHide, $CheckboxBubble, $iAbout, $iExit, $iMenu Global $FileDir= @DesktopDir Global $FileName = "Settings.ini", $Section = "Settings" Global $Settings, $IniHide, $IniBubble, $Hide, $Bubble ;============================================ If FileExists($FileDir) Then ;Check if the file directory exist. FileChangeDir($FileDir) ;If it exists, go to the file directory. Else DirCreate ($FileDir) ;If file directory doesnt exist, create it. FileChangeDir($FileDir) ;If it exists, go to the file directory. IniWrite($FileName,$Section,"CheckboxHide","True") IniWrite($FileName,$Section,"CheckboxBubble","True") EndIf Global $IniHide = IniRead($FileName,$Section,"CheckboxHide","True") Global $IniBubble = IniRead($FileName,$Section,"CheckboxBubble","True") ;============================================ TrayCreateItem("Top",-1,0) $Hide = TrayCreateItem("Hide",-1,1) $Bubble = TrayCreateItem("Bubble",-1,2) TrayCreateItem("Bottom",-1,3) ;============================================ $Gui = GUICreate("Main",300,200) _TrayManagement() GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $iMenu = GUICtrlCreateMenu("Menu") $iSettings = GUICtrlCreateMenuItem("Settings", $iMenu) GUICtrlSetOnEvent(-1, "_Settings") $iExit = GUICtrlCreateMenuItem("Exit", $iMenu) GUICtrlSetOnEvent(-1, "_Exit") GUISetState(@SW_SHOW,$gui) ;============================================ While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ;============================================ Func _Settings() #Region ### START Koda GUI section ### ;Create GUI $Settings = GUICreate("Settings", 358, 196) ;If window is closed then exit GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit" & "_TrayManagement") $IniHide = IniRead($FileName,$Section,"CheckboxHide","True") $IniBubble = IniRead($FileName,$Section,"CheckboxBubble","True") ;Gui content ;Disable hide function $CheckboxHide = GUICtrlCreateCheckbox("Disable Hide function", 16, 8, 321, 41) If $IniHide = "True" Then GUICtrlSetState($CheckboxHide,$GUI_CHECKED) ElseIf $IniHide = "False" Then GUICtrlSetState($CheckboxHide,$GUI_UNCHECKED) EndIf ;Disable Whats playing bubble $CheckboxBubble = GUICtrlCreateCheckbox("Disable Whats playing bubble", 16, 48, 321, 41) GUICtrlSetState(-1,$GUI_CHECKED) If $IniBubble = "True" Then GUICtrlSetState($CheckboxBubble,$GUI_CHECKED) ElseIf $IniBubble = "False" Then GUICtrlSetState($CheckboxBubble,$GUI_UNCHECKED) EndIf ;OK button $ButtonOk = GUICtrlCreateButton("Ok", 30, 144, 129, 41, $WS_GROUP) GUICtrlSetOnEvent(-1, "_ButtonOk") ;Cancel button $ButtonCancel = GUICtrlCreateButton("Cancel", 198, 144, 129, 41, $WS_GROUP) GUICtrlSetOnEvent(-1, "_Exit") ;Show gui GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### EndFunc Func _TrayManagement() If $IniHide = "True" and TrayItemGetState($Hide) = 1 Then $Hide = TrayCreateItem("Hide",-1,1) ElseIf $Inihide = "False" then TrayItemDelete($Hide) Endif If $IniBubble = "True" and TrayItemGetState($Bubble) = 1 Then $Bubble = TrayCreateItem("Bubble",-1,2) ElseIf $IniBubble = "False" then TrayItemDelete($Bubble) Endif EndFunc ;Check for checkedness Func _IsChecked($iControlID) Return BitAND(GUICtrlRead($iControlID), 1) = 1 EndFunc;==>_IsChecked ;Ok button function. Will check for checkmarks Func _ButtonOk() ConsoleWrite("Hide function is " & _IsChecked($CheckboxHide) & @CRLF & "Bubble function is " & _IsChecked($CheckboxBubble) & @CRLF) IniWrite($FileName,$Section,"CheckboxHide",_IsChecked($CheckboxHide)) IniWrite($FileName,$Section,"CheckboxBubble",_IsChecked($CheckboxBubble)) ;~ ConsoleWrite("Hide function is " & $CheckboxHideData & @CRLF & "Bubble function is " & $CheckboxBubbleData & @CRLF & "Disabled function is " & $CheckboxDisabledData & @CRLF) GUIDelete($Settings) _TrayManagement() EndFunc;==>_ButtonOk ;Exit function. Both clicking the cancel button and closing the gui will use the _Exit function! Func _Exit() Exit EndFunc;==>_Exit [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]
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