Sign in to follow this  
Followers 0
xwinterx

Dynamic Menu Bar (0.7 beta!) (10-26-07)

6 posts in this topic

#1 ·  Posted (edited)

I use a method similar to XSkin to skin my GUI's, the only problem I come up with is that I can't use standard menus with my GUI's as the menu bar appears "above" my window. So I have started working on this little project and maybe some of the more experienced Autoit folks can help me out a bit.

Dynamic Menus!

These will simulate menus. I just started this to get the feel of it to see if what I want to do is possible. It appears it is but I need to develop this more but in the mean time here is what I have so far. There is a performance issue that I must resolve!

To Do:

- Simulated Menu mouseover highlights

(thanks to some mouseover stuff from the forums, I will give credit as soon as I find it or if someone can let me know. Great stuff!)

- Simulated child menus when parent menus are clicked.

- Simulated child menu mouseover highlights.

- Simulated child menu separators.

- Open/Close child menus respectively when mouseovering through the parents after a parent has been clicked.

- Option for "decorating" the menubar with a lower etched edge.

- Allow menubar to be anchored to any Autoit GUI handle.

- Allow user to set colors for menubar, active/inactive colors for parent/child menus.

- Close all menus when mouse clicked outside of menus and menubar.

- Increase speed performance

- Script not reacting to child menu clicks until mouse is moved out of menu region.

- A whole lot more I am sure!

Now, there are some things that must be done a certain way, and unfortunately at this time, I am running with these until I can find a better way of doing things.

1. You must create a "blank" parent gui BEFORE creating a menu bar.

2. You must create a Dynamic Menubar BEFORE creating Dynamic Parent Menus.

3. You must create ALL Dynamic Parent Menus BEFORE creating Dynamic Child Menus.

4. You must create ALL Dynamic Child BEFORE creating the "master" child window.

5. You must create a "master" child window in which your normal controls (buttons, etc...) will go.

6. You must have the calling function in your guimsg loop. See example!

HERE ARE MAIN UDFs

; Sets Active/Inactive Hover Colors for Dynamic Menu parents
Func SetDynamicMenuColors($__active, $__inactive)
    $MenuActiveColor = $__active
    $MenuInactiveColor = $__inactive
EndFunc

; Sets Active/Inactive Hover Colors for Dynamic Menu Items
Func SetDynamicMenuItemColors($__active, $__inactive)
    $MenuItemActiveColor = $__active
    $MenuItemInactiveColor = $__inactive
EndFunc

; Sets Active/Inactive Text Colors for Dynamic Menu Items
Func SetDynamicMenuItemTextColor($__active, $__inactive)
    $MenuColorTextDefault = $__active
    $MenuColorTextHighlight = $__inactive
EndFunc

; Turns the menus on. enter tim in milliseconds.
Func EnableMenuHover($__time)
    AdlibEnable("MenuHoverOn", $__time)
EndFunc

; Turns the menus off.
Func DisableMenuHover()
    AdlibDisable()
EndFunc

; ===============================================================================================
; Function:     CreateDynamicMenuBar($DMB_x, $DMB_y, $DMB_width, $DMB_height, $DMB_Opt, $DBM_hWin)
;
; Description:  Creates a "dummy" menubar for the appearance of a full-width menu bar
;
; Requirements: - Must be created prior to creating Dynamic Menus
;
; Parameters:   $DMB_x          - X Coordinate for Creation
;               $DMB_y          - Y Coordinate for Creation
;               $DMB_width      - Menu bar width
;               $DMB_height     - Menu bar height
;               $DM_Opt         - Option for adding an etched bottom border
;                                   0 = no etched bottom border
;                                   1 = etched bottom border
;                                   2 = etched top border
;                                   3 = etched top and bottom border
;               $DBM_hWin       - Window handle of the main window GUI
;
; Usage:        $Menu_File = GuiCtrlCreateDynamicMenu("File", 10, 30, 40, 15, 200, 100, $My_GUI)
; ===============================================================================================
Func CreateDynamicMenuBar($DMB_x, $DMB_y, $DMB_width, $DMB_height, $DMB_Opt, $DBM_hWin)
    
    If $DMB_Opt = 0 Then
        $___hWIN = GUICreate("", $DMB_width, $DMB_height, $DMB_x, $DMB_y, BitOR($WS_CHILD, $WS_TABSTOP), $WS_EX_TOOLWINDOW, $DBM_hWin)
        GUISetBkColor($MenuInactiveColor)
        GUISetState(@SW_ENABLE,$___hWIN)
        GUISetState(@SW_SHOW, $___hWIN)
        $___MenuDecoration = 0
    ElseIf $DMB_Opt = 1 Then
        $___hWIN = GUICreate("", $DMB_width, $DMB_height + 2, $DMB_x, $DMB_y, BitOR($WS_CHILD, $WS_TABSTOP), $WS_EX_TOOLWINDOW, $DBM_hWin)
        GUICtrlCreateLabel("", 0, $DMB_height, $DMB_width, 2, $SS_ETCHEDFRAME)
        GUISetBkColor($MenuInactiveColor)
        GUISetState(@SW_ENABLE,$___hWIN)
        GUISetState(@SW_SHOW, $___hWIN)
        $___MenuDecoration = 1
    EndIf
    
    $___MainGUI = $DBM_hWin
    
