Jump to content
Sign in to follow this  
yoinkster

Simple Menu

Recommended Posts

yoinkster

Hey guys,

I'm totally new to AutoIt but I think it's going to be what I'm looking for, I guess I'll be here asking many more lame questions this week!

Anyway, just for now, all I'm trying to do is adapt the SampleControls.au3 script that comes with the latest version and I basically want to add some children options to the main menu items.

I have as my code at the mo ::

#include <GuiConstantsEx.au3>
#include <AVIConstants.au3>
#include <TreeViewConstants.au3>
#Include <Array.au3>

Local $menu, $fileexit, $fileopen, $msg, $chosen, $files, $path, $wholething, $realpath, $i

; GUI
GuiCreate("My test toy", 400, 400)
GuiSetIcon(@SystemDir & "\mspaint.exe", 0)


; MENU
$menu = GuiCtrlCreateMenu("&File")
$fileopen = GUICtrlCreateMenuItem("Open ...", $menu)
$fileexit = GuiCtrlCreateMenuItem("E&xit", $menu)

GuiSetState()
While GuiGetMsg() <> $GUI_EVENT_CLOSE
    $msg = GuiGetMsg()
    If $msg = $fileopen then
        $chosen = FileOpenDialog("Choose file...", "q:\TOCs", "(*.TOC)", 1+2+4)
        If @error Then
            MsgBox(4096, "Whoops", "No files chosen")
        Else 
            $path = StringSplit($chosen, "|")
            $realpath = $path[1]
            $i = 1
            while $i < UBound($path) - 1
                $wholething = $realpath & "\"  & $path[$i + 1]
                MsgBox(4096, "You win!", "You chose " & $wholething)
                $i = $i + 1
            WEnd
        EndIf
    EndIf
    
    if $msg = $fileexit then ExitLoop
WEnd

The open box works fine and at the mo, I'm just playing with the selection so I'm not worried about how I'm handling selections as I'm sure that'll all change/be removed.

Anyway, my problem is that sometimes the Exit option works and sometimes it doesn't and like, if I select two TOC files, I then have to push the Exit option three times for it to actually exit, like there is something still hanging around from making the selection. Also, the normal red X close button in XP doesn't work either and has the same issues as the Exit option, you sometimes have to push it three or four times for it to take it. Sometimes even more randomly, I have to click on Open two or three times, you click it and it does nothing then for some reason it then goes ahead and brings up the file open dialog. Not making much sense to me at all!

Is my loop structure fundamentally wrong or ... ?

Share this post


Link to post
Share on other sites
Zedna

Try this:

While 1
    $msg = GuiGetMsg()
 If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    if $msg = $fileexit then ExitLoop
 
    If $msg = $fileopen then
        $chosen = FileOpenDialog("Choose file...", "q:\TOCs", "(*.TOC)", 1+2+4)
        If @error Then
            MsgBox(4096, "Whoops", "No files chosen")
        Else 
            $path = StringSplit($chosen, "|")
            $realpath = $path[1]
            $i = 1
            while $i < UBound($path) - 1
                $wholething = $realpath & "\"  & $path[$i + 1]
                MsgBox(4096, "You win!", "You chose " & $wholething)
                $i = $i + 1
            WEnd
        EndIf
    EndIf
WEnd

Share this post


Link to post
Share on other sites
yoinkster

that's the badger thank you very much.

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  

×