Sign in to follow this  
Followers 0
xeroTechnologiesLLC

[Resolved] get width of guictrlmenu

5 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

@Melba,

The problem in this case is that the menu items that can be hidden are static, built into the form - not from the ini this time.

@ProgAndy,

Thanks, I am reading the intel on them now and will give it a whirl and reply back with results.

I appreciate both of you taking the time to reply.

Share this post


Link to post
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!

;):)

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • nikink
      By nikink
      Hi all,
      I have a bit of code that works on my old Win10 PC, that fails on my new Win10 PC, and I think the only significant difference is the version of Autoit - old PC has 3.3.12, new has 3.3.14.
      I couldn't find anything mentioned in the change logs though, so perhaps I'm wrong.
      Anyway, the code to replicate my issue is:
      Test('username', 'DOMAIN') ; THIS ERRORS: ;Test('localun', 'DOMAIN') ; THIS ERRORS: ;Test(' ', ' ') ; THIS ERRORS: ;Test('', '') ; THIS ERRORS: ;Test('localun', '') ; THIS ERRORS: ;Test('', 'DOMAIN') Func Test($un, $dom) $compName = 'PCNAME' $FullName = '.' $Description = '.' ; get the WIM object $objWMIService = ObjGet("winmgmts:\\" & $compName & "\root\cimv2") ; get default user full name and description $objAccount = $objWMIService.Get("Win32_UserAccount.Name='" & $un & "',Domain='" & $dom & "'") If IsObj($objAccount) Then $FullName = $objAccount.FullName $Description = $objAccount.Description EndIf ConsoleWrite($FullName & @CRLF) ConsoleWrite($Description & @CRLF) Return EndFunc  
      On my old PC this code will output just . and . for each of those line currently commented out. Which is fine.
      On my new PC any of those commented out lines of code cause an error, and the script won't even compile.
      $objAccount = $objWMIService.Get("Win32_UserAccount.Name='" & $un & "',Domain='" & $dom & "'") $objAccount = $objWMIService^ ERROR I'm very much a newb with the WMI stuff and objects, but it looks like the .Get property is failing when either $un or $dom aren't valid in v3.3.14, whereas in 3.3.12 the .Get would fail to return an object, which is then caught by the If statement.
      Am I on track with this? Is there some new/better way to code the example so that 3.3.14 will compile it?
    • nacerbaaziz
      By nacerbaaziz
      Hi all
      I want a way to get the last key pressed.
      I have a program that works with keyboard shortcuts and I want to  give the permission for the user to edit shortcut keys depending on what suits him
      i  want to make read-only edit box and the program writes the latest shortcut key pressed
      Please help me,
      greetings to all
      And thanks in advance
    • nacerbaaziz
      By nacerbaaziz
      hello guys
      how are you؟
      I hope to be fine.
      I have a question  please
      how do I get the menu item that was pressed without that contains a variable؟
      For example I have a menu  of Favorites and I want the script recognizes the existing path in the pressed item
      i'll repeat to tell the item does not contain a variable
      Is there any solution
      if you want to explain more I could write an example of what I want.
      Greetings to all,
      thanks in advance
    • nacerbaaziz
      By nacerbaaziz
      Hello my friends
      I have an urgent question, please help.
      How do I select all the text in the edit or input
      And how to get the currently selected text
      Please help urgently
      Greetings and thanks for all
    • KimberlyJillPereira
      By KimberlyJillPereira
      I am a newbie in AutoIt. May I know what is the code used to expand the width and height of excel cells because I want to insert pictures in the cell.I tried AutoFit but that doesnt work as I cant specify for the width and height. Only for column width I could expand by using .ColumnWidth but for the row I am not able to expand the row? How to do?? What is the code used ??Please help me and thank you.