EndFunc ;=> CreateDynamicMenuBar($DMB_x, $DMB_y, $DMB_width, $DMB_height, $DMB_Opt, $DBM_hWin)

; ===============================================================================================
; Function:     GuiCtrlCreateDynamicMenu($DM_Label, $DM_x, $DM_y, $DM_width, $DM_height, $DM_gui_width, $DM_gui_height)
;
; Description:  Creates a dynamic parent menu to be placed anywhere on your GUI
;
; Requirements: - Your Parent Window must use the variable  -  $___hWIN
;               - All Dynamic Parent Menus MUST be created prior to creating Dynamic Menuitems
;
; Parameters:   $DM_Label       - Menu Window
;               $DM_x           - X Coordinate for Creation
;               $DM_y           - Y Coordinate for Creation
;               $DM_width       - Menu width, menu label is centered
;               $DM_height      - Menu height, incase you want to make bigger top-level menus
;               $DM_gui_width   - Width of the actual expanded menu
;               $DM_gui_height  - Height of the actual expanded menu
;
; Usage:        $Menu_File = GuiCtrlCreateDynamicMenu("File", 10, 30, 40, 15, 200, 100)
;
;               Case $msg = $Menu_File[0]   <- for checking click on dynamic menu
; ===============================================================================================
Func GuiCtrlCreateDynamicMenu($DM_Label, $DM_x, $DM_y, $DM_width, $DM_height, $DM_gui_width, $DM_gui_height)
    Dim $TempDM[5]
    
    ;$TempDM[0] = GUICtrlCreateLabel($DM_Label, $DM_x, $DM_y, $DM_width, $DM_height, $SS_CENTER)
    $TempDM[0] = GUICtrlCreateLabel($DM_Label, $DM_x, 0, $DM_width, $DM_height, $SS_CENTER)
    GUICtrlSetBkColor(-1,$MenuInactiveColor)
    
    If $___MenuDecoration = 0 Then
        $TempDM[1] = GUICreate($TempDM[0], $DM_gui_width, $DM_gui_height, $DM_x, $DM_y + $DM_height, BitOR($WS_CHILD, $WS_TABSTOP, $WS_DLGFRAME), $WS_EX_TOOLWINDOW, $___MainGUI)
    ElseIf $___MenuDecoration = 1 Then
        $TempDM[1] = GUICreate($TempDM[0], $DM_gui_width, $DM_gui_height, $DM_x, $DM_y + $DM_height + 2, BitOR($WS_CHILD, $WS_TABSTOP, $WS_DLGFRAME), $WS_EX_TOOLWINDOW, $___MainGUI)
    EndIf
    
    MenuAddHover($TempDM[0], $TempDM[1], "menu")
    GUISetBkColor($MenuItemInactiveColor)
    GUISetState(@SW_HIDE, $TempDM[1])
    GUISetState(@SW_DISABLE, $TempDM[1])
    GUISetState(@SW_SHOW, $___hWIN)
    $TempDM[2] = 0
    $TempDM[3] = $DM_x
    $TempDM[4] = $DM_y + $DM_height
    Return $TempDM
