Jump to content

guigetmsg


Yeik
 Share

Recommended Posts

Ok if i use GUIGetMsg(), i have to have a loop

while 1 
    $msg= GUIGetMsg()
   switch $msg
       case $GUI_EVENT_CLOSE
     .....
     ....

Personally i dont like loops, especially if there are conditions that need to be checked, and code that then needs to be run.

So im curious as to why i see more people use GuiGetMsg() than as to GUISetOnEvent(), what are advantages/disadvantages to both?

I know that both require loops to keep the GUI from closing, dont understand why that is though. But atleast with GUISetOnEvent() i can make the loop sleep() or just run so it isn't going over variables and code constantly in the loop. or is that how GUISetOnEvent() works is by creating a seperate loop just to wait? i assume it just has an object call made as that seems like the best way to do it.

func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()
Link to comment
Share on other sites

For anything somewhat complicated I use GuiSetOnEvent... I think it's much more efficient. However, the standard mode with GuiGetMsg is easier to make simple program in. Also, GuiSetOnEvent leaves your loop open for anything else you might need to do.

If the GUIOnEventMode option is set to 1 then the return from GUIGetMsg is always 0 and the @error is set to 1.

So i noticed you can't mix and match. so if you mean the loop that keeps the GUI open, then i guess you could, but i still dont see much use for the GUIGetMsg function unless you just have a GUI pop up and then close itself out after a set amount of time with very basic options.

So am i correct in thinking that GUIGetMsg is probably more of just some Legacy code that is still supported?

func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()
Link to comment
Share on other sites

  • Moderators

If the GUIOnEventMode option is set to 1 then the return from GUIGetMsg is always 0 and the @error is set to 1.

So i noticed you can't mix and match. so if you mean the loop that keeps the GUI open, then i guess you could, but i still dont see much use for the GUIGetMsg function unless you just have a GUI pop up and then close itself out after a set amount of time with very basic options.

So am i correct in thinking that GUIGetMsg is probably more of just some Legacy code that is still supported?

Some of us prefer it with simple (even complicated) GUI's, rather than having to make several functions for specific things (Or even an event handler that does everything you would have thrown into a loop anyway).

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Some of us prefer it with simple (even complicated) GUI's, rather than having to make several functions for specific things (Or even an event handler that does everything you would have thrown into a loop anyway).

Ok, but to me, with the little code experience i have, was always taught to code for efficiency and for tidyness, there is nothing wrong with having extra functions. I think of it this way, when i go to clean my desk/garage, I like to have everything neat, organized where i can easily get to it. I know exactly where everything is at and why its there, move it without having to rearrange my whole garage because i had to change it for something different. On the other hand people like it simpler where its just a simple desk and its not hard to rearrange, lets just put everything in this spot, in a box.

Not to be offensive towards anybody if it gets taken that way, I am just trying to find out if there is a benefit, something you can do with one, that isn't possible with the other.

func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()
Link to comment
Share on other sites

Event mode is better than GuiGetMsg mode (which is nothing but waste of CPU power, even if your app is a "Hello world" with 2 buttons, not even talking about bigger GUIs), but it requires some extra typing to set up. Which, depending on one's coding habits (such as, not having a template script to build on, or simply not wanting to obscure the example with bunch of unrelated code), may be too boring/unwanted to do when writing some short example of something that is often unrelated to actual GUI work at all (and which is just that - an example, not the final version of an app). I do that all the time. But I'd never even consider using GuiGetMsg mode in my apps.

I guess newbies use GuiGetMsg mode because they see all examples using it, and, being newbs, just don't know better.

Seriously, don't worry, you are on the right path. Forget about GuiGetMsg(). I wish the "Goto is bad" sayers around here would focus on killing this abomination instead. :)

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

  • Moderators

Event mode is better than GuiGetMsg mode (which is nothing but waste of CPU power, even if your app is a "Hello world" with 2 buttons, not even talking about bigger GUIs)

Maybe I'm a noob...

But to respond to the above quote:

Global $hGUI, $nB1, $nB2
$hGUI = GUICreate("My GUI")
$nB1 = GUICtrlCreateButton("B1", 10, 10, 30)
$nB2 = GUICtrlCreateButton("B2", 10, 40, 30)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $nB1
            MsgBox(64, "Info", "B1")
        Case $nB2
            MsgBox(64, "Info", "B2")
    EndSwitch
WEnd
Not sure if you're referring to the "Olddddd" GUIGetMsg()?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Event mode is better than GuiGetMsg mode (which is nothing but waste of CPU power, even if your app is a "Hello world" with 2 buttons, not even talking about bigger GUIs), but it requires some extra typing to set up. Which, depending on one's coding habits (such as, not having a template script to build on, or simply not wanting to obscure the example with bunch of unrelated code), may be too boring/unwanted to do when writing some short example of something that is often unrelated to actual GUI work at all (and which is just that - an example, not the final version of an app). I do that all the time. But I'd never even consider using GuiGetMsg mode in my apps.

