Jump to content

[Solved] MessageLoop GUI and Tray polling problems


dany
 Share

Recommended Posts

Well, I finally got my laptop back after, well waaaay too long. Shopkeeper ordered the wrong network card.Twice. Anyhow, I'm back on the net and happy happy joy joy.

And I'll jump right in with a question about MessageLoop mode. Up until now I've only used OnEvent mode but for a recent project I needed the MessageLoop mode (bc multifile drag and drop support).

In my _Main() function I poll both GUIGetMsg() and TrayGetMsg() but the program just becomes unresponsive. No events are triggered. Below is a summary of the actual code, the script would be really long to post here and about uploading it, I could do that if need be. Or write a simpler proof of concept. But for now I can add it just creates the GUI and tray menu and uses event functions with only a Return 1 statement. So basically nothing is happening anyway, but the MsgBoxes I put in as checks just don't show up either or only occasionally and after a really 'long' time (+5 seconds or longer). I can only close the program through the taskbar context menu.

I just want to know if it's common practise to write scripts like this and if so, what could be the reason it's not working? Am I stupidly missing something, I looked at the online manual and examples like a hundred times so I might be temporarily codeblind now... Or is it just better to combine GUI MessageLoops with Tray OnEvents? Personally I'd like to stick with one method, that's cleaner code imho...

AutoItSetOption('GUIOnEventMode', 0) ; Use GUIGetMsg()
AutoItSetOption('TrayOnEventMode', 0) ; Use TrayGetMsg()

Func _Main()
    Local $iTrayMsg, $iGUIMsg
    ; Function that creates the tray menu.
    ; Function that creates the GUI.
    While 1
        $iTrayMsg = GUIGetMsg()
        $iGUIMsg = GUIGetMsg()
        Switch $iTrayMsg
            Case 1
                MsgBox(0, 'Tray event', 'Tray event fired') ; Doesn't show.
                _Event_TraySomething() ; Function returns 1, nothing more, but doesn't get called.
            Case $GUI_EVENT_CLOSE ; Exit
                ExitLoop
        EndSwitch
        Switch $iGUIMsg
            Case 1
                MsgBox(0, 'GUI event', 'GUI event triggered') ; Doesn't show.
                _Event_GUISomething() ; Function returns 1, nothing more, but doesn't get called.
            Case $GUI_EVENT_CLOSE ; Exit
                ExitLoop
        EndSwitch
    WEnd
    Exit
EndFunc

Any clarification would be much appreciated.

Edited by dany

[center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF

Link to comment
Share on other sites

  • Moderators

dany,

Or is it just better to combine GUI MessageLoops with Tray OnEvents?

That is exactly what I do. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Yea, I already tried that and it simply works like a charm. Thanks for the reply, I've already implemented it as I have to get this show on the road as it were.

But it just doesn't feel right, as a programmer, albeit amateur, I can't let it go that easily. I mean, it's the default setting for AutoIt so in some way the above code must work, right? What also bugs me is this feeling that I'm missing something embarrassingly obvious. Maybe it's just me but it's becoming a game of hackers honour. The code shall do as I will.

Off topic: Wow, I've been lurking here for more than 6 months now and this is my first post? Really? I could've sworn I had some previous topics, must have been on some other forum. Well, just shows how helpful the search results are here!

[center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF

Link to comment
Share on other sites

Sorry for doubleposting, I can't edit my previous post.

But to clarify. In the first iteration of the loop $iTrayMsg is set to -3, the value of $GUI_EVENT_CLOSE. It's always -3 after program start! :wacko:

[center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF

Link to comment
Share on other sites

  • Moderators

dany,

You cannot edit until you have 5 posts - then a new button appears at bottom right. :)

I will look at your code tomorrow. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks, that's much appreciated. But I've had my own moment of clarity. $GUI_EVENT_CLOSE isn't a Tray message, so it's illogical to check for it inside the TrayMessage loop:

While 1
    $iTrayMsg = TrayGetMsg()
    $iGUIMsg = GUIGetMsg()
    Switch $iTrayMsg
        Case $cTrayTest
            MsgBox(0, 'Tray', 'Tray test event ' & $iTrayMsg)
        ;Case $cTrayExit, $GUI_EVENT_CLOSE ; <<<<<<<< wrong!
        Case $cTrayExit
            MsgBox(0, 'Tray', 'Tray exit event ' & $iTrayMsg)
            ExitLoop
    EndSwitch
    Switch $iGUIMsg
        Case $cGUITest
            MsgBox(0, 'GUI', 'GUI test event ' & $iGUIMsg)
        Case $cGUIExit, $GUI_EVENT_CLOSE ; No problems here.
            MsgBox(0, 'GUI', 'GUI exit event ' & $iGUIMsg)
            ExitLoop
    EndSwitch
WEnd

Like I said, embarrassingly obvious :whistle:

You cannot edit until you have 5 posts - then a new button appears at bottom right.

Thanks btw for clearing that up, I couldn't find that in the FAQ.

EDIT: four posts!

Edited by dany

[center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF

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