EndFunc ;=> GuiCtrlCreateDynamicMenu($DM_Label, $DM_x, $DM_y, $DM_width, $DM_height, $DM_gui_width, $DM_gui_height)

; ===============================================================================================
; Function:     GuiCtrlCreateDynamicMenuItem($DMI_Label, $DMI_target, $DMI_order)
;
; Description:  Creates a menu item in your dynamic parent menu
;
; Requirements: Must be created AFTER all dynamic parent menus
;
; Parameters:   $DMI_Label      - Menu Label
;               $DMI_target     - Dynamic Menu Parent
;               $DMI_order      - Sort order in menu with 0 being the first menuitem in the list
;
; Usage:        $Menu_File_Open = GuiCtrlCreateDynamicMenuItem("Open...", $Menu_File, 0)
; ===============================================================================================
Func GuiCtrlCreateDynamicMenuItem($DMI_Label, $DMI_target, $DMI_order)
    ; Enable and Show Child "Menu" Window for Menu Item creation
    GUISetState(@SW_ENABLE, $DMI_target[1])
    GUISetState(@SW_SHOW, $DMI_target[1])
    ; Get width of Menu for auto-sizing the menu for highlight
    Local $TempWidth = WinGetPos($DMI_target[1])
    ; Checks for empty label for separator creation
    If $DMI_Label = "" Then
        Local $TempDMI = GUICtrlCreateGraphic(0, ($DMI_order * 14) + 6, $TempWidth[2], 2, $SS_ETCHEDFRAME)
        ;MenuAddHover($TempDMI, "separator")
    Else
        Local $TempDMI = GUICtrlCreateLabel("     " & $DMI_Label, 0, $DMI_order * 14, $TempWidth[2], 14)
        GUICtrlSetBkColor(-1,$MenuItemInactiveColor)
        MenuAddHover($TempDMI,"none", "menuitem")
    EndIf
    ; Hide and disable child "menu" window.
    GUISetState(@SW_HIDE, $DMI_target[1])
    GUISetState(@SW_DISABLE, $DMI_target[1])
    
    
    Return $TempDMI
EndFunc ;=> GuiCtrlCreateDynamicMenuItem($DMI_Label, $DMI_target, $DMI_order)

Edited for updated (code is still sloppy will clean up soon!)

post-10606-1193135688_thumb.gif

dynamic_menus_0.7beta.au3

dynamic_menus_test_0.7.au3

Edited by xwinterx

Share this post


Link to post
Share on other sites



Share this post


Link to post
Share on other sites

Wow... This is a great job! Just 1 issue... The menu doesn't close when you click on the GUI again? Other than that, it is a great job! <_<

Thanks... yeah... it is still a work in progress. I guess at this point my main concern is the opening/closing of the menus depending on whether or not a menu is already open, if you open one and then mouseover other menus and as you stated for your case, mouseover/click something aside from the parent/child menus.

Still workin on it though. :)

Share this post


Link to post
Share on other sites

You can solve the problem of having to use $Main_GUI by adding a $hWin Parm

Old

Func GuiCtrlCreateDynamicMenu($DM_Label, $DM_x, $DM_y, $DM_width, $DM_height, $DM_gui_width, $DM_gui_height)

New

Func GuiCtrlCreateDynamicMenu($DM_Label, $DM_x, $DM_y, $DM_width, $DM_height, $DM_gui_width, $DM_gui_height, $hWin)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

You can solve the problem of having to use $Main_GUI by adding a $hWin Parm

Old

Func GuiCtrlCreateDynamicMenu($DM_Label, $DM_x, $DM_y, $DM_width, $DM_height, $DM_gui_width, $DM_gui_height)

New

Func GuiCtrlCreateDynamicMenu($DM_Label, $DM_x, $DM_y, $DM_width, $DM_height, $DM_gui_width, $DM_gui_height, $hWin)
yeah, I was think about that. Thanks!

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

updated a little. Still has some performance issues.

edited for bug: Click on menu won't work unless you have moved the mouse out of the menu.

Edited for bugfix.

Edited by xwinterx

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