Jump to content

Can I change the menu height and its font?


charvi
 Share

Recommended Posts

Hi everybody.

I wonder if it's possible to change the menu height and the font (name & size). I have tried _GUICtrlMenu_SetMenuHeight but it seems to have no effect. The example in the help file writes two lines in Notepad, but has no effect on the menu??

Using AutoIt 3.2.12.1 on Windows Vista Home Premium SP1.

Link to comment
Share on other sites

When I run the example for _GUICtrlMenu_SetMenuHeight() I get the following text in notepad and the menu is changed, what is written in your notepad? Are you even looking at the right thing? (your description makes it sound like you want to change the menuitems but that udf is for the whole menu)

File menu max height: 0

File menu max height: 100

Link to comment
Share on other sites

Hi everybody.

I wonder if it's possible to change the menu height and the font (name & size). I have tried _GUICtrlMenu_SetMenuHeight but it seems to have no effect. The example in the help file writes two lines in Notepad, but has no effect on the menu??

Using AutoIt 3.2.12.1 on Windows Vista Home Premium SP1.

It's not easy...Ok quick and rough example:

#include <GuiConstantsEx.au3>
#include <GuiMenu.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>

Global Const $ODT_MENU = 1

Global Const $ODS_SELECTED = 0x0001
Global Const $ODS_GRAYED   = 0x0002
Global Const $ODS_DISABLED = 0x0004
Global Const $ODS_CHECKED  = 0x0008
Global Const $ODS_DEFAULT  = 0x0020
Global Const $ODS_NOACCEL  = 0x0100

Global Enum $IDNew = 1000, $IDOpen

$hGUI = GUICreate("Test", 300, 200)

$FileMenu = GUICtrlCreateMenu("&File")
$hMenu = GUICtrlGetHandle($FileMenu)

_GUICtrlMenu_AddMenuItem($hMenu, "New", $IDNew)
_GUICtrlMenu_AddMenuItem($hMenu, "Open", $IDOpen)

$tMENUITEMINFO = DllStructCreate($tagMENUITEMINFO)
DllStructSetData($tMENUITEMINFO, "Mask", $MIIM_FTYPE)
DllStructSetData($tMENUITEMINFO, "Type", $MFT_OWNERDRAW)

_GUICtrlMenu_SetItemInfo($hMenu, 0, $tMENUITEMINFO)
_GUICtrlMenu_SetItemInfo($hMenu, 1, $tMENUITEMINFO)

GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_MEASUREITEM($hWnd, $Msg, $wParam, $lParam)
    Local $tMEASUREITEMSTRUCT, $itemID
    
    $tMEASUREITEMSTRUCT = DllStructCreate("int CtlType;int CtlID;int itemID;int itemWidth;int itemHeight;dword itemData", $lParam)
    
    If DllStructGetData($tMEASUREITEMSTRUCT, "CtlType") = $ODT_MENU Then
        DllStructSetData($tMEASUREITEMSTRUCT, "itemWidth", 80) ;Menu item width
        DllStructSetData($tMEASUREITEMSTRUCT, "itemHeight", 16) ;Menu item height
    EndIf
    
    Return $GUI_RUNDEFMSG
