问题描述
我有一个 Windows 应用程序,我试图在其中创建一个 PropertyPage 底部的状态栏。我在派生的 propertypage 类中添加了一个名为 m_StatBar 的 CStatusBarCtrl 类型的成员变量。
这是PropertyPage的OnInitDialog中的代码
enter code here
int nTotWide; // total width of status bar
CRect rect3;
this->GetwindowRect(&rect3);
rect3.top = rect3.bottom - 70;
int m_bRvstatOk = m_StatBar.Create(WS_CHILD | WS_BORDER | WS_VISIBLE,rect3,this,IDC_STATUSBAR);
if (m_bRvstatOk == NULL)
{
AfxMessageBox("Status Bar not created!",NULL,MB_OK);
}
// get size of window,use to configure the status
// bar with four separate parts
nTotWide = rect3.right - rect3.left;
//
// Make each part 1/4 of the total width of the window.
//
m_Widths[0] = nTotWide / 4;
m_Widths[1] = nTotWide / 2;
m_Widths[2] = nTotWide - m_Widths[0];
m_Widths[3] = -1;
m_StatBar.SetMinHeight(70);
m_StatBar.SetParts(4,m_Widths);
m_StatBar.SetText("TEXT WITH BORDER.",0);
m_StatBar.SetText("TEXT WITHOUT BORDER.",1,SBT_NOBORDERS);
m_StatBar.SetText("TEXT POPUP.",2,SBT_POPOUT);
我无法更改状态栏的高度。 感谢任何帮助。
解决方法
您不能设置 status bar 的高度。但是,您可以通过向控件发送 SB_SETMINHEIGHT 消息(这是 CStatusBarCtrl::SetMinHeight 实现所做的)来请求最小大小。
不过,这还不足以让系统拾取请求的最小高度。虽然 MFC 文档没有提供任何帮助或提示,但 SB_SETMINHEIGHT 文档有以下注释:
应用程序必须向状态窗口发送 WM_SIZE 消息才能重新绘制窗口。 WM_SIZE
消息的 wParam 和 lParam 参数应设置为零。
这转化为以下 MFC 实现:
m_StatBar.SetMinHeight(70);
m_StatBar.SendMessage(WM_SIZE); // wParam and lParam have default arguments set to 0