Jump to content

[Resolved] get width of guictrlmenu


Recommended Posts

Greetings programmers,

Back with another, probably dumb, question.

I created a menu bar that lets users dynamically add and remove items - fun times (with more help than listable from one particular BA$$ on this forum - thank you again); and now that they can remove the items I need the bar to resize to fit shorter or longer against what items are left.

IE:

starts off with a dozen menu items

user removes 5

restarts the program

i need the bar to read the width of the left over menu items and make the gui that + about 5 to 10 pixels for safety.

Thoughts?

Ideas?

I tried the getcntrlpos but it doesn't work for menu items.

Any thoughts, ideas / directions?

Thanks in advance.

Edited by xeroTechnologiesLLC
Link to comment
Share on other sites

  • Moderators

xeroTechnologiesLLC,

I will take that as a compliment! :)

The menu titles in a GUI are always in the same font, so I would suggest using my StringSize UDF to get the size of each top level menu title. They should all be in a single section of the ini, so a simple loop should be enough. Sum those values and add enough for the inter-title margins and you should get a sensible answer on which to base your new GUI size. ;)

Give it a go and see how you get on - you know where I am if you run into difficulties. ;)

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

You should be able do something with _GUICtrlMenu_GetMenu and _GUICtrlMenu_GetItemRect

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Great lead in information above came up with the working code below.

Consider this one resolved.

On to how to make the program 'refresh' the width automatically without requiring the program to restart every time....

#region --- resize toolbox ---
        ; resize the toolbox to the width of the left over buttons
        $hWnd = WinGetHandle("ToolBox")
        $hMain = _GUICtrlMenu_GetMenu($hWnd)

        ; counter variable
        $c = 0
        $btnWidth1 = 0

         do
          $c += 1
          $mInfo = _GUICtrlMenu_GetMenuBarInfo($FRMtoolbox, $c, 1)
          $btnWidth1 += $minfo[2] - $minfo[0]
         until $minfo[2] = 0

         ; added a few extra pixels for screen width safety
         $screenW = $btnWidth1 + 15

        ; now resize the box based on the ini values plus the new width value
        winmove("ToolBox", "", $screenX, $screenY, $screenW)
       #endregion --- end resize toolbox ---

As always, thanks very much!

;):)

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

×
×
  • Create New...