Jump to content
Tyranna

Script slows down way to much when using GuiGetMsg

Recommended Posts

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



 

Share this post


Link to post
Share on other sites
Earthshine
Posted (edited)

i can move my mouse all i want and the speed is constant... hmmmmm and I have the worst possible cpu too. an A6

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Tyranna

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



 

Share this post


Link to post
Share on other sites
Earthshine
Posted (edited)

there is a bew autoit. im on that and win 10

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Tyranna

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. 



 

Share this post


Link to post
Share on other sites
FrancescoDiMuro

@Tyranna

Did you try with:

Opt("GUIOnEventMode", 1)

? :D

 

Best Regards.

 


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
Tyranna

Not an option.

 



 

Share this post


Link to post
Share on other sites
Tyranna

New information:  The speed change happens only when the GUI for my Script has FOCUS.

 



 

Share this post


Link to post
Share on other sites
TimRude

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.

Share this post


Link to post
Share on other sites
Tyranna

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.

 

 



 

Share this post


Link to post
Share on other sites
AutoBert
2 hours ago, FrancescoDiMuro said:

Did you try with:

Opt("GUIOnEventMode", 1)

? :D

 

2 hours ago, Tyranna said:

Not an option.

The best solution is GUIOnEventMode for your problem.

  • Like 2

Share this post


Link to post
Share on other sites
Tyranna

Really?  How does that solve this problem?



 

Share this post


Link to post
Share on other sites
FrancescoDiMuro

@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

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
LarsJ

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()

 

Share this post


Link to post
Share on other sites
mikell

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

 

Share this post


Link to post
Share on other sites
Tyranna

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.



 

Share this post


Link to post
Share on other sites
Tyranna

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.



 

Share this post


Link to post
Share on other sites
Jos
Posted (edited)
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 Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Tyranna

Who are you addressing ?



 

Share this post


Link to post
Share on other sites
Earthshine

you. as the Moderator quoted you


My resources are limited. You must ask the right questions

 

Share this post


Link to post
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

×