Jump to content

Script slows down way to much when using GuiGetMsg


Recommended Posts

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

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, 22)
   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
Until GUIGetMsg() = $GUI_EVENT_CLOSE

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

 

Just run thus code it will be obvious....


 

Link to comment
Share on other sites

I am on Win7 Ultimate SP1

Processor: AMD FX(tm)-8350 Eight-Core Processor 4.01 GHz

Installed Memory(RAM) : 32.0 GB

64-bit Operating system.

AMD Radeon HD 7900 Series (Tahiti)

AutoIt version: 3.3.12.0


 

Link to comment
Share on other sites

What is "bew"?

I assuming "new".

I just read the script breaking modifications on the new 3.3.14.0 version.

I think the mouse floods the messaging system with mouse messages and keeps AutoIt from Idling the CPU, and therefore it runs the script  at full speed.

Strange thing is that it produces the speed boost no matter if the cursor is in the Autoit window or not.

The slowdown really is too slow to make the scroller convenient to watch. 


 

Link to comment
Share on other sites

I see your speed change behavior on my 32-bit Windows 7 Pro SP1 with Intel Core i3 @ 3.4 GHz CPU, running AutoIt 3.3.14.5. Speedy when script GUI has focus, not speedy when other windows have focus.

I don't know how to fix it, but I wanted to report that it's not just something on your machine.

I do notice that adding a Sleep(10) command just before the Until... line alleviates the issue quite a bit. Not perfect but at least the text doesn't go supersonic in the scroller.

Link to comment
Share on other sites

It does go quite fast does it not!  And sleep(10) makes it go too slow.   I want to adjust the delay built into the GuiGetMsg() function.   Maybe there

is a byte that we can edit so I can get slow mode to go faster.

 

 


 

Link to comment
Share on other sites

@Tyranna

From the Help file:

In the OnEvent mode instead of constantly polling the GUI to find out if anything has happened you make the GUI temporarily pause your script and call a pre-defined function to handle the event.

Take a look here.

Give it a try :)

 

Best Regards.

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Use a Timer to check how many times per. second your graphics update:

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

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, 22)
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 )

Local $hTimer = TimerInit()
Do
  If TimerDiff($hTimer) > 25 Then
    _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
    $hTimer = TimerInit()
  EndIf
Until GUIGetMsg() = $GUI_EVENT_CLOSE

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

 

Link to comment
Share on other sites

Or maybe use AdlibRegister 

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

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, 22)
   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 )

AdLibRegister("_slide", 15)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

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


Func _slide()
    Static $i = 200
    _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
EndFunc

 

Link to comment
Share on other sites

New Information:  After about 25 minutes, the overspeeding caused by the mouse movement stoppend and it ran at normal speed again.

I have ran the script at least 3 times and at about 25 minutes the scroller behaves normally.  Very odd.

The scroller , when running at normal speed, is  really too slow due to the complexity of the script itself.  I do not want to slow it down more that it is.

I would however like to speed it up.  Decresing the dwell time built into the GUIGetMsg() function would do that.

I will try AdLib to update the graphics and let you know.


 

Link to comment
Share on other sites

The Adlib function fixes the mouse speeding up the scroller  problem. That is very cool.

The  scroller behavior is not real smooth anymore. And when I imbed it in my other script it is really really slow.

The GuiGetMsg() loop is really slowing this process down.  As stated above, A Do Until Loop makes the scroller  run

very fast , and I can limit easily with with a TimerInit().  But then I do not get the Message Loop.  I need a way to make the CPU Idler in the

GuiGetMsg()  function not restrict the speed so much.  Maybe we can make that function adjustable or something.  I did notice that the CPU ran at 13% when

it was in a Do Until Loop, and 6% when in the GuiGetMsg() loop.  There seems to be alot of room for speeding it up.


 

Link to comment
Share on other sites

  • Developers
8 hours ago, Tyranna said:

Really?  How does that solve this problem?

Really ? what about letting the attitude go, start thinking for a little bit and properly answering that question?

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

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...