Sign in to follow this  
Followers 0
MattX

Can't get GUI box to close

7 posts in this topic

What am I missing here ?

The hotkey works fine - it brings up the GUI box with both buttons but I want to be able to close the box as well but still have the main script running. The GUI box is inside the showmessage() func. I would apprecite some help or guidence.

#Include <Constants.au3>
#include <ScreenCapture.au3>
#include <IE.au3>

Dim $portalsite = "http://stjohns02:9675/helpdesk"
Dim $helpdesk_screenshots = "c:\helpdesk_screenshots"


Opt("TrayMenuMode",1)   
HotKeySet("+!h", "ShowMessage")  ;Shift-Alt-h

If FileExists("c:\helpdesk_screenshots") Then
    FileDelete("c:\helpdesk_screenshots\*.jpg")
Else
    DirCreate("c:\helpdesk_screenshots")
EndIf

Func ShowMessage()
    
$Form1 = GUICreate("Portal Launcher", 220, 110, 348, 309)
$helpmenu = GUICtrlCreateMenu("Help")
$infoitem = GUICtrlCreateMenuitem("About", $helpmenu)
GUISetBkColor(0x0066FF)
$Button1 = GUICtrlCreateButton("Screen Shot", 10, 20, 89, 49 )
$Button2 = GUICtrlCreateButton("To Portal", 120, 20, 89, 49 )
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $Button1
            _ScreenCapture_Capture($helpdesk_screenshots & "\helpdesk_Image1.jpg")
            sleep(2000)
            _IECreate($portalsite)
        Case $nMsg = $Button2
            _IECreate($portalsite)
        Case $nMsg = $infoitem
            MsgBox(0, "Portal Launcher 1B", "Written By Matt." & @CRLF & "Comments & Suggestions to:" & @CRLF & "matt")
        
EndSelect
WEnd
 
EndFunc

$settingsitem   = TrayCreateMenu("Settings")
$displayitem    = TrayCreateItem("Screen Shot", $settingsitem)
$portal         = TrayCreateItem("Portal", $settingsitem)
TrayCreateItem("")
$aboutitem      = TrayCreateItem("About")
TrayCreateItem("")
$exititem       = TrayCreateItem("Exit")

TraySetState()

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        case $msg = $displayitem
            _ScreenCapture_Capture($helpdesk_screenshots & "\helpdesk_Image1.jpg")
            sleep(2000)
            _IECreate($portalsite)
        case $msg = $portal
            _IECreate($portalsite)
        Case $msg = $aboutitem
            MsgBox(0, "Portal Launcher 1B", "Written By Matt." & @CRLF & "Comments & Suggestions to:" & @CRLF & "matt")
                ; Remember to comment out $exititem so prog can't be closed or keep it in if you want users to close !!
        Case $msg = $exititem
            ExitLoop
    EndSelect
WEnd

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Insert

#include <GUIConstants.au3>
at the beginning of your script and change your GUI-loop to:

While 1
 $nMsg = GUIGetMsg()
 Select
    Case $nMsg = $Button1
    _ScreenCapture_Capture($helpdesk_screenshots & "\helpdesk_Image1.jpg")
    sleep(2000)
    _IECreate($portalsite)
    Case $nMsg = $Button2
    _IECreate($portalsite)
    Case $nMsg = $infoitem
    MsgBox(0, "Portal Launcher 1B", "Written By Matt." & @CRLF & "Comments & Suggestions to:" & @CRLF & "matt")
    Case $nMsg = $GUI_EVENT_CLOSE
    GUIDelete($Form1)
 EndSelect
WEnd

And shouldn't you change line

Case $msg = $exititem
    ExitLoop
to
Case $msg = $exititem
    Exit
so that the script really exits? Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks - working great now. Trust me to forget the GUIConstants. [ That will teach me for re-using code from another one of my old scripts !! ]

Insert

#include <GUIConstants.au3>
at the beginning of your script and change your GUI-loop to:

While 1
 $nMsg = GUIGetMsg()
 Select
    Case $nMsg = $Button1
    _ScreenCapture_Capture($helpdesk_screenshots & "\helpdesk_Image1.jpg")
    sleep(2000)
    _IECreate($portalsite)
    Case $nMsg = $Button2
    _IECreate($portalsite)
    Case $nMsg = $infoitem
    MsgBox(0, "Portal Launcher 1B", "Written By Matt." & @CRLF & "Comments & Suggestions to:" & @CRLF & "matt")
    Case $nMsg = $GUI_EVENT_CLOSE
    GUIDelete($Form1)
 EndSelect
WEnd

And shouldn't you change line

Case $msg = $exititem
    ExitLoop
to
Case $msg = $exititem
    Exit
so that the script really exits?

Share this post


Link to post
Share on other sites

One more quick question, after the hotkey has been used, how come the options in the system tray no longer work ? [ even after closing the GUI box ? ]

Share this post


Link to post
Share on other sites

My fault :)

Please insert a "Return" so that the script leaves the SHowMessage function:

Case $nMsg = $GUI_EVENT_CLOSE
 GUIDelete($Form1)
 Return ; <== Was missing

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

My fault :)

Please insert a "Return" so that the script leaves the SHowMessage function:

Case $nMsg = $GUI_EVENT_CLOSE
 GUIDelete($Form1)
 Return ; <== Was missing

Your fault !!?? You have helped me out !! Thanks.

Share this post


Link to post
Share on other sites

Your fault !!??

Yes, my fault, because I've written the the part of code where the script went into an infinite loop Posted Image

But on the other hand i wished that all mistakes I make are as easily to locate and repair :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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