EndFunc

Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
    Local $tDRAWITEMSTRUCT, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC, $hBrush, $hBrushOld
    Local $hFont, $iBrushColor, $sItmText
    
    $tDRAWITEMSTRUCT = DllStructCreate("uint cType;uint cID;uint itmID;uint itmAction;uint itmState;" & _
                                       "hwnd hItm;hwnd hDC;int itmRect[4];dword itmData", $lParam)
                                       
    If DllStructGetData($tDRAWITEMSTRUCT, "cType") = $ODT_MENU Then
        $cID = DllStructGetData($tDRAWITEMSTRUCT, "cID")
        $itmID = DllStructGetData($tDRAWITEMSTRUCT, "itmID")
        $itmAction = DllStructGetData($tDRAWITEMSTRUCT, "itmAction")
        $itmState = DllStructGetData($tDRAWITEMSTRUCT, "itmState")
        $hItm = DllStructGetData($tDRAWITEMSTRUCT, "hItm")
        $hDC = DllStructGetData($tDRAWITEMSTRUCT, "hDC")
        
        Local $bGrayed   = BitAnd($itmState, $ODS_GRAYED)
        Local $bSelected = BitAnd($itmState, $ODS_SELECTED)
        Local $bDefault  = BitAnd($itmState, $ODS_DEFAULT)
        Local $bNoAcc    = BitAnd($itmState, $ODS_NOACCEL)
        
        If $itmState = $bNoAcc Then
            $iBrushColor = 0x00FF00
            
            $hBrush = _WinAPI_CreateSolidBrush($iBrushColor)
            $hBrushOld = _WinAPI_SelectObject($hDC, $hBrush)
        
            _WinAPI_FillRect($hDC, DllStructGetPtr($tDRAWITEMSTRUCT, "itmRect"), $hBrush)
        
            _WinAPI_SelectObject($hDC, $hBrushOld)
            _WinAPI_DeleteObject($hBrush)

            Local $tRECT = DllStructCreate("int[4]")
            DllStructSetData($tRECT, 1, DllStructGetData($tDRAWITEMSTRUCT, "itmRect", 1) + 7, 1)
            DllStructSetData($tRECT, 1, DllStructGetData($tDRAWITEMSTRUCT, "itmRect", 2), 2)
            DllStructSetData($tRECT, 1, DllStructGetData($tDRAWITEMSTRUCT, "itmRect", 3), 3)
            DllStructSetData($tRECT, 1, DllStructGetData($tDRAWITEMSTRUCT, "itmRect", 4), 4)
        
            Switch $itmID
                Case $IDNew
                    $sItmText = "New"
                    $hFont = _CreateFont($hWnd, 10, 800, 1, "MS Sans Serif")
                    _WinAPI_SelectObject($hDC, $hFont)
                    _WinAPI_DeleteObject($hFont)
                    _WinAPI_SetTextColor($hDc, 0xFF0000)
                Case $IDOpen
                    $sItmText = "Open"
                    $hFont = _CreateFont($hWnd, 12, 800, 2, "Comic Sans MS")
                    _WinAPI_SelectObject($hDC, $hFont)
                    _WinAPI_DeleteObject($hFont)
                    _WinAPI_SetTextColor($hDc, 0x0000FF)
            EndSwitch
        
            _WinAPI_SetBkColor($hDc, $iBrushColor)
        
            DllCall("user32.dll", "int", "DrawText", "hwnd", $hDC, "str", $sItmText, "int", StringLen($sItmText), _
                    "ptr", DllStructGetPtr($tRECT), "int", $DT_LEFT)
        EndIf
    EndIf
    
    Return $GUI_RUNDEFMSG
EndFunc

Func _CreateFont($hWnd, $nFontSize, $nFontWeight, $nFontAtrribute, $nFont)
    Local $hDc = DllCall("user32.dll", "hwnd", "GetDC", "hwnd", $hWnd)
    Local $nPixel = DllCall("gdi32.dll", "int", "GetDeviceCaps", "hwnd", $hDc[0], "int", $LOGPIXELSY)
    Local $nHeight = DllCall("kernel32.dll", "int", "MulDiv", "int", $nFontSize, "int", $nPixel[0], "int", 72)

    Local $hFont = DllCall("gdi32.dll", "hwnd", "CreateFont", "int", $nHeight[0], "int", 0, _
                           "int", 0, "int", 0, "int", $nFontWeight, "dword", BitAND($nFontAtrribute, 2), _
                           "dword", BitAND($nFontAtrribute, 4), "dword", BitAND($nFontAtrribute, 8), "int", $DEFAULT_CHARSET, _
                           "int", $OUT_DEFAULT_PRECIS, "int", $CLIP_DEFAULT_PRECIS, "int", $DEFAULT_QUALITY, "int", 0, _
                           "str", $nFont)
    
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "hwnd", $hDc[0])
    
    Return $hFont[0]
EndFunc   ;==>_CreateFont
Link to comment
Share on other sites

@AdmiralAlkex: I have the same output as you, and yes, it changed now... I must have been somewhat absent-minded for a while... Anyway, this kind of resizing is not what I was looking for, it resizes the height for the complete sub-menu frame, where the elements have to scroll into this restricted area. I was willing to resize the height for each menu element, but especially the height of the wide horizontal bar, so 'shooting' with the mouse gets easier.

@rasim: Thank you for the script. It is indeed rather complex, and I don't think I will use it, however I will preciously save your script, we never know. If you (or someone else?) can write a Func that just changes the height of the menu bar, that will be enough for me.

AutoIt's Koda menu system can create a menu, but doesn't change the width/height/font properties, as this is a Windows component. Then, maybe later with Windows 7 ? .....

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