Sign in to follow this  
Followers 0
sunlord

Quick question

12 posts in this topic

Anything wrong with this code?

;Rest of the code omitted
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem2 = GUICtrlCreateMenuItem("Settings", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem4 = GUICtrlCreateMenu("&About")
GUICtrlSetState($From, $GUI_FOCUS)
Guisetonevent($GUI_EVENT_CLOSE, "Exit2")



GuiSetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
        Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MenuItem3
            RunSmtp()
            
        
    EndSwitch
    
    
        
WEnd

My menu doesn't work. If I click "Settings" under "File" its supposed to run the RunSmtp() function but nothing happens?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Did this help? I aligned the Switch with the EndSwitch

;Rest of the code omitted
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem2 = GUICtrlCreateMenuItem("Settings", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem4 = GUICtrlCreateMenu("&About")
GUICtrlSetState($From, $GUI_FOCUS)
Guisetonevent($GUI_EVENT_CLOSE, "Exit2")



GuiSetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MenuItem3
            RunSmtp()
    EndSwitch
WEnd
Edited by BALA

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites

Nope......Same problem.

Share this post


Link to post
Share on other sites

Are you using GUISetOnEvent on the part of the script that we cant see. If so then GUIGetMsg and Switch will not work.



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

I have these bits in the code. Do you mean one of them?

Opt("GUIOnEventMode", 1)

GUICtrlSetOnEvent($Send, "RunSmtp")

and

Guisetonevent($GUI_EVENT_CLOSE, "Exit2")

Share this post


Link to post
Share on other sites

Like BigDod said... "Are you using GUISetOnEvent on the part of the script that we cant see. If so then GUIGetMsg and Switch will not work."

You don't mix GUISetOnEvent and GuiGetMsg.

Share this post


Link to post
Share on other sites

So are you saying I'm not supposed to have this bit in the code?

Guisetonevent($GUI_EVENT_CLOSE, "Exit2")

Just that bit or anything more?

Share this post


Link to post
Share on other sites

When you have GUIOnEventMode set to 1 (on), you can't use GuiGetMsg(). It always returns 0. Instead, you can create functions with GuiSetOnEvent($control, 'function').

You have to choose to either use GuiGetMsg() method for gui events, or GuiSetOnEvent(). Which you use depends on whether you have GuiOnEventMode on or off.

Share this post


Link to post
Share on other sites

Ahhhh ok. Yeah I see what you mean. That works. Thanks.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

something that seems to have been overlooked: $MenuItem3 is the item "Exit", as per your code. You need to check if the $nMsg=$MenuItem2 ("Settings") to do anything with that menu item when it is clicked!

$MenuItem2 = GUICtrlCreateMenuItem("Settings", $MenuItem1)

$MenuItem3 = GUICtrlCreateMenuItem("Exit", $MenuItem1)

Case $MenuItem3

RunSmtp()

Edited by improbability_paradox

Share this post


Link to post
Share on other sites

I know , I was just testing if it actually works so I was just testing it with random functions in my script.

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
Sign in to follow this  
Followers 0