Jump to content

Recommended Posts

Posted (edited)

How do I make a sub menu like (edit/paragraph) in auto it when you run GUI in MessageLoop Mode?

I've tried to do it accordingly to the help file but example where running in OnEvent mode. When I tried to run in MessageLoop Mode all the functions that would be activated by the menu buttons got called upon creation!!

How could it be done?

Edited by PhilipG
  • Moderators
Posted

PhilipG,

This works for me: ;)

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$mEdit_Menu = GUICtrlCreateMenu("&Edit")
$hParagraph_Menu_Item = GUICtrlCreateMenuItem("&Paragraph", $mEdit_Menu)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hParagraph_Menu_Item
            MsgBox(0, "", "Paragraph Menu Item clicked")
    EndSwitch

WEnd

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted (edited)

PhilipG,

This works for me: ;)

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$mEdit_Menu = GUICtrlCreateMenu("&Edit")
$hParagraph_Menu_Item = GUICtrlCreateMenuItem("&Paragraph", $mEdit_Menu)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hParagraph_Menu_Item
            MsgBox(0, "", "Paragraph Menu Item clicked")
    EndSwitch

WEnd

M23

When I reread your post i noticed that that's not what i'm trying to do! im trying to do something like this:

;Submenu
        $sExport = _GUICtrlMenu_CreateMenu ()
        _GUICtrlMenu_InsertMenuItem ($sExport, 0, "Exportera Databas", $ExpDB)
        _GUICtrlMenu_InsertMenuItem ($sExport, 1, "Exportera Uppdrag", $ExpUPD) 
        
        ;Submenu
        $sImport = _GUICtrlMenu_CreateMenu ()
        _GUICtrlMenu_InsertMenuItem ($sImport, 0, "Importera Databas", $ImpDB)
        _GUICtrlMenu_InsertMenuItem ($sImport, 1, "Importera Uppdrag", $ImpUPD) 


        ; Create File menu
        $hAkriv = _GUICtrlMenu_CreateMenu ()
        _GUICtrlMenu_InsertMenuItem ($hAkriv, 0, "Nytt uppdrag", $nytt)
        _GUICtrlMenu_InsertMenuItem ($hAkriv, 1, "Öppna uppdrag", $open)
        _GUICtrlMenu_InsertMenuItem ($hAkriv, 2, "")
        _GUICtrlMenu_InsertMenuItem ($hAkriv, 3, "Exportera", $export, $sExport)
        _GUICtrlMenu_InsertMenuItem ($hAkriv, 4, "Importera", 0, $sImport)
        _GUICtrlMenu_InsertMenuItem ($hAkriv, 5, "")
        _GUICtrlMenu_InsertMenuItem ($hAkriv, 6, "Stäng av", $exititem)

        
        ; Create Edit menu
        $hRedigera = _GUICtrlMenu_CreateMenu ()
        _GUICtrlMenu_InsertMenuItem ($hRedigera, 0, "Redigera uppdragsledare", $redupdled)
        _GUICtrlMenu_InsertMenuItem ($hRedigera, 1, "")
        _GUICtrlMenu_InsertMenuItem ($hRedigera, 2, "Inställningar", $redigera)
        


    ; Create Main menu
    $hMain = _GUICtrlMenu_CreateMenu ()
    _GUICtrlMenu_InsertMenuItem ($hMain, 0, "Arkiv", 0, $hAkriv)
    _GUICtrlMenu_InsertMenuItem ($hMain, 1, "Redigera", 0, $hRedigera)

    ; Set window menu
    _GUICtrlMenu_SetMenu ($hGUI, $hMain)

EDIT: Spelling

Edited by PhilipG
Posted (edited)

if you want to get the clicks on Menuitems with GUIGetMsg, you have to use the native GUICtrlMenu-functions. An example with a submenu:

GUICreate("Menutest")
$mnuMain1 = GUICtrlCreateMenu("MainMenu1")
    $mnuMain1_item1 = GUICtrlCreateMenuItem("Item1", $mnuMain1)
    $mnuMain1_mnuSub1 = GUICtrlCreateMenu("Submenu1", $mnuMain1)
        $mnuMain_mnuSub1_Item1 = GUICtrlCreateMenuItem("SubItem1", $mnuMain1_mnuSub1)
    $mnuMain1_item2 = GUICtrlCreateMenuItem("Item2", $mnuMain1)

$mnuMain2 = GUICtrlCreateMenu("MainMenu2")
    $mnuMain2_item1 = GUICtrlCreateMenuItem("Item1", $mnuMain2)

GUISetState()

While 1
    $uMsg = GUIGetMsg()
    Switch $uMsg
        Case -3 ; $GUI_EVENT_CLOSE
            Exit
        Case $mnuMain_mnuSub1_Item1
            MsgBox(0, '', "Main1 -> Submenu1 .> SubItem1")
        Case $mnuMain1_item1
            MsgBox(0, '', "Main1 -> Item1")
        Case $mnuMain1_item2
            MsgBox(0, '', "Main1 -> Item2")
        Case $mnuMain2_item1
            MsgBox(0, '', "Main2 -> Item1")
    EndSwitch
WEnd
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

  • Moderators
Posted (edited)

PhilipG,

