Jump to content

Can a subitemless menu behave as a button ?


Recommended Posts

Are there any styles that could help or something ?

Also, how can I align a menu to the right ? Only the last one ?

Here an example, how to align menus to right (this is done by function), and how to catch message when clicking on the popup menu item.

#include <GUIConstants.au3>

Global Const $WM_MENUSELECT = 0x11F
Global Const $MF_MOUSESELECT = 0x8000
Global Const $MF_SYSMENU = 0x2000


$GUI = GUICreate("Form1", 626, 454, 193, 115)
$compactmenu = GUICtrlCreateMenu("&Compact mode")
$fullmenu = GUICtrlCreateMenu("&Full mode")
$helpmenu = GUICtrlCreateMenu("&Help")
_GUICtrlMenuRightJustify($GUI, $fullmenu)

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_MENUSELECT, "WM_MENUSELECT_FUNC")

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

Func WM_MENUSELECT_FUNC($hWnd, $Msg, $wParam, $lParam)
    Local $index = BitAND($wParam, 0xFFFF)
    Local $state = BitShift($wParam, 16)
    Local $info = GUIGetCursorInfo() ; action only when mouse button actually pressed
    If BitAND($state, $MF_MOUSESELECT) and not BitAND($state, $MF_SYSMENU) and ($info[2] = 1) then
        Switch $index
            Case 0
               Compact()
            Case 1
               Full()
        EndSwitch
    EndIf
EndFunc

Func Compact()
    MsgBox (0, "", "I'm Compact function")
EndFunc

Func Full()
    MsgBox (0, "", "I'm Full function")
EndFunc

Func _GUICtrlMenuRightJustify($hGUI, $nItem, $isIndex = false)
    Local $MFT_RIGHTJUSTIFY = 0x4000
    Local $MIIM_TYPE = 0x10
#cs
typedef struct tagMENUITEMINFO {
    UINT cbSize;
    UINT fMask;
    UINT fType;
    UINT fState;
    UINT wID;
    HMENU hSubMenu;
    HBITMAP hbmpChecked;
    HBITMAP hbmpUnchecked;
    DWORD dwItemData;
    LPTSTR  dwTypeData;
    UINT cch;
} MENUITEMINFO, FAR *LPMENUITEMINFO;
#ce
    Local $tagMENUITEMINFO = "uint;uint;uint;uint;uint;uint;uint;uint;dword;ptr;uint"
    Local $menu = DllCall("user32.dll", "hwnd", "GetMenu", "hwnd", $GUI)
    $menu = $menu[0]

    Local $menuinfo = DllStructCreate($tagMENUITEMINFO)
    Local $buffer   = DllStructCreate("byte[80]")

    DllStructSetData($menuinfo, 1, DllStructGetSize($menuinfo))
    DllStructSetData($menuinfo, 2, $MIIM_TYPE)
    DllStructSetData($menuinfo, 10, DllStructGetPtr($buffer))
    DllStructSetData($menuinfo, 11, 80)

    DllCall("user32.dll", "int", "GetMenuItemInfo", "int", $menu, _
                                                    "int", $nItem, _
                                                    "int", $isIndex, _
                                                    "ptr", DllStructGetPtr($menuinfo))

    DllStructSetData($menuinfo, 3, BitOR(DllStructGetData($menuinfo, 3), $MFT_RIGHTJUSTIFY))

    DllCall("user32.dll", "int", "SetMenuItemInfo", "int", $menu, _
                                                    "int", $nItem, _
                                                    "int", $isIndex, _
                                                    "ptr", DllStructGetPtr($menuinfo))
EndFunc
Edited by Lazycat
Link to comment
Share on other sites

Tried the obvious, won't work:

$compactmenu = GUICtrlCreateMenu ("&Compact mode")
    ...
    case $msg[0] = $compactmenu
        Compact ()oÝ÷ Ø
