Is there any option to set the height if a CMenu
?
I know one can draw a custom menu item and use a custom size there CMenu::MeasureItem
, but is there a way to set/change the height of the menu(bar) itself?
Thanks.
Is there any option to set the height if a CMenu
?
I know one can draw a custom menu item and use a custom size there CMenu::MeasureItem
, but is there a way to set/change the height of the menu(bar) itself?
Thanks.
Changing the height of a menu-bar is relatively easy, if your menu-bar is derived from the CMFCMenuBar class*. In this case, you simply need to override the CalcLayout
member and specify the required height in the .y
member of the returned CSize
object. Here's a minimal example:
// Class declaration...
class MyMenuBar : public CMFCMenuBar {
public: // Standard constructors and destructor ...
MyMenuBar(void) : CMFCMenuBar() {}
inline MyMenuBar(const MyMenuBar&) = delete;
inline MyMenuBar& operator = (MyMenuBar&) = delete;
virtual ~MyMenuBar(void) {}
protected: // Overrides for custom behaviour ...
CSize CalcLayout(DWORD dwMode, int nLength = -1) override;
};
// Implementation...
CSize MyMenuBar::CalcLayout(DWORD dwMode, int nLength)
{
CSize cs = CMFCMenuBar::CalcLayout(dwMode, nLength); // Call base-class to get width
cs.cy = 42; // Set this to your desired menu-bar height (in pixels)
return cs;
}
To use such a menu-bar, you need only to declare it as a member of your main frame window and then create it and set its style/properties when handling the WM_CREATE
message for that frame window (typically, in MFC
apps, this will be in the OnCreate()
member override).
Note: You could, in theory, use this method with any base-class that has the CalcLayout
member (such as CMFCToolbar
); however, the CMFCMenuBar
class allows the framework to handle all other expected actions from the contained menu.