I guess newbies use GuiGetMsg mode because they see all examples using it, and, being newbs, just don't know better.

Seriously, don't worry, you are on the right path. Forget about GuiGetMsg(). I wish the "Goto is bad" sayers around here would focus on killing this abomination instead. :)

I would rather just use a function than goto, You can code everything in a function, set up conditional statements, etc, and go from there, that is what OOP is about.

func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()
Link to comment
Share on other sites

Maybe I'm a noob...

But to respond to the above quote:

Global $hGUI, $nB1, $nB2
$hGUI = GUICreate("My GUI")
$nB1 = GUICtrlCreateButton("B1", 10, 10, 30)
$nB2 = GUICtrlCreateButton("B2", 10, 40, 30)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $nB1
            MsgBox(64, "Info", "B1")
        Case $nB2
            MsgBox(64, "Info", "B2")
    EndSwitch
WEnd
Not sure if you're referring to the "Olddddd" GUIGetMsg()?

ok, tell me how many times per second it has to query the GUI, run through the conditional statements, and then start over....

func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()
Link to comment
Share on other sites

  • Moderators

ok, tell me how many times per second it has to query the GUI, run through the conditional statements, and then start over....

I believe it's 4 per second... Why?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Event mode is better than GuiGetMsg mode (which is nothing but waste of CPU power, even if your app is a "Hello world" with 2 buttons, not even talking about bigger GUIs), but it requires some extra typing to set up. Which, depending on one's coding habits (such as, not having a template script to build on, or simply not wanting to obscure the example with bunch of unrelated code), may be too boring/unwanted to do when writing some short example of something that is often unrelated to actual GUI work at all (and which is just that - an example, not the final version of an app). I do that all the time. But I'd never even consider using GuiGetMsg mode in my apps.

I guess newbies use GuiGetMsg mode because they see all examples using it, and, being newbs, just don't know better.

Seriously, don't worry, you are on the right path. Forget about GuiGetMsg(). I wish the "Goto is bad" sayers around here would focus on killing this abomination instead. :)

Actually my personal preference is just the opposite of yours and I'm a long way from being a newbie. Although I have used Event Functions I don't really like them and in one of my scripts in particular my message loop monitors many things besides Control events and that script currently contains 582 controls. Do I want to start writing functions for those given the fact that you can't pass parameters to GUIOnEvent functions? Probably not. This concept of eliminating the GUIMsg loop might even cause a parting of the ways between AutoIt and I.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Moderators

Actually my personal preference is just the opposite of yours and I'm a long way from being a newbie. Although I have used Event Functions I don't really like them and in one of my scripts in particular my message loop monitors many things besides Control events and that script currently contains 582 controls. Do I want to start writing functions for those given the fact that you can't pass parameters to GUIOnEvent functions? Probably not. This concept of eliminating the GUIMsg loop might even cause a parting of the ways between AutoIt and I.

To be fair here, I use an OnEvent type with other languages I use.

But, seeing as (from memory of course... might be wrong until validated or discredited by a Dev) they both have a 250 ms delay, I don't see what it matters what type you use in AutoIt. I think it's just a personal perference here.

I've used both in the past, and to me... Out of habit I just perfer GUIGetMsg() in AutoIt for the majority of things.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Actually my personal preference is just the opposite of yours and I'm a long way from being a newbie. Although I have used Event Functions I don't really like them and in one of my scripts in particular my message loop monitors many things besides Control events and that script currently contains 582 controls. Do I want to start writing functions for those given the fact that you can't pass parameters to GUIOnEvent functions? Probably not. This concept of eliminating the GUIMsg loop might even cause a parting of the ways between AutoIt and I.

See the fact i can't pass parameters to these functions really bothers me, as well as a few other things i was thinking of using to pass functions. I started in a language that isn't far off from C, then moved into C and am learning that, my next leap is C++ and C#, not being able to pass paramaters really gets at me in lots of things, and i wish there was more functionality, but i also realize that this isn't made for people that know C, C++, and C# cause that would be kind of pointless. I will admit im a newb, and as far as I know, when you use inputbox() it uses GUIGetMsg() but is just coded in directly.

func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()
Link to comment
Share on other sites

To be fair here, I use an OnEvent type with other languages I use.

But, seeing as (from memory of course... might be wrong until validated or discredited by a Dev) they both have a 250 ms delay, I don't see what it matters what type you use in AutoIt. I think it's just a personal perference here.

I've used both in the past, and to me... Out of habit I just perfer GUIGetMsg() in AutoIt for the majority of things.

