ripdad Posted November 6, 2010 Author Posted November 6, 2010 I'm afraid thats still not fast enough -- 120ms Round Trip for 100 Pixels Heres the project I'm working on. It uses a 1ms AdLib function. "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
JohnOne Posted November 7, 2010 Posted November 7, 2010 Forgive me if this is an ignorant question, but why would you want a progress bar for any less tham 1000 ms ? never mind 150 ms. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
ripdad Posted November 7, 2010 Author Posted November 7, 2010 (edited) It has to be fast when you're capturing audio requests. I could probably get away with 10ms, but no more. Heres an example to illustrate: expandcollapse popup#include <string.au3> Local $ui = GUICreate('Stereo Level Meter', 220, 100, 100, 100, Default, 0x00000008) Local $CursorTrap = GUICtrlCreateInput('', 170, 10, 4, 20) Global $ProgressBarL = GUICtrlCreateInput('', 10, 20, 200, 18) GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetColor(-1, 0x80FF80) Global $ProgressBarR = GUICtrlCreateInput('', 10, 40, 200, 18) GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetColor(-1, 0x80FF80) GUICtrlCreateLabel('Meter Speed (ms)', 10, 71, 85, 18) Global $RTurn = GUICtrlCreateInput('', 105, 70, 40, 18) GUISetState(@SW_SHOW, $ui) ControlFocus('', '', $CursorTrap) ; Global $mciLevel, $lpszReturnString, $LeftChannel, $RightChannel, $timer Local $mciInit = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'open new type waveaudio alias mywave buffer 2', 'str', $lpszReturnString, 'long', 64, 'long', 0) If $mciInit[0] <> 0 Then Exit $mciInit = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'set mywave bitspersample 8 channels 2 samplespersec 11025', 'str', $lpszReturnString, 'long', 64, 'long', 0) If $mciInit[0] <> 0 Then Exit AdlibRegister('MCI_AdLib', 1) ; Do Sleep(30) Until GUIGetMsg() = -3 ; GUIDelete($ui) Exit Func MCI_AdLib() $timer = TimerInit() MCI_Status_Level() GUICtrlSetData($RTurn, Round(TimerDiff($timer))) EndFunc Func MCI_Status_Level() $mciLevel = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'status mywave level', 'str', $lpszReturnString, 'long', 64, 'long', 0) If $mciLevel[0] <> 0 Then Exit $LeftChannel = Round((_LoWord($mciLevel[2]) / 128) * 100) -1 $RightChannel = Round((_HiWord($mciLevel[2]) / 128) * 100) -1 GUICtrlSetData($ProgressBarL, _StringRepeat("|", $LeftChannel)) GUICtrlSetData($ProgressBarR, _StringRepeat("|", $RightChannel)) EndFunc Func _HiWord($value); From WinAPI.au3 Return BitShift($value, 16); 0x7F EndFunc Func _LoWord($value); From WinAPI.au3 Return BitAND($value, 0xFFFF); 0x7FFF EndFunc Edited November 7, 2010 by ripdad "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
Moderators Melba23 Posted November 7, 2010 Moderators Posted November 7, 2010 ripdad, Now we know what you want to do. Have you thought of something like this? expandcollapse popup#include <GUIConstantsEx.au3> Global $aLabels[101] $hGUI = GUICreate("Test", 500, 500) GUISetBkColor(0xC0C0C0) ; Create a full set of labels and hide them For $i = 0 To 100 $alabels[$i] = GUICtrlCreateLabel("", 10, 10, 20, $i) ; Set colour as required Switch $i Case 1 To 60 GUICtrlSetBkColor(-1, 0x00FF00) Case 61 to 90 GUICtrlSetBkColor(-1, 0xFFFF00) Case Else GUICtrlSetBkColor(-1, 0xFF0000) EndSwitch GUICtrlSetState(-1, $GUI_HIDE) Next GUISetState() ; Set initial index $iIndex = 0 ; Start the update function AdlibRegister("_Modify", 5) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _Modify() ; Save the current index Local $iOldIndex = $iIndex ; Simulate reading the value $iIndex = Random($iIndex - 5 , $iIndex + 5, 1) If $iIndex < 0 Then $iIndex = 0 If $iIndex > 100 Then $iIndex = 100 ; Show the new label GUICtrlSetState($aLabels[$iIndex], $GUI_SHOW) ; Delete the old one GUICtrlSetState($aLabels[$iOldIndex], $GUI_HIDE) EndFunc This way you have only a few commands to run each function call - and you have ready-made colour bands. You might want to show the new level before deleting the old one - your choice. 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
ripdad Posted November 7, 2010 Author Posted November 7, 2010 Melba, Thats an interesting approach indeed. The problem with "labels and speed" together is flicker. I ran a test on GUIDelete @ 1ms. It just can't keep up with that many calls and not cause flicker. I think I did find a solution though. Recheck the link at the top of this page. I just posted a draft of one that UEZ posted earlier in it using GDIPlus. "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
Bowmore Posted November 7, 2010 Posted November 7, 2010 I'm puzzled as to why you want to update the size of the bar every 1 millisecond. Most LCD screens used with PCs have a refresh rate of 60Hz that means the display is updated approximately once every 15 milliseconds. The LCD pixels themselves are only capable of changing their state every 3 to 5 milliseconds and finally most people are unable to see anything that is visible for less than 20 millisecond, "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook
ripdad Posted November 7, 2010 Author Posted November 7, 2010 (edited) Bowmore,I'm sorry you're puzzled. I'm working on a much bigger project and every (1ms) counts.Calling a dozen functions continuously requires speed. By the time it makes one round,theres already been 15ms gone by. I'm trying to get that down further.So .... I hope I've explained myself better to you or anyone else.In any case -- I'm delighted. Thanks UEZ. Thanks to all. Here's the result.4 progress bars in 4 directions - done in GDIPlus ... (might have to adjust your mixer controls to see properly)expandcollapse popup; Stereo Meter #include <GDIPlus.au3> _GDIPlus_Startup() ; Opt('GUIOnEventMode', 1) Local $ui = GUICreate('Stereo Meter', 200, 200, -1, -1, Default, 0x00000008 + 0x00000200) Local $iInput = GUICtrlCreateInput('', 10, 175, 50, 18) GUICtrlSetBkColor($iInput, 0xDDFFDD) Local $CursorTrap = GUICtrlCreateInput('', 200, 10, 4, 20) ; Global $hImage1, $hBrush1 = _GDIPlus_BrushCreateSolid() Global $hGraphic1 = _GDIPlus_GraphicsCreateFromHWND($ui) Global $bg_w1 = 12, $bg_h1 = 70 Global $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($bg_w1, $bg_h1, $hGraphic1) Global $hContext1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1) ; Global $hImage2, $hBrush2 = _GDIPlus_BrushCreateSolid() Global $hGraphic2 = _GDIPlus_GraphicsCreateFromHWND($ui) Global $bg_w2 = 70, $bg_h2 = 12 Global $hBitmap2 = _GDIPlus_BitmapCreateFromGraphics($bg_w2, $bg_h2, $hGraphic2) Global $hContext2 = _GDIPlus_ImageGetGraphicsContext($hBitmap2) ; GUISetState(@SW_SHOW, $ui) ControlFocus('', '', $CursorTrap) GUISetOnEvent(-3, '_Exit') ; Local $Rtn, $MCI_Request[9] = [8, 'bitspersample', 'bytespersec', 'channels', 'input', 'output', 'ready', 'samplespersec', 'time format'] Global $MCI_Level, $MCI_Rtn, $LeftChannel, $RightChannel Local $Init = MCI_Open() Local $SetCh = MCI_SetCh(2) ; If ($Init == 0) And ($SetCh == 0) Then AdlibRegister('MCI_AdLib', 5) ; While 1 Sleep(10000) WEnd ; Func MCI_AdLib() $timer = TimerInit() MCI_Status_Level() GUICtrlSetData($iInput, Round(TimerDiff($timer)) & 'ms') EndFunc ; Func Progressbar_UpDn($lChl, $rChl); Thanks goes to UEZ ; Left Channel _GDIPlus_GraphicsClear($hContext1) _GDIPlus_BrushSetSolidColor($hBrush1, 0xF000E000) _GDIPlus_GraphicsFillRect($hContext1, 1, 1, 10, Round($lChl / 1.5), $hBrush1) _GDIPlus_GraphicsDrawImageRect($hGraphic1, $hBitmap1, 90, 100, $bg_w1, - $bg_h1) ; Right Channel _GDIPlus_GraphicsClear($hContext1) _GDIPlus_BrushSetSolidColor($hBrush1, 0xF000E000) _GDIPlus_GraphicsFillRect($hContext1, 1, 1, 10, Round($rChl / 1.5), $hBrush1) _GDIPlus_GraphicsDrawImageRect($hGraphic1, $hBitmap1, 90, 112, $bg_w1, $bg_h1) EndFunc ; Func Progressbar_LtRt($lChl, $rChl); Thanks goes to UEZ ; Left Channel _GDIPlus_GraphicsClear($hContext2) _GDIPlus_BrushSetSolidColor($hBrush2, 0xF000E000) _GDIPlus_GraphicsFillRect($hContext2, 1, 1, Round($lChl / 1.5), 10, $hBrush2) _GDIPlus_GraphicsDrawImageRect($hGraphic2, $hBitmap2, 90, 100, - $bg_w2, $bg_h2) ; Right Channel _GDIPlus_GraphicsClear($hContext2) _GDIPlus_BrushSetSolidColor($hBrush2, 0xF000E000) _GDIPlus_GraphicsFillRect($hContext2, 1, 1, Round($rChl / 1.5), 10, $hBrush2) _GDIPlus_GraphicsDrawImageRect($hGraphic2, $hBitmap2, 102, 100, $bg_w2, $bg_h2) EndFunc ; Func _Exit() _GDIPlus_ImageDispose($hImage1) _GDIPlus_BrushDispose($hBrush1) _GDIPlus_BitmapDispose($hBitmap1) _GDIPlus_GraphicsDispose($hContext1) _GDIPlus_GraphicsDispose($hGraphic1) _GDIPlus_ImageDispose($hImage2) _GDIPlus_BrushDispose($hBrush2) _GDIPlus_BitmapDispose($hBitmap2) _GDIPlus_GraphicsDispose($hContext2) _GDIPlus_GraphicsDispose($hGraphic2) _GDIPlus_Shutdown() AdlibUnRegister('MCI_Status_Level') GUIDelete($ui) Exit EndFunc ; Func MCI_Status_Level() $MCI_Level = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'status mywave level', 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_Level[0] <> 0 Then AdlibUnRegister('MCI_Status_Level') Return EndIf $LeftChannel = Round(_LoWord((100 * $MCI_Level[2])) / 128) - 1 $RightChannel = Round(_HiWord((100 * $MCI_Level[2])) / 128) - 1 If $RightChannel = -1 Then $RightChannel = $LeftChannel Progressbar_UpDn($LeftChannel, $RightChannel) Progressbar_LtRt($LeftChannel, $RightChannel) EndFunc ; Func MCI_Status($request) Local $MCI_Status = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'status mywave ' & $request, 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_Status[0] <> 0 Then Return -1 Return $MCI_Status[2] EndFunc ; Func MCI_Open() Local $MCI_Open = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'open new type waveaudio alias mywave buffer 2', 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_Open[0] <> 0 Then Return -1 Return $MCI_Open[0] EndFunc ; Func MCI_SetCh($numchannels) Local $MCI_SetCh = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'set mywave bitspersample 8 channels ' & $numchannels & ' samplespersec 11025', 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_SetCh[0] <> 0 Then Return -1 Return $MCI_SetCh[0] EndFunc ; Func _HiWord($value); From WinAPI.au3 Return BitShift($value, 16) EndFunc ; Func _LoWord($value); From WinAPI.au3 Return BitAND($value, 0xFFFF) EndFunc- Edit -Fixed a problem in the script.- Edit2 -Same script as above - except reversed displayexpandcollapse popup; Stereo Meter - Reversed Display #include <GDIPlus.au3> _GDIPlus_Startup() ; Opt('GUIOnEventMode', 1) Local $ui = GUICreate('Stereo Meter', 200, 200, -1, -1, Default, 0x00000008 + 0x00000200) Local $iInput = GUICtrlCreateInput('', 10, 175, 50, 18) GUICtrlSetBkColor($iInput, 0xDDFFDD) Local $CursorTrap = GUICtrlCreateInput('', 200, 10, 4, 20) ; Global $hImage1, $hBrush1 = _GDIPlus_BrushCreateSolid() Global $hGraphic1 = _GDIPlus_GraphicsCreateFromHWND($ui) Global $bg_w1 = 12, $bg_h1 = 70 Global $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($bg_w1, $bg_h1, $hGraphic1) Global $hContext1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1) ; Global $hImage2, $hBrush2 = _GDIPlus_BrushCreateSolid() Global $hGraphic2 = _GDIPlus_GraphicsCreateFromHWND($ui) Global $bg_w2 = 70, $bg_h2 = 12 Global $hBitmap2 = _GDIPlus_BitmapCreateFromGraphics($bg_w2, $bg_h2, $hGraphic2) Global $hContext2 = _GDIPlus_ImageGetGraphicsContext($hBitmap2) ; GUISetState(@SW_SHOW, $ui) ControlFocus('', '', $CursorTrap) GUISetOnEvent(-3, '_Exit') ; Local $Rtn, $MCI_Request[9] = [8, 'bitspersample', 'bytespersec', 'channels', 'input', 'output', 'ready', 'samplespersec', 'time format'] Global $MCI_Level, $MCI_Rtn, $LeftChannel, $RightChannel Local $Init = MCI_Open() Local $SetCh = MCI_SetCh(2) ; If ($Init == 0) And ($SetCh == 0) Then AdlibRegister('MCI_AdLib', 5) ; While 1 Sleep(10000) WEnd ; Func MCI_AdLib() $timer = TimerInit() MCI_Status_Level() GUICtrlSetData($iInput, Round(TimerDiff($timer)) & 'ms') EndFunc ; Func Progressbar_UpDn($lChl, $rChl); Thanks goes to UEZ ; Left Channel _GDIPlus_GraphicsClear($hContext1) _GDIPlus_BrushSetSolidColor($hBrush1, 0xF000E000) _GDIPlus_GraphicsFillRect($hContext1, 1, 1, 10, Round($lChl / 1.5), $hBrush1) _GDIPlus_GraphicsDrawImageRect($hGraphic1, $hBitmap1, 90, 182, $bg_w1, - $bg_h1) ; Right Channel _GDIPlus_GraphicsClear($hContext1) _GDIPlus_BrushSetSolidColor($hBrush1, 0xF000E000) _GDIPlus_GraphicsFillRect($hContext1, 1, 1, 10, Round($rChl / 1.5), $hBrush1) _GDIPlus_GraphicsDrawImageRect($hGraphic1, $hBitmap1, 90, 30, $bg_w1, $bg_h1) EndFunc ; Func Progressbar_LtRt($lChl, $rChl); Thanks goes to UEZ ; Left Channel _GDIPlus_GraphicsClear($hContext2) _GDIPlus_BrushSetSolidColor($hBrush2, 0xF000E000) _GDIPlus_GraphicsFillRect($hContext2, 1, 1, Round($lChl / 1.5), 10, $hBrush2) _GDIPlus_GraphicsDrawImageRect($hGraphic2, $hBitmap2, 172, 100, - $bg_w2, $bg_h2) ; Right Channel _GDIPlus_GraphicsClear($hContext2) _GDIPlus_BrushSetSolidColor($hBrush2, 0xF000E000) _GDIPlus_GraphicsFillRect($hContext2, 1, 1, Round($rChl / 1.5), 10, $hBrush2) _GDIPlus_GraphicsDrawImageRect($hGraphic2, $hBitmap2, 20, 100, $bg_w2, $bg_h2) EndFunc ; Func _Exit() _GDIPlus_ImageDispose($hImage1) _GDIPlus_BrushDispose($hBrush1) _GDIPlus_BitmapDispose($hBitmap1) _GDIPlus_GraphicsDispose($hContext1) _GDIPlus_GraphicsDispose($hGraphic1) _GDIPlus_ImageDispose($hImage2) _GDIPlus_BrushDispose($hBrush2) _GDIPlus_BitmapDispose($hBitmap2) _GDIPlus_GraphicsDispose($hContext2) _GDIPlus_GraphicsDispose($hGraphic2) _GDIPlus_Shutdown() AdlibUnRegister('MCI_Status_Level') GUIDelete($ui) Exit EndFunc ; Func MCI_Status_Level() $MCI_Level = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'status mywave level', 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_Level[0] <> 0 Then AdlibUnRegister('MCI_Status_Level') Return EndIf $LeftChannel = Round(_LoWord((100 * $MCI_Level[2])) / 128) - 1 $RightChannel = Round(_HiWord((100 * $MCI_Level[2])) / 128) - 1 If $RightChannel = -1 Then $RightChannel = $LeftChannel Progressbar_UpDn($LeftChannel, $RightChannel) Progressbar_LtRt($LeftChannel, $RightChannel) EndFunc ; Func MCI_Status($request) Local $MCI_Status = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'status mywave ' & $request, 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_Status[0] <> 0 Then Return -1 Return $MCI_Status[2] EndFunc ; Func MCI_Open() Local $MCI_Open = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'open new type waveaudio alias mywave buffer 2', 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_Open[0] <> 0 Then Return -1 Return $MCI_Open[0] EndFunc ; Func MCI_SetCh($numchannels) Local $MCI_SetCh = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'set mywave bitspersample 8 channels ' & $numchannels & ' samplespersec 11025', 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_SetCh[0] <> 0 Then Return -1 Return $MCI_SetCh[0] EndFunc ; Func _HiWord($value); From WinAPI.au3 Return BitShift($value, 16) EndFunc ; Func _LoWord($value); From WinAPI.au3 Return BitAND($value, 0xFFFF) EndFunc Edited November 8, 2010 by ripdad "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
Bowmore Posted November 7, 2010 Posted November 7, 2010 (edited) If you are trying To get every last millisecond of speed then you may find this application AU3Profiler useful to determine which functions and code are causing your script to be slower than you desire. I've just used it to test you demo stereo meter and was able to tweak the following functions to get the average round trip time to less than 1 millisecond. MCI_Status_Level Progressbar_UpDn Progressbar_LtRt expandcollapse popup#include <GDIPlus.au3> #include <Memory.au3> _GDIPlus_Startup() ; Opt('GUIOnEventMode', 1) Local $ui = GUICreate('Stereo Meter', 200, 200, -1, -1, Default, 0x00000008 + 0x00000200) Local $iInput = GUICtrlCreateInput('', 10, 175, 50, 18) GUICtrlSetBkColor($iInput, 0xDDFFDD) Local $CursorTrap = GUICtrlCreateInput('', 200, 10, 4, 20) ; Global $hImage1, $hBrush1 = _GDIPlus_BrushCreateSolid() Global $hGraphic1 = _GDIPlus_GraphicsCreateFromHWND($ui) Global $bg_w1 = 12, $bg_h1 = 70 Global $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($bg_w1, $bg_h1, $hGraphic1) Global $hContext1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1) ; Global $hImage2, $hBrush2 = _GDIPlus_BrushCreateSolid() Global $hGraphic2 = _GDIPlus_GraphicsCreateFromHWND($ui) Global $bg_w2 = 70, $bg_h2 = 12 Global $hBitmap2 = _GDIPlus_BitmapCreateFromGraphics($bg_w2, $bg_h2, $hGraphic2) Global $hContext2 = _GDIPlus_ImageGetGraphicsContext($hBitmap2) ; GUISetState(@SW_SHOW, $ui) ControlFocus('', '', $CursorTrap) GUISetOnEvent(-3, '_Exit') ; Local $Rtn, $MCI_Request[9] = [8, 'bitspersample', 'bytespersec', 'channels', 'input', 'output', 'ready', 'samplespersec', 'time format'] Global $MCI_Level, $MCI_Rtn, $LeftChannel, $RightChannel Local $Init = MCI_Open() Local $SetCh = MCI_SetCh(2) ; If ($Init == 0) And ($SetCh == 0) Then AdlibRegister('MCI_AdLib', 2) ; While 1 Sleep(10) WEnd ; Func MCI_AdLib() Static $ciTrip = 0 Local $iTrip = 0 Local $utimer = TimerInit() MCI_Status_Level() $iTrip = Round(TimerDiff($utimer),1) If $iTrip = $ciTrip Then Return $ciTrip = $iTrip GUICtrlSetData($iInput, $iTrip & 'ms') EndFunc ; Func Progressbar_UpDn($lChl, $rChl); Thanks goes to UEZ Static $clCh = 0 Static $crCh = 0 Static $UpDateTime = 0 If TimerDiff($UpDateTime) < 20 Then Return If $clCh = $lChl And $crCh = $rChl Then Return ; Left Channel _GDIPlus_GraphicsClear($hContext1) _GDIPlus_BrushSetSolidColor($hBrush1, 0xF000E000) _GDIPlus_GraphicsFillRect($hContext1, 1, 1, 10, Round($lChl / 1.5), $hBrush1) _GDIPlus_GraphicsDrawImageRect($hGraphic1, $hBitmap1, 90, 100, $bg_w1, - $bg_h1) ; Right Channel _GDIPlus_GraphicsClear($hContext1) _GDIPlus_BrushSetSolidColor($hBrush1, 0xF000E000) _GDIPlus_GraphicsFillRect($hContext1, 1, 1, 10, Round($rChl / 1.5), $hBrush1) _GDIPlus_GraphicsDrawImageRect($hGraphic1, $hBitmap1, 90, 112, $bg_w1, $bg_h1) $clCh = $lChl $crCh = $rChl $UpDateTime = TimerInit() EndFunc ; Func Progressbar_LtRt($lChl, $rChl); Thanks goes to UEZ Static $clCh = 0 Static $crCh = 0 Static $UpDateTime = 0 If TimerDiff($UpDateTime) < 20 Then Return If $clCh = $lChl And $crCh = $rChl Then Return ; Left Channel _GDIPlus_GraphicsClear($hContext2) _GDIPlus_BrushSetSolidColor($hBrush2, 0xF000E000) _GDIPlus_GraphicsFillRect($hContext2, 1, 1, Round($lChl / 1.5), 10, $hBrush2) _GDIPlus_GraphicsDrawImageRect($hGraphic2, $hBitmap2, 90, 100, - $bg_w2, $bg_h2) ; Right Channel _GDIPlus_GraphicsClear($hContext2) _GDIPlus_BrushSetSolidColor($hBrush2, 0xF000E000) _GDIPlus_GraphicsFillRect($hContext2, 1, 1, Round($rChl / 1.5), 10, $hBrush2) _GDIPlus_GraphicsDrawImageRect($hGraphic2, $hBitmap2, 102, 100, $bg_w2, $bg_h2) $clCh = $lChl $crCh = $rChl $UpDateTime = TimerInit() EndFunc ; Func _Exit() _GDIPlus_ImageDispose($hImage1) _GDIPlus_BrushDispose($hBrush1) _GDIPlus_BitmapDispose($hBitmap1) _GDIPlus_GraphicsDispose($hContext1) _GDIPlus_GraphicsDispose($hGraphic1) _GDIPlus_ImageDispose($hImage2) _GDIPlus_BrushDispose($hBrush2) _GDIPlus_BitmapDispose($hBitmap2) _GDIPlus_GraphicsDispose($hContext2) _GDIPlus_GraphicsDispose($hGraphic2) _GDIPlus_Shutdown() AdlibUnRegister('MCI_Status_Level') GUIDelete($ui) Exit EndFunc ; Func MCI_Status_Level() $MCI_Level = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'status mywave level', 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_Level[0] <> 0 Then AdlibUnRegister('MCI_Status_Level') Return EndIf $LeftChannel = Round(_LoWord((100 * $MCI_Level[2])) / 128) - 1 $RightChannel = Round(_HiWord((100 * $MCI_Level[2])) / 128) - 1 If $RightChannel = -1 Then $RightChannel = $LeftChannel Progressbar_UpDn($LeftChannel, $RightChannel) Progressbar_LtRt($LeftChannel, $RightChannel) EndFunc ; Func MCI_Status($request) Local $MCI_Status = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'status mywave ' & $request, 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_Status[0] <> 0 Then Return -1 Return $MCI_Status[2] EndFunc ; Func MCI_Open() Local $MCI_Open = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'open new type waveaudio alias mywave buffer 2', 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_Open[0] <> 0 Then Return -1 Return $MCI_Open[0] EndFunc ; Func MCI_SetCh($numchannels) Local $MCI_SetCh = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'set mywave bitspersample 8 channels ' & $numchannels & ' samplespersec 11025', 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_SetCh[0] <> 0 Then Return -1 Return $MCI_SetCh[0] EndFunc ; Func _HiWord($value); From WinAPI.au3 Return BitShift($value, 16) EndFunc ; Func _LoWord($value); From WinAPI.au3 Return BitAND($value, 0xFFFF) EndFunc Edited to reflect changes in ripdat's previous post Edited November 7, 2010 by Bowmore "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook
ripdad Posted November 7, 2010 Author Posted November 7, 2010 Bowmore, Thanks - I'll check it out. We must have posted about the same time. I've updated the script ... It had a memory leak. It's fixed now. (My fault for not testing it thoroughly) Anyway -- I'd appreciate it if you would edit your post and do the same with the updated script. Thanks. "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
ripdad Posted November 8, 2010 Author Posted November 8, 2010 Bowmore, I did some test with your script example using AU3Profiler. I can see a use for it in some scripts. However, it did give me a great idea of alternating GDIPlus calls between the 4 bars. I modified the script for it. End result .. I didn't like it. Oh yes, I got it down to 1.5ms (steady) on turn around, but looking at the bars showed delay between them. This would have been much easier if the native progress bar would just mirror and do rotating at 90's. It would have been about 1.5ms with no work-arounds. Anyways ... below is a bare example of using GDIPlus and doing what this thread was started for. expandcollapse popup#include <GDIPlus.au3> _GDIPlus_Startup() ; Local $ui = GUICreate('Test', 200, 200, -1, -1) ; Global $hImage1, $hBrush1 = _GDIPlus_BrushCreateSolid() Global $hGraphic1 = _GDIPlus_GraphicsCreateFromHWND($ui) Global $bg_w1 = 12, $bg_h1 = 100 Global $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($bg_w1, $bg_h1, $hGraphic1) Global $hContext1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1) ; GUISetState(@SW_SHOW, $ui) ; For $i = 1 To 100 Progressbar_UpDn($i, $i) Sleep(25) Next For $i = 100 To 1 Step - 1 Progressbar_UpDn($i, $i) Sleep(25) Next _Exit() ; Func Progressbar_UpDn($up1, $down1); Thanks goes to UEZ ; Up Bar _GDIPlus_GraphicsClear($hContext1) _GDIPlus_BrushSetSolidColor($hBrush1, 0xFFFF0F00) _GDIPlus_GraphicsFillRect($hContext1, 1, 1, 10, $up1, $hBrush1) _GDIPlus_GraphicsDrawImageRect($hGraphic1, $hBitmap1, 80, 150, $bg_w1, - $bg_h1) ; Down Bar _GDIPlus_GraphicsClear($hContext1) _GDIPlus_BrushSetSolidColor($hBrush1, 0xFFFFFF00) _GDIPlus_GraphicsFillRect($hContext1, 1, 1, 10, $down1, $hBrush1) _GDIPlus_GraphicsDrawImageRect($hGraphic1, $hBitmap1, 100, 50, $bg_w1, $bg_h1) EndFunc ; Func _Exit() _GDIPlus_ImageDispose($hImage1) _GDIPlus_BrushDispose($hBrush1) _GDIPlus_BitmapDispose($hBitmap1) _GDIPlus_GraphicsDispose($hContext1) _GDIPlus_GraphicsDispose($hGraphic1) _GDIPlus_Shutdown() GUIDelete($ui) Exit EndFunc "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
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