Þ¶«y©ò²Ü¥zËaj×(ºWazZh®Ê&zØb%²hÁƧ!©bv¦z{­¢Ø^®(!´éåÊØ^«-¢w©ä³}ÿªê-xw«z+ìZ^ºÈ§­£râm§¶¬t1ºÚ"µÍÚ[ÛYH  ÐLÓY[K]LÉÝÂÛØ[   ÌÍÚÕRK  ÌÍÚ[K    ÌÍÚ[ÛØ[[[H ÌÍÚY]ÏLL    ÌÍÚYÜ[  ÌÍÚYØ]K ÌÍÚY^]   ÌÍÚYXÝ]ÌÍÚÕRHHÕRPÜX]J ][ÝÓY[HÝ ][ÝË
Ì
BÈÜX]H[HY[BÌÍÚ[HHÓY[WÐÜX]SY[J
BÓY[WÐYY[R][J ÌÍÚ[K    ][ÝÉ[Ó]É][ÝÈ  ÌÍÚY]È
BÓY[WÐYY[R][J ÌÍÚ[K    ][ÝÉ[ÓÜ[][ÝÈ  ÌÍÚYÜ[BÓY[WÐYY[R][J   ÌÍÚ[K    ][ÝÉ[ÔØ]I][ÝÈ ÌÍÚYØ]JBÓY[WÐYY[R][J  ÌÍÚ[K    ][ÝÉ][ÝÈ
BÓY[WÐYY[R][J ÌÍÚ[K    ][ÝÑI[Þ] ][ÝÈ  ÌÍÚY^]
BÈÜX]H[Y[BÌÍÚ[HÓY[WÐÜX]SY[J
BÓY[WÐYY[R][J ÌÍÚ[ ][ÝÉ[ÐXÝ]   ][ÝË  ÌÍÚYXÝ]
BÈÜX]HXZ[Y[BÌÍÚXZ[HÓY[WÐÜX]SY[J
BÓY[WÐYY[R][J ÌÍÚXZ[   ][ÝÉ[Ñ[I][ÝË   ÌÍÚ[JBÓY[WÐYY[R][J ÌÍÚXZ[   ][ÝÉ[Ò[  ][ÝË  ÌÍÚ[
BÓY[WÔÙ]][UJ ÌÍÚXZ[K  ÌÍÓQÔQÒTÕQJBÈÙ]HÚ[ÝÈY[BÓY[WÔÙ]Y[J ÌÍÚÕRK  ÌÍÚXZ[BÕRTÙ]Ý]J
BÈYÚÝÛÛ[X[[[ØZ]Ü^]ÕRTYÚÝÙÊ  ÌÍÕÓWÐÓÓSPS  ][ÝÕÓWÐÓÓSPS  ][ÝÊBÂ[[ÕRQÙ]ÙÊ
HH  ÌÍÑÕRWÑUSÐÓÔÑBÈ[HY[HÛÛ[X[Â[ÈÓWÐÓÓSPS
    ÌÍÚÛ    ÌÍÚSÙË ÌÍÚ]Ô[K ÌÍÚ[[JBÝÚ]ÚÓXÓÕÛÜ
    ÌÍÚ]Ô[JBØÙH   ÌÍÚY]ÂÓXÐÛÛÛÛUÜ]J    ][ÝÓ]É][ÝÈ
BØÙH  ÌÍÚYÜ[ÓXÐÛÛÛÛUÜ]J    ][ÝÓÜ[][ÝÈ
BØÙH  ÌÍÚYØ]BÓXÐÛÛÛÛUÜ]J   ][ÝÔØ]I][ÝÈ
BØÙH  ÌÍÚY^]^]ØÙH    ÌÍÚYXÝ]ÓXÐÛÛÛÛUÜ]J   ][ÝÐXÝ]  ][ÝÊB[ÝÚ]Ú]    ÌÍÑÕRWÔSQTÑÂ[[
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

Here an example, how to align menus to right (this is done by function), and how to catch message when clicking on the popup menu item.

Thank you, it almost worked :)

I don't seem to be able to find that "popup" menu item. I modified your code, included it into my script, and it aligned what I asked it to align, but I don't see where or how I could specify which menu triggers the Compact() function. Anyhow, the function gets triggered by my first two menus which have sub items, but not for the 3rd one which has disabled subitems, nor for the 4th one which is the menu I aligned to right and which should be the one triggering the function....

Very nice example Lazycat!

I learned something new.

I wish I could say the same. Dll calls are worse than Chinese to me.

PaulIA, special thanks goes to you for your code. It remembers me of another language I'm trying to accommodate my self with right now. And I guess that's the right way to go. But, I would need to rewrite a considerable amount of my code... and if I do that, I think I'll opt for Python.

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...