Jump to content

Script slows down way to much when using GuiGetMsg


Recommended Posts

Ok, well , let me elaborate then.

Really?  =  ( with suprise...is that true? )

How does that solve this problem?  ( Please explain how this would solve this problem. 'technically'  I really want to know )

I can see how reading my post , that it might like I am giving you attitude, but I am really asking what is behind your thinking.

 


 

Link to comment
Share on other sites

Your script in GuiOnEvent-Mode:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>

Opt("GUIOnEventMode", 1)

Global $TextString = "                                                                                                                " & _
                     "This scroller speeds up massively when I move the mouse.  When the mouse is NOT moving then the scrolling slows "  & _
                     "down to a crawl.  I would like to be able to control the speed at which the scrolling is done and not have a cha"  & _
                     "nge in speed when moving the mouse.  Maybe someone can tell me what I need to do to keep a consistent speed for "  & _
                     "this. I tried a Do / Until loop and it ran consitently super fast.  When I use GuiGetMsg , the scroller starts f"  & _
                     "ast momentarily and then becomes slow. This I am sure is due to the dwell in the GuiGetMsg function itself.  I n"  & _
                     "eed to be able to regulate the dwell time for GuiGetMsg cpu idling or pick up the window messages another way..."

   $hGUI = GUICreate("GDI+", 400, 220)
   GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton")
   Global $MovingInput = GUICtrlCreateLabel( "" , 0 , 0 , 400 , 22 , $ES_READONLY , $WS_EX_TRANSPARENT )
   $Handle = GUICtrlGetHandle(-1)
   GUISetState(@SW_SHOW)
   Local $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout
   Local $aInfo
   Local $bitmap
   Local $i = 200


   _GDIPlus_Startup()
   $hGraphic = _GDIPlus_GraphicsCreateFromHWND($Handle)
   $bitmap = _GDIPlus_BitmapCreateFromGraphics( 400 , 22 , $hGraphic )
   $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)

   $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFF00)
   $hFormat = _GDIPlus_StringFormatCreate( 0x1000 )
   $hFamily = _GDIPlus_FontFamilyCreate( "Arial" )
   $hFont = _GDIPlus_FontCreate($hFamily, 10 , 1)
   $tLayout = _GDIPlus_RectFCreate( 0 , 0 , 8192 , 16 )
   $aInfo = _GDIPlus_GraphicsMeasureString( $backbuffer , $TextString , $hFont , $tLayout , $hFormat )
   _GDIPlus_GraphicsDrawStringEx( $backbuffer , $TextString , $hFont , $aInfo[0] , $hFormat , $hBrush )

Do
   _GDIPlus_GraphicsClear ( $backbuffer , 0xFF000000 )
   $tLayout = _GDIPlus_RectFCreate( $i , 4 , 8192 , 16 )
   $aInfo = _GDIPlus_GraphicsMeasureString( $backbuffer , $TextString , $hFont , $tLayout , $hFormat )
   _GDIPlus_GraphicsDrawStringEx( $backbuffer , $TextString , $hFont , $aInfo[0] , $hFormat , $hBrush )
   _GDIPlus_GraphicsDrawImageRect( $hGraphic , $bitmap , 0 , 0 , 400 , 22 )
   $i = $i -1
   If $i < -5000 Then $i = 1
   Sleep(30)    ;adjust sleeptime to your needs
Until False

func CLOSEButton()
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc

 

Link to comment
Share on other sites

  • Developers
3 hours ago, Tyranna said:

Ok, well , let me elaborate then.

Really?  =  ( with suprise...is that true? )

How does that solve this problem?  ( Please explain how this would solve this problem. 'technically'  I really want to know )

I can see how reading my post , that it might like I am giving you attitude, but I am really asking what is behind your thinking.

 

You see how simple statements come across differently. I now understand you meant to say the same thing but your first version came across totally different.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Thanks for the Example on OnEvent.  I tried it and it works to a point.

But , as I stated , it is not really an option. I have a script with  over 6000 lines that I am adding this to.

 It runs a GUIGetMsg() Loop , and a call to this function is what updates the scroller.  I would prefer not to rewrite it all.

Anyway , the sleep function fails as a speed modifier ,  Its minumum is 10 no matter what you set it to and thats way too large to be effective.

Especially when added to an already iterating loop taking up even more CPU cycles.  

 

 This script uses only 6% of my processing power on one CPU.  And I know by testing it in a Do Loop that it can run a whole lot faster. So I would think that

there would be some room to speed it up , so here is what I would like to know...

1.) How the speed of the main GUIGetMsg() loop is governed. :  Is it capping execution speed , and if it is not , what is.

 

 


 

Link to comment
Share on other sites

Split your code into two scripts that runs as independent processes. A primary script that runs in MessageLoop Mode and handles user input and also starts and stops the secondary script. And a secondary script that runs in OnEvent Mode and handles the graphics. When it's two different processes, GUIGetMsg() will not affect the graphics in the other process.

Link to comment
Share on other sites

4 hours ago, Tyranna said:

How the speed of the main GUIGetMsg() loop is governed

Run your script, open task manager and see the CPU usage. When you don't move mouse then CPU usage is 0, because AutoIt pauses the script for about 10ms if GuiGetMsg receives 0. If you start to move mouse then GuiGetMsg reads messages and don't pauses the script, but CPU usage in this case is maximum.

Edited by InnI
Corrected 1ms to 10ms
Link to comment
Share on other sites

Thanks , that sounds coherent.                                                                                                                                                                                                                                                                          I did look at the Task manager and saw 6% and about 13%.

Q1: Is there another way to get the messages that does not involve slowing/halting the script?

Q2: Is there a way to set the delay time for the GUIGetMsg() function? 
I understand that you do not want to run a CPU at 100% when there are no messages , but when you approach the point where the size of the delay cripples the rest of the script to run effectively , then it would be logical to reduce the delay time to accommodate.  1ms Is a pretty huge wait state when you have a 4.0Ghz processor.

Q3: Can AutoIt  be changed to allow the dwell time to be changed?

 

 

 

 


 

Link to comment
Share on other sites

  • Developers
11 minutes ago, Tyranna said:

Q1: Is there another way to get the messages that does not involve slowing/halting the script?

Thought we went over this: by using the OnEventMode, which has zero delay and works with interupts. Ofcourse eveything runs in a single thread, so one thing at the time is performed.

11 minutes ago, Tyranna said:

Q2: Is there a way to set the delay time for the GUIGetMsg() function? 

No

10 minutes ago, Tyranna said:

OMG, how can I lose this doubles spacing

Shift+Enter does a soft return and Enter a hard return.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

29 minutes ago, Tyranna said:

1ms Is a pretty huge wait state when you have a 4.0Ghz processor.

Even in OnEvent mode, if you put a sleep in to not use all of your CPU when idle, the lowest that sleep will go is 10ms, even if you put in Sleep(1).

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 Gude
How 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

(I love shift enter now) 

The root problem here is the limiter in the function GUIGetMsg().
On its face , the assertion that " If my message loop receives no messages then all other script functions will be delayed." is obviously flawed.

Solution:  Go back to the Code base and remove the limiter , replacing it with code that limits a race condition on the backside rather than the front:

Entrance into function GuiGetMsg()
     ---> Received no Messages---> Set Race Timer---> Return to Script.
Entrance into function GuiGetMsg()--->Received no Messages--->Check--Are we racing?
   ---> No ---> Return to Script.
   ---> Yes ---> Insert dwell --->Reset race timer.--->Return to Script.

Recompile the code.
Release it in the next version.

No more root problem.

 


 

Link to comment
Share on other sites

  • Developers

Sure, thanks for pointing this out to us and we will get to it first thing.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Tyranna,

it seems like you are mixing in a bunch of too many things ..

What can you expect from the poor label control & having GDI in the mix plus feeding them with negative values
It isn't some kind of a rotate function that you need ..

Anyways, you really should think of something simpler  :

Local $sTex, $sTexL, $pad, $iSpeed = 60
Do
    While StringLen($sTex) > 2
        Sleep($iSpeed)
        
        If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop 2
        $sTex = StringTrimLeft($sTex, 1)
        $sTexL = StringLeft($sTex, 50)
        $pad = ""
        StringReplace($sTexL, " ", " ")
        For $i = 1 To @extended
            $pad &= " "
        Next
        $sTexL = $pad & $sTexL
        _GDIPlus_GraphicsClear($backbuffer, 0xFF000000)
        _GDIPlus_GraphicsDrawStringEx($backbuffer, $sTexL, $hFont, $aInfo[0], $hFormat, $hBrush)
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $bitmap, 0, 0, 400, 22)
    WEnd
    $sTex = $TextString
Until GUIGetMsg() = $GUI_EVENT_CLOSE

 

Edited by Deye
Link to comment
Share on other sites

Thanks , I appreciate the supposition that using a smaller segment of the string would be better. Then there would be less time spent painting.

However this code does not scroll the image , it moves to the left the full width of the letter , and makes no accounting of the width of letter.

 

 

 


 

Link to comment
Share on other sites

As already suggested by @LarsJ, using 2 separate script may be a good way to go

here is a trivial example just to show how you can use a script detached from the main script that can run separately but at the same time to be controlled by the main script

Save the following two scripts in the same folder and run the main script. The buttons can control the direction of the text and the end of both scripts. You can also click on the scrolling text and drag it around.

Main script:

; spawn the "detached" process, keep anyway the pid and the stdin stream
Local $DetachedProcess = Run(@AutoItExe & " .\TextSlider.au3", '', Default, 0x1) ; 0x1 -> $STDIN_CHILD
GUICreate("Marquee controller", 300, 100, 20, 20)
Local $Button1 = GUICtrlCreateButton(" <==== ", 10, 10, 80, 80)
Local $Button2 = GUICtrlCreateButton(" ====> ", 110, 10, 80, 80)
Local $Button3 = GUICtrlCreateButton(" The end ", 210, 10, 80, 80)
GUISetState()