You must use the builtin functions if you want to use GUIGetMsg because you need a ControlID and not a handle. ;)

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$mArkiv_Menu = GUICtrlCreateMenu("Arkiv")
    $mNytt_uppdrag_Menu_Item = GUICtrlCreateMenuItem("Nytt uppdrag", $mArkiv_Menu)
    $mOppna_uppdrag_Menu_Item = GUICtrlCreateMenuItem("Öppna uppdrag", $mArkiv_Menu)
    GUICtrlCreateMenuItem("", $mArkiv_Menu) ; separator line
    $mExportera_Menu_Item = GUICtrlCreateMenu("Exportera", $mArkiv_Menu)
        $mExportera_Databas_Menu_Item = GUICtrlCreateMenuItem("Exportera Databas", $mExportera_Menu_Item)
        $mExportera_Uppdrag_Menu_Item = GUICtrlCreateMenuItem("Exportera Uppdrag", $mExportera_Menu_Item)
    $mImportera_Menu_Item = GUICtrlCreateMenu("Importera", $mArkiv_Menu)
        $mImportera_Databas_Menu_Item = GUICtrlCreateMenuItem("Importera Databas", $mImportera_Menu_Item)
        $mImportera_Uppdrag_Menu_Item = GUICtrlCreateMenuItem("Importera Uppdrag", $mImportera_Menu_Item)
    GUICtrlCreateMenuItem("", $mArkiv_Menu) ; separator line
    $mStang_av_Menu_Item = GUICtrlCreateMenuItem("Stäng av", $mArkiv_Menu)
$mRedigera_Menu = GUICtrlCreateMenu("Redigera")
    $mRedigera_uppdragsledare_Menu_Item = GUICtrlCreateMenuItem("Redigera uppdragsledare", $mRedigera_Menu)
    GUICtrlCreateMenuItem("", $mRedigera_Menu) ; separator line
    $mInstallningar_Menu_Item = GUICtrlCreateMenuItem("Inställningar", $mRedigera_Menu)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $mNytt_uppdrag_Menu_Item
            MsgBox(0, "Menu", "Nytt uppdrag")
        Case $mOppna_uppdrag_Menu_Item
            MsgBox(0, "Menu", "Oppna uppdrag")
        Case $mExportera_Databas_Menu_Item
            MsgBox(0, "Menu", "Exportera Databas")
        Case $mExportera_Uppdrag_Menu_Item
            MsgBox(0, "Menu", "Exportera Uppdrag")
        Case $mImportera_Databas_Menu_Item
            MsgBox(0, "Menu", "Importera Databas")
        Case $mImportera_Uppdrag_Menu_Item
            MsgBox(0, "Menu", "Importera Uppdrag")
        Case $mStang_av_Menu_Item
            MsgBox(0, "Menu", "Stang av")
        Case $mRedigera_uppdragsledare_Menu_Item
            MsgBox(0, "Menu", "Redigera uppdragsledare")
        Case $mInstallningar_Menu_Item
            MsgBox(0, "Menu", "Installningar")
    EndSwitch

WEnd

M23

Edit: As ProgAndy has just told you!

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted (edited)

if you want to get the clicks on Menuitems with GUIGetMsg, you have to use the native GUICtrlMenu-functions. An example with a submenu:

GUICreate("Menutest")
$mnuMain1 = GUICtrlCreateMenu("MainMenu1")
    $mnuMain1_item1 = GUICtrlCreateMenuItem("Item1", $mnuMain1)
    $mnuMain1_mnuSub1 = GUICtrlCreateMenu("Submenu1", $mnuMain1)
        $mnuMain_mnuSub1_Item1 = GUICtrlCreateMenuItem("SubItem1", $mnuMain1_mnuSub1)
    $mnuMain1_item2 = GUICtrlCreateMenuItem("Item2", $mnuMain1)

$mnuMain2 = GUICtrlCreateMenu("MainMenu2")
    $mnuMain2_item1 = GUICtrlCreateMenuItem("Item1", $mnuMain2)

GUISetState()

While 1
    $uMsg = GUIGetMsg()
    Switch $uMsg
        Case -3 ; $GUI_EVENT_CLOSE
            Exit
        Case $mnuMain_mnuSub1_Item1
            MsgBox(0, '', "Main1 -> Submenu1 .> SubItem1")
        Case $mnuMain1_item1
            MsgBox(0, '', "Main1 -> Item1")
        Case $mnuMain1_item2
            MsgBox(0, '', "Main1 -> Item2")
        Case $mnuMain2_item1
            MsgBox(0, '', "Main2 -> Item1")
    EndSwitch
WEnd

I Thought i tried that without success. But when I look closer on your code i noticed what i've done wrong!

This was my code:

$arkiv = GUICtrlCreateMenu ( "Akriv");skapar en 
$export = GUICtrlCreateMenuitem("Exportera", $arkiv)
    $exportDB = GUICtrlCreateMenuItem("Databas", $export)

Now corrected it to:

$arkiv = GUICtrlCreateMenu ( "Akriv");skapar en 
$export = GUICtrlCreateMenu("Exportera", $arkiv)
    $exportDB = GUICtrlCreateMenuItem("Databas", $export)

And now it all works fine! Thanks!

Edited by PhilipG

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
×
×
  • Create New...