I agree, it is strictly a matter of personal prefence. I also think that the amount of code being used can be a determining factor. I've never seen a performance hit between one method or the other. People tend to think of something in the neighborhood of .5% difference in processor usage as being a performance hit and they do the same with speed testing. They think that shaving a few micro-seconds off a function is a bonus. It is, IF you are shaving that .5 micro-seconds enough times but in the real world that seldom happens. Lets' face it, we are not using AutoIt to calculate a balance sheet for the world economy so extremely minor differences generally have little impact on the end user. And using

Do
   Sleep(250)
Until Whatever
has the same impact as putting a Sleep(250) in a message loop so you gained nothing there.

Edit: I have to correct my figures from my first post and this is as good a place as any. There are actually 619 controls (+ up to over 1000 created dynamically) and 126 existing functions in the script I referred to in that post.

My Msg loop starts on Line 530 and runs for 495 lines. My Outer Switch statement doesn't start until line 648 ("Outer" because it also contains nested Switch and Select statements). That means that I have 118 lines of code continually doing things besides reading and reacting to GUI events.

The changes required to modify that script to GUI Event code would be a horror show and I don't do nightmares very well.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Valik had the suggestion of parameters a long time ago... I would still like to have it implemented.

Edit: However, the ticked that Valik's links to in his last post is empty so maybe it didn't work.

I've been following that and if it ever happens then it will have an impact on my thinking. Until then I'll stay with my preference.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I would rather just use a function than goto, You can code everything in a function, set up conditional statements, etc, and go from there, that is what OOP is about.

How did GoTo get into this? AutoIt doesn't support it anyway. I can also call a function from a message loop. Just exactly the way that Smoke outlined above and when I call it from a message loop I can pass parameters to it. That generally means that I can re-use functions rather than creating a new one for each function.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

See the fact i can't pass parameters to these functions really bothers me, as well as a few other things i was thinking of using to pass functions. I started in a language that isn't far off from C, then moved into C and am learning that, my next leap is C++ and C#, not being able to pass paramaters really gets at me in lots of things, and i wish there was more functionality, but i also realize that this isn't made for people that know C, C++, and C# cause that would be kind of pointless. I will admit im a newb, and as far as I know, when you use inputbox() it uses GUIGetMsg() but is just coded in directly.

This is an example of what has happened to AutoIt over the years. I discovered AutoIt when I was looking for a simple scripting engine that would allow me to replace VBS and batch files. AutoIt v2 fit the bill perfectly. Then Larry came along with a 3rd party add-on that gave us a GUI, not a complex GUI but a GUI none the less. I started adding that into my scripts and then when AutoIt 3 came out (don't remember for sure if the first version of AutoIt3 had GUI or not) and it had the GUI I thought it was great, even though we had to learn AutoIt all over again. Then the GUI became more complex and had much more functionality. Then people started asking for more and more feature up to the point where AutoIt was no longer a simple scripting engine. I can't decide if that was a good thing or not but the fact remains that during the process we lost a nice and very small scripting engine. What people expect now is more in the area of the traditional languages like C (any flavor) and Delphi and that was never the origional intent of AutoIt. I know for a fact tat Jon has had many occasions to reflect on whether or not he should ever have started making all of these changes. I appreciate almost all that the devs have added to AutoIt but I often think that I should just be writing my code in Delphi again (recently had to) and use the simple scripting functions of AutoIt for simple scripting.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

This is an example of what has happened to AutoIt over the years. I discovered AutoIt when I was looking for a simple scripting engine that would allow me to replace VBS and batch files. AutoIt v2 fit the bill perfectly [...]

Well, AutoIt allows for very advanced integration between self-made GUIs and the rest of the windowing system in a -very- easy manner; this is something that no other language can currently offer (Delphi or others) and as such I for one REALLY appreciate that AutoIt has developed into a full fledged language while maintaining its superb scripting capacity! I'm confident that because AutoIt allows for such fast development my programs are more stable and further matured than would have been the case if I had used a language that forced me into a more low-level approach.

Best/Sunaj

Link to comment
Share on other sites

Well, AutoIt allows for very advanced integration between self-made GUIs and the rest of the windowing system in a -very- easy manner; this is something that no other language can currently offer (Delphi or others) and as such I for one REALLY appreciate that AutoIt has developed into a full fledged language while maintaining its superb scripting capacity! I'm confident that because AutoIt allows for such fast development my programs are more stable and further matured than would have been the case if I had used a language that forced me into a more low-level approach.

Best/Sunaj

Don't get me wrong. I still love AutoIt even though I may have reservations about some of the functions. Other people have reservations about different functions and even the Devs each have some reservations. There are so many people involved that you will seldom see complete agreement. And with my reference to using Delphi recently, I was refering to the fact that a client insisted on something that can not be done in AutoIt so I had to switch back. BYW, after working with AutoIt for so long, I can assure you it was not a smooth transition and they are still reporting minor bugs.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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