Jump to content

GUI with "File > Edit > View...." Menu


Recommended Posts

I'm curious how to make the common drop down links that most programs have, such as "File > Edit > View> Help" etc...

Also, witht he GUI that I have, the "x" that should close the program (in top right) does not seem to work. How can I make it function.

Link to comment
Share on other sites

#include <GUIConstants.au3>

GUICreate("My GUI menu",300,200)

Global $defaultstatus = "Ready"
Global $status

$filemenu = GUICtrlCreateMenu ("&File")
$fileitem = GUICtrlCreateMenuitem ("Open",$filemenu)
GUICtrlSetState(-1,$GUI_DEFBUTTON)
$helpmenu = GUICtrlCreateMenu ("?")
$saveitem = GUICtrlCreateMenuitem ("Save",$filemenu)
GUICtrlSetState(-1,$GUI_DISABLE)
$infoitem = GUICtrlCreateMenuitem ("Info",$helpmenu)
$exititem = GUICtrlCreateMenuitem ("Exit",$filemenu)
$recentfilesmenu = GUICtrlCreateMenu ("Recent Files",$filemenu,1)

$separator1 = GUICtrlCreateMenuitem ("",$filemenu,2)   ; create a separator line

$viewmenu = GUICtrlCreateMenu("View",-1,1) ; is created before "?" menu
$viewstatusitem = GUICtrlCreateMenuitem ("Statusbar",$viewmenu)
GUICtrlSetState(-1,$GUI_CHECKED)
$okbutton = GUICtrlCreateButton ("OK",50,130,70,20)
GUICtrlSetState(-1,$GUI_FOCUS)
$cancelbutton = GUICtrlCreateButton ("Cancel",180,130,70,20)

$statuslabel = GUICtrlCreateLabel ($defaultstatus,0,165,300,16,BitOr($SS_SIMPLE,$SS_SUNKEN))

GUISetState ()
While 1
    $msg = GUIGetMsg()
    
    If $msg = $fileitem Then
        $file = FileOpenDialog("Choose file...",@TempDir,"All (*.*)")
        If @error <> 1 Then GUICtrlCreateMenuitem ($file,$recentfilesmenu)
    EndIf 
    If $msg = $viewstatusitem Then
        If BitAnd(GUICtrlRead($viewstatusitem),$GUI_CHECKED) = $GUI_CHECKED Then
            GUICtrlSetState($viewstatusitem,$GUI_UNCHECKED)
            GUICtrlSetState($statuslabel,$GUI_HIDE)
        Else
            GUICtrlSetState($viewstatusitem,$GUI_CHECKED)
            GUICtrlSetState($statuslabel,$GUI_SHOW)
        EndIf
    EndIf
    If $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton Or $msg = $exititem Then ExitLoop
    If $msg = $infoitem Then Msgbox(0,"Info","Only a test...")
WEnd
GUIDelete()

Exit

I think you need one of the latest BETA's.

qq

Link to comment
Share on other sites

I have whatever the latest AutoIt version is.... just got few days ago... I have the following:

#include <GUIConstants.au3>

GUICreate("test gui", 180, 150)
GUISetState ()

$menuFile = GUICtrlCreateMenu ("&File")
$menuAbout = GUICtrlCreateMenu ("&About")
$itemExit = GUICtrlCreateMenuitem ("E&xit",$menuFile)
$itemAbout = GUICtrlCreateMenuitem ("About Us",$menuAbout)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $itemExit Then ExitLoop
Wend
GUIDelete()
Exit

However, the exit button doesn't seem to work... this still goes for the "X" button in the top right as well.

Edited by joncom
Link to comment
Share on other sites

Works fine here. Exactly what autoit version do you have?

[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Link to comment
Share on other sites

I'm using 3.1.1.0... hmmm it seems that other script that I didnt' bother mentioning is screwing it up.

While $complete = 0
  $pixelMiss = 0
  $pixelFound = 0
  If $detectLast = "Left" Then
    detectLeft()
    If $pixelFound = 0 Then
      detectRight()
    EndIf
  ElseIf $detectLast = "Right" Then
    detectRight()
    If $pixelFound = 0 Then
      detectLeft()
    EndIf
  ElseIf $detectLast = "" Then
    detectLeft()
    If $pixelFound = 0 Then
      detectRight()
    EndIf
  EndIf
 ; Detection for NONE
  If $pixelMiss > 1 Then
    GUICtrlSetData($positionDetected,"...")
    GUICtrlSetData($currentAction,"...")
    $detectLast = ""
    Sleep(50)
  EndIf
WEnd

If I have $complete set to "0".... then the exit features do not work.... can the script not exit while performing a loop? How can I change it to work even while this is running.

Edited by joncom
Link to comment
Share on other sites

if your using both of your posted scripts in one script, then when $complete = 0 then its going into another loop where its not polling 4 events.. so add this to the last thing you posted..

$get = GUIGetMsg()
If $get = -3 then exit

then it will poll 4 events :)

FootbaG
Link to comment
Share on other sites

Can you please tell me why a -3 is used... if I can understand that, maybe I will be able to do it myself in the future when I have more code in the file as well.

<{POST_SNAPBACK}>

-3 is the value that AutoIt arbitrarily uses to represent the window closing event.

It's much better to put #include <GUIConstants.au3> at the beginning of your script

and use the variable $GUI_EVENT_CLOSE

(just in case the AutoIt developer would decide to change -3 to another value)

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Still doesn't work.. I'm guessing because while my program is running... unless I disable the point of the whole script, it never even makes it to the lines

$get = GUIGetMsg()

If $get = -3 then exit

This is because its stuck in a loop above these lines of code.

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