Champak Posted January 2, 2017 Share Posted January 2, 2017 This code works randomly/intermittently. If I run the code 10 times 1-2 times wont work. I added the sleep to hopefully help, but it didn't. Any idea why? Local $DB = "DB Meter" ConsoleWrite(WinGetState($DB)) ;BitAND(WinGetState($MEDIAGUI), 2) If WinGetState($DB) = 5 Then Sleep(100) WinSetState("DB Meter", "", @SW_SHOW) Else Sleep(100) WinSetState("DB Meter", "", @SW_HIDE) EndIf Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted January 2, 2017 Moderators Share Posted January 2, 2017 Is it intermittent only with that window, or with all? If the former, what is DB Meter exactly? By replacing DB Meter with Notepad, this worked just fine for me. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
mikell Posted January 2, 2017 Share Posted January 2, 2017 You might try this $iState = WinGetState($DB) If BitAND($iState, 5) Then ... Link to comment Share on other sites More sharing options...
Champak Posted January 3, 2017 Author Share Posted January 3, 2017 @JLogan3o13 Yes, it's only happening with this app as far as I see. expandcollapse popup#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Install\Install Additions\Icons\INMDB4.ico #AutoIt3Wrapper_Outfile=Install\Install Helpers\INM DB Meter.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;#requireadmin #include <WinAPI.au3> #include <Array.au3> #include <Array2.au3> #include <WindowsConstants.au3> #include <ProgressConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #Include <string.au3> #Include <GUIConstants.au3> #include <misc.au3> #include <MailSlot.au3> ;Opt("TrayIconHide", 1) Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 0) Opt("GUIOnEventMode", 1) Global Const $hMailSlot_To_Main = "\\.\mailslot\INavMedia-Media1";===Send data to INavMedia Global Const $hMailSlot_PRE_Setup = "\\.\mailslot\INavMedia-Media2";===Receive data from INavMedia Global Const $hMailSlot_From_Main = _MailSlotCreate($hMailSlot_PRE_Setup) ;$SH = TrayCreateItem ( "Show/Hide") ;TrayItemSetOnEvent($SH,"_ShowHide") ;TraySetState() DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 1);========================Makes it so I can set the color of the progress bar background Global $AppName = RegRead("HKEY_CURRENT_USER\SOFTWARE\INavMedia", "App Name") ;Global $DB = RegRead("HKEY_CURRENT_USER\SOFTWARE\INavMedia", "Audio Clipping DB") Global $Run_DBMeter = True Global $lpszDevice = "new type waveaudio" Global $lpszOpenFlags = "alias mywave" Global $lpszFlags = "" Global $lpszCommand = StringFormat("open %s %s %s", $lpszDevice, $lpszOpenFlags, $lpszFlags) Global $lpszReturnString = _StringRepeat(" ", 100) Global $cchReturn = StringLen($lpszReturnString) Global $mciError = _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, 0); If $mciError[0] <> 0 Then _mciShowError($mciError[0]) Global $lpszDeviceID = "mywave" Global $lpszRequest = "level" Global $lpszFlags = "" $lpszCommand = StringFormat("status %s %s %s", $lpszDeviceID, $lpszRequest, $lpszFlags) Global $hWnd = WinGetHandle($AppName & " - Visual Screen") Global $PeakHold = TimerInit() #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("DB Meter", 422, 20, -2, -75, $WS_POPUPWINDOW, BitOR($WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE), $hWnd) GUISetBkColor("0x000000") GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_ShowHide") $Progress1 = GUICtrlCreateProgress(0, 0, 422, 20, $PBS_SMOOTH) GUICtrlSetBkColor($Progress1, "0x000000") $Meter = GUICtrlCreateLabel("",0,0,0,0); GUICtrlCreateDummy() GUICtrlSetBkColor($Progress1, "0x000000") GUICtrlSetState(-1, $GUI_HIDE) ;$BackgroundRim2 = GUICtrlCreateLabel("", 235, 0, 12, 30) ; GUICtrlSetBkColor($BackgroundRim2, "0xff0000") $Progress2 = GUICtrlCreateLabel("", 402, 3, 20, 16) GUICtrlSetBkColor($Progress2, "0x000000") ; $hWnd = WinGetHandle("INavMedia - Visual Screen") _WinAPI_SetWindowPos($Form1, $hWnd, -2, -75, 422, 20, $SWP_NOACTIVATE ) GUISetState(@SW_HIDE, $Form1) ;GUISetState(@SW_SHOW, $Form1) ;Sleep(3000) #EndRegion ### END Koda GUI section ### $mciError2 = 0 While 1 Sleep(25);===CPU usage is already extremely low, but increasing this to 50 will drop cpu usage to next to nothing. ;====If we receive the message to stop or pause music, set indicator to stop retrieving level Local $iSize = _MailSlotCheckForNextMessage($hMailSlot_From_Main) If $iSize Then Local $sData = _MailSlotRead($hMailSlot_From_Main, $iSize, 2) $Run_DBMeter = $sData[1] GUICtrlSetData($Progress1,0) EndIf If $Run_DBMeter = "True" Then If BitAND(WinGetState($AppName & " - Visual Screen"), 2) And BitAND(WinGetState($Form1), 2) Then;===Check if window is visible $mciError = _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, 0); If $mciError[0] <> 0 Then _mciShowError($mciError[0]) $mciError = (GUICtrlRead($Meter)*$mciError[2]) ConsoleWrite($mciError & @CRLF) If $mciError > $mciError2 Then $Increment = +1 $mciError2 = $mciError Else $Increment = -1 $mciError2 = $mciError EndIf If $mciError > 100 Then $mciError = 100 ; TrayTip("level", $mciError, 1000) _SETPROGCOLOR($mciError) ; ControlSetText($AppName & " - Visual Screen", "Next", 158, $mciError) _MailSlotWrite($hMailSlot_To_Main, $mciError, 2, "99") EndIf EndIf If Not WinExists($AppName & " - Visual Screen") Then Exit WEnd Func _ShowHide() $KEYBOARDSTATE = WinGetState($Form1) $KEYBOARDSTATE2 = ControlGetFocus("DB Meter") GUISetState(@SW_SHOWNORMAL, $Form1) GUISetState(@SW_HIDE, $Form1) EndFunc Func _SETPROGCOLOR($MXVOL) $MXVOL2 = $MXVOL; + 1 If $MXVOL2 < 0 Then $MXVOL2 = 0 If $MXVOL2 > 1000 Then $MXVOL2 = 1000 $Redness = Int(255 - ($MXVOL2 / 100 * 112)) If $Redness < 0 Then $Redness = 0 $Greeness = Int(($MXVOL2 / 100 * 512) - 257 ) If $Greeness < 0 Then $Greeness = 0 $Blueness = Int(255 - ($Redness + $Greeness)) $PROGCOLOR = ( $Greeness * 256 * 256) + ($Redness * 256) ;TrayTip($mciError,$Increment,1) GUICtrlSetData($Progress1, Int($MXVOL2)) GUICtrlSetColor($Progress1, $PROGCOLOR) ; If TimerDiff($PeakHold) > 1000 Then If $mciError > 95 Then GUICtrlSetBkColor($Progress2, 0xFF0000) ; $PeakHold = TimerInit() ; TrayTip("level", $mciError, 1000) Else;If $mciError < 95 Then GUICtrlSetBkColor($Progress2, 0x000000) EndIf ; EndIf EndFunc ;==>_SETPROGCOLOR Func _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, $hwndCallback) Return DllCall("winmm.dll", "long", "mciSendStringA", "str", $lpszCommand, "str", $lpszReturnString, "long", $cchReturn, "long", 0) EndFunc ;==>_mciSendString Func _mciShowError($mciError) Dim $errStr; Error message $errStr = _StringRepeat( " ", 100) ; Reserve some space for the error message $Result = DllCall("winmm.dll", "long", "mciGetErrorStringA", "long", $mciError, "string", $errStr, "long", StringLen($errStr)) MsgBox(0, "MCI test", "MCI Error Number " & $mciError & ":" & $Result[2]) EndFunc ;==>_mciShowError @mikell I've done that before with the same results. One other thing if it is of any importance, this app lays right on top of another GUI I have when it is showing. Link to comment Share on other sites More sharing options...
iAmNewbe Posted January 3, 2017 Share Posted January 3, 2017 16 hours ago, Champak said: This code works randomly/intermittently. If I run the code 10 times 1-2 times wont work. I added the sleep to hopefully help, but it didn't. Any idea why? Local $DB = "DB Meter" ConsoleWrite(WinGetState($DB)) ;BitAND(WinGetState($MEDIAGUI), 2) If WinGetState($DB) = 5 Then Sleep(100) WinSetState("DB Meter", "", @SW_SHOW) Else Sleep(100) WinSetState("DB Meter", "", @SW_HIDE) EndIf Your IF statement is assigning 5 to WinGetState($DB) WinGetState($DB) = 5 Then should be WinGetState($DB) == 5 Then You should NEVER hit the ELSE statement the way it is now so the DB Meter line will always be shown. If it is happening intermittently then I would look at other parts of your code that calls this section and find if it isn't duplicated anywhere else or it is being called only in certain circumstances. Link to comment Share on other sites More sharing options...
BrewManNH Posted January 3, 2017 Share Posted January 3, 2017 12 hours ago, iAmNewbe said: Your IF statement is assigning 5 to WinGetState($DB) No it's not. It's comparing WingetState to the value of 5. The double equals sign is used (in AutoIt) as a case sensitive string comparison. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted January 3, 2017 Moderators Share Posted January 3, 2017 (edited) 13 hours ago, iAmNewbe said: You should NEVER hit the ELSE statement the way it is now so the DB Meter line will always be shown. Also completely wrong, as shown in my own reply in post #2: Quote By replacing DB Meter with Notepad, this worked just fine for me. Edited January 3, 2017 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
iAmNewbe Posted January 19, 2017 Share Posted January 19, 2017 (edited) Hmm... I didn't know that the = was also a comparison operator in AutoIT. Leaving that up to interpretation by context is interesting. In that case then what I posted was wrong, I thought all it was doing was assigning the 5 so it would never get to the ELSE. Now if that was ALWAYS an assignment operator I would of been correct at least with the ELSE statement. Interesting. Edited January 19, 2017 by iAmNewbe Link to comment Share on other sites More sharing options...
BrewManNH Posted January 19, 2017 Share Posted January 19, 2017 In AutoIt, the equals sign is used as an assignment operator as well as an equality operator. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
iAmNewbe Posted January 20, 2017 Share Posted January 20, 2017 Yes, I am not only using AutoIt for programming languages and am used to to assignment only with a single equal sign. I find it interesting the choice in allowing that but as stated above you are correct. 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