Jump to content

Recommended Posts

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
  • Moderators
Posted

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:

  Reveal hidden contents

 

Posted

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

Posted

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

Posted

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!

;):)

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
×
×
  • Create New...