Jump to content

GUIGetMsg Performance tip


Recommended Posts

  • Administrators

If you write a big GUI that uses the GUIGetMsg/MessageLoop mode then you will probably end up with a huge select statement checking for various clicks and controls. It might be worth remembering that AutoIt checks each Case until it finds one that is true, so it is a good idea to put the most common messages right at the top.

Even for large GUIs it will be so fast that you may not notice anyway, but I thought it was worth mentioning (maybe on slow PCs or when the system is under strain already).

The most common message will be 0, followed by $GUI_EVENT_MOUSEMOVE, so if you put a test for those at the top of your Select statement (even if you don't do anything with the mouse) then you will avoid having to check all your controls each loop for worthless messages.

While 1
  $msg = GUIGetMsg()
  
  Select
    Case $msg = 0
      ContinueLoop
    Case $msg = $GUI_EVENT_MOUSEMOVE
      ContinueLoop

    Case $msg = $mycontrol
      ...
      ...
  EndSelect
WEnd

Link to post
Share on other sites

If you write a big GUI that uses the GUIGetMsg/MessageLoop mode then you will probably end up with a huge select statement checking for various clicks and controls.  It might be worth remembering that AutoIt checks each Case until it finds one that is true, so it is a good idea to put the most common messages right at the top. 

Even for large GUIs it will be so fast that you may not notice anyway, but I thought it was worth mentioning (maybe on slow PCs or when the system is under strain already).

The most common message will be 0, followed by $GUI_EVENT_MOUSEMOVE, so if you put a test for those at the top of your Select statement (even if you don't do anything with the mouse) then you will avoid having to check all your controls each loop for worthless messages.

While 1
  $msg = GUIGetMsg()
  
  Select


    Case $msg = 0
      ContinueLoop
    Case $msg = $GUI_EVENT_MOUSEMOVE
      ContinueLoop

    Case $msg = $mycontrol
      ...
      ...
  EndSelect
WEnd

<{POST_SNAPBACK}>

:D Thx Jon i test it on my big Gui ,great idea! :idiot:
Link to post
Share on other sites

On this note I put Case $msg <= 0 right after the Case $GUI_EVENT_CLOSE = $msg

Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote]

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...