Jump to content

Menu possible without submenus?


Go to solution Solved by Melba23,

Recommended Posts

Posted (edited)

simple example:

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

$Form1 = GUICreate("Form1", 615, 437, 192, 124)
$menu1 = GUICtrlCreateMenu("click me")
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $menu1
            MsgBox(64,'yes!','it works') ; not
    EndSwitch
WEnd

To make this work without submenus/empty menu tricks seems to be difficult :wacko:

Not possible without dummy's / extensive UDF's or submenus?

TheAutomator

Edited by TheAutomator
Link to comment
Share on other sites

Here one way :

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3>

Opt("MustDeclareVars", True)

Global $hGUI = GUICreate("Form1", 625, 442, 370, 232)
Global $idMenu = GUICtrlCreateMenu("Click me")
Global $hMenu = _GUICtrlMenu_GetMenu($hGUI)
Global $idChoice = GUICtrlCreateDummy()

GUISetState()
GUIRegisterMsg($WM_MENUSELECT, WM_MENUSELECT)

While True
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      Exit
    Case $idChoice
      ConsoleWrite("Menu clicked " & GUICtrlRead($idChoice) & @CRLF)
  EndSwitch
WEnd

Func WM_MENUSELECT($hWnd, $iMsg, $wParam, $lParam)
  Local $iIndex = _WinAPI_LoWord($wParam)
  Local $iFlag = _WinAPI_HiWord($wParam)
  If $iIndex = 0 And BitAND($iFlag, $MF_MOUSESELECT) And $lParam = $hMenu Then
    GUICtrlSendToDummy($idChoice, $iIndex)
    EndMenu()
  EndIf
  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_MENUSELECT

Func EndMenu()
  DllCall("user32.dll", "bool", "EndMenu")
EndFunc

 

Link to comment
Share on other sites

  • Moderators
  • Solution

TheAutomator,

The trick I have used in the past only works when you to have an initial "normal" menu entry - so how about this:

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

$Form1 = GUICreate("Form1", 615, 437, 192, 124)

$mDummymenu = GUICtrlCreateMenu("")

$menu1 = GUICtrlCreateMenuItem("click me", -1)

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $menu1
            MsgBox(64,'yes!','it works') ; does!
    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

 

Link to comment
Share on other sites

Posted (edited)

I guess the short answer is "nope",
I tend to use the one from Melba32 for simplicity (and marked it as solution to close the topic), but you have to have a clickable empty menu in your gui..
The one Nine posted was a little more complicated and used a dummy and udf's, but it looks the way it should when used..
I can't really call any reply's the right 'solution' because the question was "possible without dummy's, udf's or submenu/second menu tricks?".

But I wanna thank you all for coming up with workarounds, now at least I know I'm not doing anything wrong in my code :)

TheAutomator

Edited by TheAutomator
Link to comment
Share on other sites

Can you show us YOUR solution without dummy, udf, menu/submenu, etc ?  I am really curious to see how you got it working, and community sure would appreciate to learn from it too... 

Link to comment
Share on other sites

@Melba23 & @Nine

Deleting the menu control seems to do the job. It will position to the very left of the GUI all existing menuitem(s) control(s) . Does this work for you ?

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

$Form1 = GUICreate("Form1", 615, 437, 192, 124)

$mDummymenu = GUICtrlCreateMenu("this menu control will be deleted")
$menu1 = GUICtrlCreateMenuItem("click me", -1)
$menu2 = GUICtrlCreateMenuItem("click me again", -1)

GUICtrlDelete($mDummymenu) ; <======================

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $menu1
            MsgBox($MB_TOPMOST ,'yes!', 'it works')
        Case $menu2
            MsgBox($MB_TOPMOST,'yes!', 'it works again')
    EndSwitch
WEnd

 

Link to comment
Share on other sites

  • Moderators

pixelsearch,

Nice one!

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

 

Link to comment
Share on other sites

Dear Nine,

On 5/9/2024 at 2:27 AM, Nine said:

Can you show us YOUR solution without dummy, udf, menu/submenu, etc ?  I am really curious to see how you got it working, and community sure would appreciate to learn from it too... 

I think you misunderstood the question.. I wanted to know if it was possible, I'm not saying it is possible :whistle:

The solution seems to be to do it like Melba32 or pixelsearch or you :)
The answer to my question would be "sorry, not possible" do you know what I mean?

Edited by TheAutomator
Link to comment
Share on other sites

And now here we can even reuse the variable, gonna do it like this.

Thanks pixelsearch!

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

$Form1 = GUICreate("Form1", 615, 437, 192, 124)

$menu2 = GUICtrlCreateMenu("this menu control will be deleted")
$menu1 = GUICtrlCreateMenuItem("click me", -1)
GUICtrlDelete($menu2) ; <======================
$menu2 = GUICtrlCreateMenuItem("click me again", -1)


GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $menu1
            MsgBox($MB_TOPMOST ,'yes!', 'it works')
        Case $menu2
            MsgBox($MB_TOPMOST,'yes!', 'it works again')
    EndSwitch
WEnd

 

Edited by TheAutomator
Link to comment
Share on other sites

On 5/9/2024 at 3:32 PM, pixelsearch said:

@Melba23 & @Nine

Deleting the menu control seems to do the job. It will position to the very left of the GUI all existing menuitem(s) control(s) . Does this work for you ?

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

$Form1 = GUICreate("Form1", 615, 437, 192, 124)

$mDummymenu = GUICtrlCreateMenu("this menu control will be deleted")
$menu1 = GUICtrlCreateMenuItem("click me", -1)
$menu2 = GUICtrlCreateMenuItem("click me again", -1)

GUICtrlDelete($mDummymenu) ; <======================

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $menu1
            MsgBox($MB_TOPMOST ,'yes!', 'it works')
        Case $menu2
            MsgBox($MB_TOPMOST,'yes!', 'it works again')
    EndSwitch
WEnd

 

This is an awesome hack btw :D

Edited by TheAutomator
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...