Change AHK Menu window style (MNS_...)

Get help with using AutoHotkey and its commands and hotkeys
gwarble
Posts: 240
Joined: 30 Sep 2013, 15:01

Change AHK Menu window style (MNS_...)

Post by gwarble » 15 Dec 2016, 18:30

Hey all,
Anyone have any tricks to set the AHK menu's window style?

My goal is to remove MNS_CHECKORBMP to display both an icon and a checkbox.

This does not work:
MI_SetMenuStyle(MenuNameOrHandle, 0x0)

but this does to remove the space for icon/check altogether
MI_SetMenuStyle(MenuNameOrHandle, 0x80000000)

Code: Select all

; Valid (and safe to use) styles:
;   MNS_AUTODISMISS  0x10000000
;   MNS_CHECKORBMP   0x04000000  The same space is reserved for the check mark and the bitmap.
;   MNS_NOCHECK      0x80000000  No space is reserved to the left of an item for a check mark.
MI_SetMenuStyle(MenuNameOrHandle, style="0x4000000")
{
    if MenuNameOrHandle is integer
        h_menu := MenuNameOrHandle
    else
        h_menu := MI_GetMenuHandle(MenuNameOrHandle)
    
    if !h_menu
        return
        
    VarSetCapacity(mi,28,0), NumPut(28,mi)
    NumPut(0x10,mi,4) ; fMask=MIM_STYLE
    NumPut(style,mi,8)
    DllCall("SetMenuInfo","uint",h_menu,"uint",&mi)
}
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
lexikos
Posts: 6175
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Change AHK Menu window style (MNS_...)

Post by lexikos » 16 Dec 2016, 04:18

If you remove MNS_CHECKORBMP, whether it displays both side by side depends on the OS and theme. Windows 7 with classic theme or Windows XP will put both side by side, but other themes on Windows 7 or Windows 10 will not. My tests showed that when they are put side by side, there is zero space between the icon and the text.

The code you posted, which comes from my Menu Icons library, is outdated and not compatible with x64. You may use this instead:

Code: Select all

; Valid (and safe to use) styles:
;   MNS_AUTODISMISS  0x10000000
;   MNS_CHECKORBMP   0x04000000  The same space is reserved for the check mark and the bitmap.
;   MNS_NOCHECK      0x80000000  No space is reserved to the left of an item for a check mark.
SetMenuStyle(MenuNameOrHandle, style:=0x4000000)
{
    if MenuNameOrHandle is integer
        h_menu := MenuNameOrHandle
    else
        h_menu := MenuGetHandle(MenuNameOrHandle)  ; v1.1.23+
    
    if !h_menu
        return
        
    VarSetCapacity(mi,40,0), NumPut(16+3*A_PtrSize,mi)
    NumPut(0x10,mi,4) ; fMask=MIM_STYLE
    NumPut(style,mi,8)
    DllCall("SetMenuInfo","ptr",h_menu,"ptr",&mi)
}
It is poor style (no pun intended) to put quotes around a number when it is used as a number, not a string of characters.
gwarble
Posts: 240
Joined: 30 Sep 2013, 15:01

Re: Change AHK Menu window style (MNS_...)

Post by gwarble » 16 Dec 2016, 08:58

Ah thanks for the info... I think i'll try to overlay a check onto the icon with gdip instead, don't want to fight dependencies on themes


I think that at the time you wrote MI() function definitions were still required to use quotes and "=" for default parameter values
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
lexikos
Posts: 6175
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Change AHK Menu window style (MNS_...)

Post by lexikos » 16 Dec 2016, 16:47

Are you saying that you added the parameter default right after I wrote the function over nine years ago? I did not give that parameter a default value.

Quotes were never required. Literal numbers were supported in v1.0.35 when optional parameters were added, whereas non-empty quoted strings weren't supported until v1.0.46.13. I posted MI several months after that.
gwarble
Posts: 240
Joined: 30 Sep 2013, 15:01

Re: Change AHK Menu window style (MNS_...)

Post by gwarble » 16 Dec 2016, 17:54

I didn't realize it but apparently i must have edited in (erroneously apparently, at the time i might have even thought that i really wanted that string to be passed and not an integer) a default parameter sometime in the past nine years, actually most likely between 1.0.48 when i started using ahk and 1.0.90 when menu icons were added natively when i don't think i would have had a reason for MI()... Probably haven't looked at it since, just dug it out of my Lib\ yesterday to try to get the icon and check
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
Post Reply

Return to “Ask For Help”