While 1
    $idMsg = GUIGetMsg()
    Select
        Case $idMsg = $Button1
            StdinWrite($DetachedProcess, "R2L")
        Case $idMsg = $Button2
            StdinWrite($DetachedProcess, "L2R")
        Case $idMsg = $Button3
            StdinWrite($DetachedProcess, "bye")
            GUIDelete()
            ExitLoop
    EndSelect
WEnd

 

TextSlider.au3

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>

Example()
MsgBox(0, 0, "Bye Bye")
; the end

Func Example()
    Local $sCommand

    Local $TextString = "                                                                                                                " & _
            "This scroller speeds up massively when I move the mouse.  When the mouse is NOT moving then the scrolling slows " & _
            "down to a crawl.  I would like to be able to control the speed at which the scrolling is done and not have a cha" & _
            "nge in speed when moving the mouse.  Maybe someone can tell me what I need to do to keep a consistent speed for " & _
            "this. I tried a Do / Until loop and it ran consitently super fast.  When I use GuiGetMsg , the scroller starts f" & _
            "ast momentarily and then becomes slow. This I am sure is due to the dwell in the GuiGetMsg function itself.  I n" & _
            "eed to be able to regulate the dwell time for GuiGetMsg cpu idling or pick up the window messages another way..."

    Local $hGUI = GUICreate("GDI+", 400, 22, -1, -1, $WS_POPUP)
    Local $MovingInput = GUICtrlCreateLabel("", 0, 0, 400, 22, $ES_READONLY, BitOR($WS_EX_TRANSPARENT, $GUI_WS_EX_PARENTDRAG))
    Local $Handle = GUICtrlGetHandle(-1)
    GUISetState(@SW_SHOW)
    Local $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout
    Local $aInfo
    Local $bitmap
    Local $i = 200


    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($Handle)
    $bitmap = _GDIPlus_BitmapCreateFromGraphics(400, 22, $hGraphic)
    $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)

    $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFF00)
    $hFormat = _GDIPlus_StringFormatCreate(0x1000)
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 10, 1)
    Local $step = -1
    ; $tLayout = _GDIPlus_RectFCreate(0, 0, 8192, 16)

    Do
        $sCommand = ConsoleRead() ; see if we have a command from the boss
        Select
            Case $sCommand = "L2R" ; scroll Left to Right
                $step = 1
            Case $sCommand = "R2L" ; scroll Right to Left
                $step = -1
        EndSelect
        _GDIPlus_GraphicsClear($backbuffer, 0xFF000000)
        $tLayout = _GDIPlus_RectFCreate($i, 4, 8192, 16)
        $aInfo = _GDIPlus_GraphicsMeasureString($backbuffer, $TextString, $hFont, $tLayout, $hFormat)
        _GDIPlus_GraphicsDrawStringEx($backbuffer, $TextString, $hFont, $aInfo[0], $hFormat, $hBrush)
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $bitmap, 0, 0, 400, 22)
        $i = $i + $step
        If $i < -5000 Then $i = 1
        If $i > 1 Then $i = -5000
    Until $sCommand = "bye"

    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Like a variant

#include <GDIPlus.au3>

$TextString = "                                                                                                                " & _
              "This scroller speeds up massively when I move the mouse.  When the mouse is NOT moving then the scrolling slows " & _
              "down to a crawl.  I would like to be able to control the speed at which the scrolling is done and not have a cha" & _
              "nge in speed when moving the mouse.  Maybe someone can tell me what I need to do to keep a consistent speed for " & _
              "this. I tried a Do / Until loop and it ran consitently super fast.  When I use GuiGetMsg , the scroller starts f" & _
              "ast momentarily and then becomes slow. This I am sure is due to the dwell in the GuiGetMsg function itself.  I n" & _
              "eed to be able to regulate the dwell time for GuiGetMsg cpu idling or pick up the window messages another way..."

$hGUI = GUICreate("GDI+", 400, 22)
GUISetState(@SW_SHOW)

_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFF00)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 10, 1)
$tLayout = _GDIPlus_RectFCreate()
$aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $TextString, $hFont, $tLayout, $hFormat)
$iWidth = Ceiling($aInfo[0].Width)
$hBitmap = _GDIPlus_BitmapCreateFromScan0($iWidth, 22)
$hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsClear($hBackbuffer, 0xFF000000)
_GDIPlus_GraphicsDrawStringEx($hBackbuffer, $TextString, $hFont, $aInfo[0], $hFormat, $hBrush)

$i = 0
AdlibRegister("Draw", 11)
Do
Until GUIGetMsg() = -3

_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_GraphicsDispose($hBackbuffer)
_GDIPlus_Shutdown()

Func Draw()
  _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hBitmap, $i, 0, 400, 22, 0, 0, 400, 22)
  $i += 1 ; <================ speed controller ($i += 3 is faster)
  If $i = $iWidth Then $i = 0
EndFunc

 

Link to comment
Share on other sites

  • 3 weeks later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...