[英]MFC: Adding a status bar to a CDialogEx that is resizable?
I thought it be nice to add a Status Bar with percentage and other information to a CDialogEx
that is used for viewing an image.我认为将带有百分比和其他信息的状态栏添加到用于查看图像的
CDialogEx
会很好。 But it doesn't seem that you can simply use a CMFCStatusBar
or a CStatusBar
and have it just work.但似乎您不能简单地使用
CMFCStatusBar
或CStatusBar
并让它正常工作。
I found various samples, but none of them have the statusbar outside the client area and moves as resized?我找到了各种样本,但没有一个样本在客户区之外有状态栏,并且没有调整大小? The different methods simply create a statusbar and it ends up hidden under a horizontal scrollbar and if you resize the window, the statusbar is sitting there in the middle of the dialog.
不同的方法只是创建一个状态栏,它最终隐藏在水平滚动条下,如果调整 window 的大小,状态栏就位于对话框的中间。
Is there an easy way or full example of having a statusbar on a CDialogEx
that can be resized like a normal window?是否有一个简单的方法或完整的示例在 CDialogEx 上有一个可以像普通
CDialogEx
一样调整大小的状态栏?
Is there an easy way or full example of having a statusbar on a
CDialogEx
that can be resized like a normal window?是否有一个简单的方法或完整的示例在 CDialogEx 上有一个可以像普通
CDialogEx
一样调整大小的状态栏?
Yes: Once you have created the status bar you can add it to the dynamic layout for resizing:是:创建状态栏后,您可以将其添加到动态布局中以调整大小:
//This is where we actually draw it on the screen
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST,
ID_INDICATOR_MEETING_TYPE);
GetDynamicLayout()->AddItem(m_StatusBar.GetSafeHwnd(),
CMFCDynamicLayout::MoveVertical(100), CMFCDynamicLayout::SizeHorizontal(100));
I have a status bar (not CMFCStatusBar
as it will not work, but CStatusBar
is OK) on two dialogs in my application.我的应用程序的两个对话框上有一个状态栏(不是
CMFCStatusBar
,因为它不起作用,但CStatusBar
没问题)。
Here is an updated example for when Dynamic Layout is not automatically enabled for you ( CDialogEx
with no controls):这是一个更新的示例,当您没有自动启用动态布局时(没有控件的
CDialogEx
):
BOOL CMyDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
if (!m_StatusBar.Create(this)) {
TRACE0("Failed to create status bar\n");
return -1;
}
m_StatusBar.SetIndicators(indicators, _countof(indicators));
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
EnableDynamicLayout();
auto pdlmanager=GetDynamicLayout();
if (pdlmanager) {
if (pdlmanager->Create(this)) {
pdlmanager->AddItem(m_StatusBar.GetSafeHwnd(), CMFCDynamicLayout::MoveVertical(100), CMFCDynamicLayout::SizeHorizontal(100));
}
}
// return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
return TRUE;
}
NIf you have a horizontal scrollbar the StatusBar will end up above it ; N如果你有一个水平滚动条,状态栏将在它上面结束; therefore you may have to create separate
CWnd
and add it to the dynamic layout (it would also be the nIDLeftOver
of the RepositionBars()
).因此您可能必须创建单独的
CWnd
并将其添加到动态布局中(它也将是RepositionBars()
的nIDLeftOver
)。
Here's how you can add the a "view" window for the contents so scrollbars can be contained within the view area:以下是如何为内容添加“视图”window,以便滚动条可以包含在视图区域中:
BOOL CMyDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
if (!m_StatusBar.Create(this)) {
TRACE0("Failed to create status bar\n");
return -1;
}
m_StatusBar.SetIndicators(indicators, _countof(indicators));
CRect rc;
GetClientRect(&rc);
CString clsname=AfxRegisterWndClass(0);
m_ImageView.Create(clsname, _T(""), WS_CHILD | WS_VISIBLE, rc, this, IDC_MY_VIEW);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, IDC_MY_VIEW);
EnableDynamicLayout();
auto pdlmanager=GetDynamicLayout();
if (pdlmanager) {
if (pdlmanager->Create(this)) {
pdlmanager->AddItem(m_StatusBar.GetSafeHwnd(), CMFCDynamicLayout::MoveVertical(100), CMFCDynamicLayout::SizeHorizontal(100));
pdlmanager->AddItem(m_ImageView.GetSafeHwnd(), CMFCDynamicLayout::MoveNone(), CMFCDynamicLayout::SizeHorizontalAndVertical(100, 100));
}
}
// return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
return TRUE;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.