Reputation: 19157
I have this simple code to create a CComboBox
and display it on a pane in a CMFCStatusBar
:
CRect rcPane;
m_StatusBar.GetItemRect(panePageBreaks, &rcPane);
CFont *pFont = m_StatusBar.GetFont();
m_myCombo.Create(WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_DROPDOWNLIST, rcPane, &m_StatusBar, 2500);
m_myCombo.SetFont(pFont);
m_myCombo.AddString(_T("Page Breaks: None"));
m_myCombo.AddString(_T("Page Breaks: 1 Week"));
m_myCombo.AddString(_T("Page Breaks: 2 Weeks"));
m_myCombo.AddString(_T("Page Breaks: 3 Weeks"));
m_myCombo.AddString(_T("Page Breaks: 4 Weeks"));
Can I make the status bar big enough to encompass this combo? At the moment it is a pixel or two too short in height:
If I use:
rcPane.InflateRect(1, 2, 0, 2);
It seems to be better. But i don't want to fudge it. Another users PC might be different. I want this combo to be exact over the specific pane.
I am kind of annoyed now. I found a similar question here which implies doing two things:
SetItemHeight
.So I employed both of these and I found that I would need a font height of -6 for the control to have the right height:
CRect rcPane;
m_StatusBar.GetItemRect(panePageBreaks, &rcPane);
CFont *pFont = m_StatusBar.GetFont();
LOGFONT sLF;
pFont->GetLogFont(&sLF);
sLF.lfHeight = -6;
pFont->CreateFontIndirect(&sLF);
m_myCombo.Create(WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_DROPDOWNLIST, rcPane, &m_StatusBar, 2500);
m_myCombo.SetItemHeight(-1, rcPane.Height());
m_myCombo.SetFont(pFont);
m_myCombo.AddString(_T("Page Breaks: None"));
m_myCombo.AddString(_T("Page Breaks: 1 Week"));
m_myCombo.AddString(_T("Page Breaks: 2 Weeks"));
m_myCombo.AddString(_T("Page Breaks: 3 Weeks"));
m_myCombo.AddString(_T("Page Breaks: 4 Weeks"));
You see, you can set the height of the edit control, but if your font height is larger it will make the edit control larger. So I can't go over -6. And the status bar text is -12. So this is not an option.
All I was trying to do was provide an easy way for the user to change this setting via the status bar as well as via menu navigation. But it looks like I can't do it.
If anything the CMFCStatusBar
height needs to be a tad taller than the default CComboBox
edit control height.
Upvotes: 2
Views: 168
Reputation: 1356
This code show how to increase the height of the statusbar. In this way you can use the stardard controls in your statubar without any modification.
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndStatusBar.Create(this))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT));
m_wndStatusBar.GetStatusBarCtrl().SetMinHeight(70); // or, whatever you need
return 0;
}
Upvotes: 1