Results 1 to 9 of 9

Thread: Adding Controls to MenuBar

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2014
    Posts
    553

    Adding Controls to MenuBar

    I'm not all the keen on placing Controls where they aren't
    typically found like extra Command Buttons on the TitleBar, but that's what I'm currently facing.

    I've added Objects to both the TitleBar and Toolbar, and now have a 'request' to place Objects on the MenuBar.

    For the TitleBar and ToolBar, I found examples on the net and pulled the code into the project, all pretty straight forward.

    But when dealing with a MenuBar, I can't seem to get it to work, and searching the web hasn't helped.

    I don't get any errors when modifying the code from the ToolBar to the MenuBar, the object just doesn't show up when changing it's parent. It just sort of disappears.

    My only thoughts are that using GetMenu doesn't return a Handle to the DC of the visible 'panel' that the Menu Buttons are seated on, so it doesn't get displayed.

    Is there a way to know or get the correct Handle to a Forms MenuBar?

    Thanks.

  2. #2
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: Adding Controls to MenuBar

    Quote Originally Posted by stuck-n-past View Post
    I'm not all the keen on placing Controls where they aren't
    typically found like extra Command Buttons on the TitleBar, but that's what I'm currently facing.

    I've added Objects to both the TitleBar and Toolbar, and now have a 'request' to place Objects on the MenuBar.

    For the TitleBar and ToolBar, I found examples on the net and pulled the code into the project, all pretty straight forward.

    But when dealing with a MenuBar, I can't seem to get it to work, and searching the web hasn't helped.

    I don't get any errors when modifying the code from the ToolBar to the MenuBar, the object just doesn't show up when changing it's parent. It just sort of disappears.

    My only thoughts are that using GetMenu doesn't return a Handle to the DC of the visible 'panel' that the Menu Buttons are seated on, so it doesn't get displayed.

    Is there a way to know or get the correct Handle to a Forms MenuBar?

    Thanks.
    The menu bar is very different from a toolbar.
    The menu bar is in the non client area, unlike toolbars or any other control.
    If you have code to place something in the title bar, the title bar is also in the non client area, so that code should be more close to the code needed to draw something in the menu bar.

    You can't do that with SetParent.

    I think you better use a custom made menu and replace the standard menu. So it will be in the client area.

  3. #3
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,046

    Re: Adding Controls to MenuBar

    Hi Stuck,

    not sure if you can use this.
    our good Spoo came up with this a while back..
    http://www.vbforums.com/showthread.p...bmenu-captions
    go to Post#26

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Adding Controls to MenuBar

    If possible avoid playing non-client area games.

    Microsoft is working on a future Windows (Windows 10, but all Windows is now Windows 10 in the modern era) feature currently being called "Sets."

    With "Sets" applications can be grouped together in a tabbed interface like the ones you see in browsers these days. Unlike browsers, "Setted" applications can be a mixture of different applications (including "browser tabs").

    One of the more troublesome issues are applications that muck around in the non-client area of windows. That is why at first only UWP apps like Edge (and MS Office, a special case they want really badly) would be "Settable." Once perfected, other normal Desktop applications may become "Settable" too. But any that mess with non-client areas might never work.

    This feature may start rolling out for general use as soon as 2nd quarter 2018.

    Or of course Microsoft may drop the entire thing too.

    Search on "Windows 10 Sets" to find more information about the early thoughts on "Sets."

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2014
    Posts
    553

    Re: Adding Controls to MenuBar

    Oh Nasty, NC region, I should of realized that Menus fell into that category. The grey matter truly is drying up.

    Eduardo, I thought about switching to a custom UC and was ready to settle in to a late night marathon of insomnia programming. But then I remember about the little quirk when it comes to maximizing MDI Child Forms and how they automatically allocate NC space at the top of a Form to host Menu buttons even if none exist. While I'm not overly crazy about where MDI Forms place there second ControlBox, I can't think of anyplace better then what they chose.

    By using a custom solution, once a MDI Child Form becomes maxed, there would be a long blank dead space under the TitleBar. And one of the reasons for trying to utilize the space next to the MenuBar was to consolidate controls into a tight grouping, displaying the most amount of information in the smallest possible 'foot-print'.

    Personally I think it makes the Form look cluttered and hard to follow, but then it's not really my call. I have tried to steer the client away from doing this type of a layout, but no luck.

    Hey ChrisE, thanks for the link. I'm not sure it's something I can make use of this go-around, but I liked the code to the point where I bookmarked the page.

    Man dilettante, you never cease to amaze me with the amount of knowledge you have when it comes to Windows and VB. From what you've described about Windows Sets, I'm not sure it's something I'd be all the keen on. After writing this I'll be searching for information on 'Sets'. I have to wonder if such a change won't cause problems to existing programs. It also might have me heading back to the client with a stronger stance against adding Objects to the MenuBar.

  6. #6
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: Adding Controls to MenuBar

    Quote Originally Posted by stuck-n-past View Post
    Eduardo, I thought about switching to a custom UC and was ready to settle in to a late night marathon of insomnia programming. But then I remember about the little quirk when it comes to maximizing MDI Child Forms and how they automatically allocate NC space at the top of a Form to host Menu buttons even if none exist. While I'm not overly crazy about where MDI Forms place there second ControlBox, I can't think of anyplace better then what they chose.

    By using a custom solution, once a MDI Child Form becomes maxed, there would be a long blank dead space under the TitleBar. And one of the reasons for trying to utilize the space next to the MenuBar was to consolidate controls into a tight grouping, displaying the most amount of information in the smallest possible 'foot-print'.

    Personally I think it makes the Form look cluttered and hard to follow, but then it's not really my call. I have tried to steer the client away from doing this type of a layout, but no luck.
    That section is part of the non client area of the MDI parent form, still when it shows the close, restore and min buttons for the maximized childs.

    Anyway, I don't know what controls you want to put there. Anything you can show there must be custom drawn, you cannot carry a normal control to the non client area.

    Nothing is impossible (there can be other options), but how many weeks are you willing to spend on doing that?

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2014
    Posts
    553

    Re: Adding Controls to MenuBar

    Yeah well that's gonna be the fun part. If I can't convince them it's not the best idea in the world to stuff Controls on the MenuBar, then I have to come up with an estimate of what it would take to accomplish.

    I had another (stupid) thought, I have a pocket full of them, is there any difference in trying to place objects on the MenuBar vs trying to place them on a MenuBar-Button?

    Create a dummy Menu Item, get it's handle and try to put an object on top. Crazy huh, I don't know enough about NC areas to know if that's complete nonsense or not. And even if it's possible the dimensions would be restrictive, limited to the size of a button.

    I even tossed around the idea of making a transparent non-modal form positioned over the MenuBar tied to the Resize Event to mimic it's parent's movements. I tend to hover on the edge of lunacy.

  8. #8
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: Adding Controls to MenuBar

    Quote Originally Posted by stuck-n-past View Post
    Yeah well that's gonna be the fun part. If I can't convince them it's not the best idea in the world to stuff Controls on the MenuBar, then I have to come up with an estimate of what it would take to accomplish.
    If they pay...

    Quote Originally Posted by stuck-n-past View Post
    I had another (stupid) thought, I have a pocket full of them, is there any difference in trying to place objects on the MenuBar vs trying to place them on a MenuBar-Button?
    I don't understand what you mean with "MenuBar-Button". Are you talking about a ToolBar?

    Quote Originally Posted by stuck-n-past View Post
    Create a dummy Menu Item, get it's handle and try to put an object on top. Crazy huh, I don't know enough about NC areas to know if that's complete nonsense or not. And even if it's possible the dimensions would be restrictive, limited to the size of a button.
    I repeat: you cannot put any VB control in the non client area.
    What you could do there (with effort) is to draw something and to respond to mouse messages. That's basically the same thing that a control does, but you'll have to draw the "controls" and respond to messages all coded by you.

    This project performs custom drawing in the NC area.

    Quote Originally Posted by stuck-n-past View Post
    I even tossed around the idea of making a transparent non-modal form positioned over the MenuBar tied to the Resize Event to mimic it's parent's movements. I tend to hover on the edge of lunacy.
    When I said "there can be other options" in my previous message, my idea was to completely remove the client area of the MDI parent form, and to place that form with SetParent into a normal form where you can have a custom menu bar.
    Doing that, you will have not only to hadle the menu (with a custom menu control) but also to handle the title bar buttons of the MDI child forms when one is maximized.

    But it will have a problem: the Title bar of the form that acts as parent will appear as inactive, because the form with the focus will be the MDI.

    And about your idea: it could be better, it could work. You'll have to subclass the MDI parent form and handle WM_WINDOWPOSCHAGING (or may be WM_WINDOWPOSCHANGED).
    I don't know if that toolbar form needs to be trasparent, just make it the same color of the menu bar.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2014
    Posts
    553

    Re: Adding Controls to MenuBar

    I don't understand what you mean with "MenuBar-Button". Are you talking about a ToolBar?
    Sorry about that, it was just me thinking out-loud, which can be very confusing.

    I was thinking that OK if I can't write on the Menu-Bar surface because it resides in the the NC region, perhaps going back to ChrisE post / link above and try to modify a MenuBar Item.

    It would be quite a stretch though as that thread deals with changing an items text vs trying to treat an item as a container.

    This is definitely turning into one of those efforts where it's going to be more trouble then it's worth.

    Here is a Hack of a test project, but don't look at the code, it's not pleasant.

    You should be able to move and size the MDIForm, just ignore the flashing TitleBar when clicking on the Controls.
    Attached Files Attached Files
    Last edited by stuck-n-past; Dec 3rd, 2017 at 12:29 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width