Sign in to follow this  
Followers 0
falconv

For Next Statement For $msg = ?

3 posts in this topic

So I'm trying to make a top-bar, sorta like a menu-bar form of a start-menu. So I'm using menus to allow myself to launch programs. I've worked it so it dynamically loads the menus from an .ini file to make it easy for any user to add or remove menus and entries and control what they do. So far everything's working great as far as creating the menu, but I can't figure out how to get it to recognize the $msg commands. I figured use a For Next statement just like I used when creating the GUI, but that seems to constatnly be recognized instead of just when the menus are being pressed.

Here's what I have so-far:

#include <GUIConstants.au3>

$configini = "C:\temp\panel.ini"
$MenuCount = IniReadSectionNames($configini)
Dim $Menu[$MenuCount[0]+1]
GUICreate("",@DesktopWidth+4,17,-2,-22)
GUISetState(@SW_SHOW)

For $n = 1 to $MenuCount[0] Step 1
    $Menu[$n] = GUICtrlCreateMenu($MenuCount[$n])
    $MenuSubCount = IniReadSection($configini,$MenuCount[$n])
    Dim $MenuSub[$MenuCount[0]+1][$MenuSubCount[0][0]+1]
    For $s = 1 to $MenuSubCount[0][0] Step 1
        $MenuSub[$n][$s] = GUICtrlCreateMenuitem($MenuSubCount[$s][0],$Menu[$n])
    Next
Next

While 1
    $msg = GUIGetMsg()
;   For $n = 1 to $MenuCount[0] Step 1  ;I tried using these, but it would just loop a blank msgbox (often two) and this is where the problem lies it seems.
;       For $s = 1 to $MenuSubCount[0][0] Step 1
;           If $msg = $MenuSub[$n][$s] Then
;               $Output = IniRead($configini,$Menu[$n],$MenuSub[$s][1],"")
;               MsgBox(0,"Test",$Output)
;           Else
;           EndIf
;       Next
;   Next
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

panel.ini

[Morgan]
Email = "c:\Program Files\Microsoft Office\Outlook\Outlook.exe"
Internet = "c:\Program Files\Internet Explorer\iexplore.exe"
[Eric]
Email = "c:\Program Files\Microsoft Office\Outlook\Outlook.exe"
Firefox = "c:\Program Files\Mozilla\Firefox.exe"
[Games]
Halo = "C:\Program Files\Microsoft Games\Halo\Halo.exe"

I'm thinking maybe replace the for/next to say 'If $msg <> 0 Then _DoSomething($msg)'?

Or would I have the same problem?

Share this post


Link to post
Share on other sites



I'm sure someone can come up with something better, but being no-one has helped yet here you go:

#include <GUIConstants.au3>

$configini = @ScriptDir & "\panel.ini"
$MenuCount = IniReadSectionNames($configini)
Dim $Menu[$MenuCount[0] + 1][2]
Dim $SubMenus[1][2]
GUICreate("", @DesktopWidth + 4, 17, -2, -22)
GUISetState(@SW_SHOW)

For $n = 1 To $MenuCount[0]
    $Menu[$n][0] = GUICtrlCreateMenu($MenuCount[$n])
    $MenuSubCount = IniReadSection($configini, $MenuCount[$n])
    If UBound($Menu, 2) < $MenuSubCount[0][0] + 1 Then
        ReDim $Menu[$MenuCount[0] + 1][$MenuSubCount[0][0] + 1]
    Else
        For $s = 1 To UBound($Menu, 2) - 1
            $Menu[$n][$s] = -999
        Next
    EndIf
    For $s = 1 To $MenuSubCount[0][0]
        $Menu[$n][$s] = GUICtrlCreateMenuitem($MenuSubCount[$s][0], $Menu[$n][0])
        If Number($SubMenus[0][0]) <> 0 Then
            ReDim $SubMenus[UBound($SubMenus) + 1][2]
        EndIf
        $SubMenus[UBound($SubMenus) - 1][0] = $Menu[$n][$s]
        $SubMenus[UBound($SubMenus) - 1][1] = $MenuSubCount[$s][0]
    Next
Next

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
            For $n = 1 To UBound($Menu) - 1
                For $s = 1 To UBound($Menu, 2) - 1
                    If $msg = $Menu[$n][$s] Then
                        For $x = 0 To UBound($SubMenus) - 1
                            If $SubMenus[$x][0] = $Menu[$n][$s] Then
                                $Output = IniRead($configini, $MenuCount[$n], $SubMenus[$x][1], "")
                                MsgBox(0, "Test", $Output)
                                ExitLoop 3
                            EndIf
                        Next
                    EndIf
                Next
            Next
    EndSelect
WEnd

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Wow, that works really well! Thanks a lot!

So where was I going wrong? Or are there too many things to list? lol

I made a couple small changes, so I'll attach the new version. I just took it off the taskbar, and replaced the messagebox with a run statement (the messagebox was, obviously, just for testing). I'm also trying to figure out, and if anyone knows off the top of their heads how to do this feel free to clue me in, how to make it act like the taskbar, where it won't let anything underneath it. I can make it always on top (I think I'll try that now actually), but that just puts windows under it, but that's not quite what I'm shooting for.

Here's my slightly updated version (and I left the spaces since I'm sure most people appreciate them, I forgot to do that to my script earlier)

#include <GUIConstants.au3>

$configini = @ScriptDir & "\panel.ini"
$MenuCount = IniReadSectionNames($configini)
Dim $Menu[$MenuCount[0] + 1][2]
Dim $SubMenus[1][2]
GUICreate("", @DesktopWidth + 4, 17, -2, -19, -1, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
GUISetState(@SW_SHOW)

For $n = 1 To $MenuCount[0]
    $Menu[$n][0] = GUICtrlCreateMenu($MenuCount[$n])
    $MenuSubCount = IniReadSection($configini, $MenuCount[$n])
    If UBound($Menu, 2) < $MenuSubCount[0][0] + 1 Then
        ReDim $Menu[$MenuCount[0] + 1][$MenuSubCount[0][0] + 1]
    Else
        For $s = 1 To UBound($Menu, 2) - 1
            $Menu[$n][$s] = -999
        Next
    EndIf
    For $s = 1 To $MenuSubCount[0][0]
        $Menu[$n][$s] = GUICtrlCreateMenuitem($MenuSubCount[$s][0], $Menu[$n][0])
        If Number($SubMenus[0][0]) <> 0 Then
            ReDim $SubMenus[UBound($SubMenus) + 1][2]
        EndIf
        $SubMenus[UBound($SubMenus) - 1][0] = $Menu[$n][$s]
        $SubMenus[UBound($SubMenus) - 1][1] = $MenuSubCount[$s][0]
    Next
Next

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
            For $n = 1 To UBound($Menu) - 1
                For $s = 1 To UBound($Menu, 2) - 1
                    If $msg = $Menu[$n][$s] Then
                        For $x = 0 To UBound($SubMenus) - 1
                            If $SubMenus[$x][0] = $Menu[$n][$s] Then
                                Run(IniRead($configini, $MenuCount[$n], $SubMenus[$x][1], ""))
                                ExitLoop 3
                            EndIf
                        Next
                    EndIf
                Next
            Next
    EndSelect
WEnd
Edited by falconv

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