Sign in to follow this  
Followers 0
AC130

GUICtrlCreateMenu

14 posts in this topic

Is there a way to treat this as a button, so that when I click on it, it will do a script?

Like:

Case

$GUICtrlCreateMenu1

MsgBox (0, "OK", "DEMO" )

Share this post


Link to post
Share on other sites



Is there a way to treat this as a button, so that when I click on it, it will do a script?

Like:

Case

$GUICtrlCreateMenu1

MsgBox (0, "OK", "DEMO" )

emm !!?? ! :huh2: post a more explicit script please... make my day easy and i will try to solve your problem...

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Global $FileMenu6 = GUICtrlCreateMenu("&Options")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $FileMenu6
      MsgBox ( whatever )
    EndSwitch
WEnd

Edited by AC130

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Global $FileMenu6 = GUICtrlCreateMenu("&Options")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $FileMenu6
      MsgBox ( whatever )
    EndSwitch
WEnd

This is NOT Helpful... -.- post a working script please....

EDIT:

This is a working script!! next time please make us to all easy!!!!

#include <GUIConstantsEx.au3>

$GUI = Guicreate("blabla")
$FileMenu = GUICtrlCreateMenu("&Options")
$fileitem = GUICtrlCreateMenuItem("Open", $filemenu)

Guisetstate()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Fileitem
      MsgBox (0,"","" )
    EndSwitch
WEnd

Anyway.... ¿is this what you want?

Edited by monoscout999

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

How is that not helpful...

I'm only asking to make it function as a button, so that I can press it.

[#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=c:\users\dad\desktop\software\form1.kxf
$Form1 = GUICreate("Test", 300, 300, 300, 300)
$FileMenu1 = GUICtrlCreateMenu("Options",)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit+
; I want to add another case so that when i press $FileMenu1 it will do a script.
    EndSwitch
WEnd
Edited by AC130

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

How is that not helpful...

is not helpfull because i have to write a new script... why dont you write the script is for you anyway

I already answer you in the last post...

Is mose pleaent help to someone who put some effor on the things... if you put an example script for us make sure that it works because is much easy copy and paste... is annoying do all the job for someone else.. to you is easy add a WORKING CODE not an prototype.. keep that in mind please

Edited by monoscout999

Share this post


Link to post
Share on other sites

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $defaultstatus, $status, $filemenu, $fileitem, $helpmenu, $saveitem
    Local $infoitem, $exititem, $recentfilesmenu, $separator1, $viewmenu
    Local $viewstatusitem, $okbutton, $cancelbutton, $statuslabel, $msg, $file
    
    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()
EndFunc   ;==>Example

This is the example code for the GUICtrlCreateMenuItem, and I'm wondering if there is a way to make GUICtrlCreateMenuItem to be a enable/disable option.

Posted Image

So that when "file" is pressed it will enable/disable another code in my script?

Share this post


Link to post
Share on other sites

Also is there a way that when I press a button, it will show a seperate GUI other than my main GUI? I tried GUICreate but I can't get it working.

Share this post


Link to post
Share on other sites

Also is there a way that when I press a button, it will show a seperate GUI other than my main GUI? I tried GUICreate but I can't get it working.

I see you are good in asking but not showing much effort yourself ... does that sound familiar?

Believe you got some time off recently and I am not seeing much change ....

What about you start studying the many examples in the Helpfile and posted code in the forum first?

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

ok well what about the other problem :huh2:...

i got it so that when i press file it shows a msgbox, but instead of a msgbox, can it be enable/disable a script.

Share this post


Link to post
Share on other sites

ok well what about the other problem :huh2:...

i got it so that when i press file it shows a msgbox, but instead of a msgbox, can it be enable/disable a script.

Have you even read what I wrote before you made the last post?

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

ok

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=c:\users\dad\desktop\software\form1.kxf
$Form1 = GUICreate("Demo", 300, 300, 100, 100)
$MenuItem = _GUICtrlCreateMenuItemEx1("Test", -1)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


GUISetState()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MenuItem
$Form2 = GUICreate("About", 350, 250, 302, 218)
$GroupBox1 = GUICtrlCreateGroup("", 8, 8, 305, 185)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("&OK", 124, 208, 75, 25, 0)
$Input1 = GUICtrlCreateInput("Test", 37, 30, 169, 21, $ES_CENTER)
GUISetState(@SW_SHOW)




    EndSwitch
WEnd

Func _GUICtrlCreateMenuItemEx1($sText, $iMenuID, $iMenuEntry=-1, $iMenuRadioItem=0)
    Local $nDummyMenu = GUICtrlCreateMenu("")
    Local $nDummyMenuItem = GUICtrlCreateMenuItem("", $nDummyMenu)

    Local $nMenuItem = GUICtrlCreateMenuItem($sText, $iMenuID, $iMenuEntry, $iMenuRadioItem)

    GUICtrlDelete($nDummyMenu)
    GUICtrlDelete($nDummyMenuItem)

    Return $nMenuItem
EndFunc

ok now whenver i press the test menuitem, i want it to bring up a new gui, and then input a number, and then when i press ok, i want it to save that number there, so that i can call a script using the entered number.

oh and also whenever i close out the about box, the whole program exits. any fixes? thanks! :huh2:

Share this post


Link to post
Share on other sites

AC130,

One way to do what you want is to have another While...WEnd loop inside the Case $Button code like this:

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>

$Form1 = GUICreate("Demo", 300, 300, 100, 100)

GUICtrlCreateMenu("")
$MenuItem = GUICtrlCreateMenuItem("Test", -1)

GUISetState(@SW_SHOW)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MenuItem
            $Form2 = GUICreate("About", 350, 250, 302, 218)
            $GroupBox1 = GUICtrlCreateGroup("", 8, 8, 305, 185)
            GUICtrlCreateGroup("", -99, -99, 1, 1)
            $Button1 = GUICtrlCreateButton("&OK", 124, 208, 75, 25, 0)
            $Input1 = GUICtrlCreateInput("Test", 37, 30, 169, 21, $ES_CENTER)
            GUISetState(@SW_SHOW)
            ; Disable the main GUI
            GUISetState(@SW_DISABLE, $Form1)
            ; Start a new loop to catch events from this GUI
            While 1
                Switch GUIGetMsg()
                    Case $Button1
                        ; Save the value from the input
                        $sInput = GUICtrlRead($Input1)
                        ; Display it to prove we did so
                        MsgBox(0, "Input", $sInput)
                        ; Carry on with the next case
                        ContinueCase
                    Case $GUI_EVENT_CLOSE
                        ; Re-enable the main GUI
                        GUISetState(@SW_ENABLE, $Form1)
                        ; Delete the GUI
                        GUIDelete($Form2)
                        ; Exit the inner While...WEnd loop
                        ExitLoop
                EndSwitch
            WEnd
    EndSwitch
WEnd

Note that the main GUI must be disabled while the child is visible. To see why this is important, comment out those lines and click on the main GUI [X] while the child is visible. What you get is not what you expected to happen, I dare say! :alien:

Another way you can go is to use the Advanced parameter with GUIGetMsg - look at the Managing Multiple GUIs tutorial in the Wiki to see how to make that work. ;)

Oh, and I also simplified the menu creation code a bit for you! :ph34r:

All clear? :huh2:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

about Menu click event i got it :huh2: !!!

#include <GUIConstantsEx.au3>
#include <array.au3>
#include <winapi.au3>
#include <WindowsConstants.au3>

$GUI = Guicreate("blabla")
$FileMenu = GUICtrlCreateMenu("&Options")

GUIRegisterMsg($WM_INITMENU,"_menuclick")
Guisetstate()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case 3
      MsgBox (0,"","" )
    EndSwitch
WEnd
func _menuclick($hWndGUI, $MsgID, $WParam, $LParam)
msgbox(0,"","")
EndFunc

But it is not perfect it shots the func when any menu is clicked...

Edited by monoscout999

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