怎样在对话框中加入状态栏?

马鸣风萧萧 2003-04-30 11:29:59
我想在对话框中加入状态栏却不知如何实现。能用一般的文档窗口中加入状态拦的方法吗?
...全文
308 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
GoogleGeek 2003-05-01
  • 打赏
  • 举报
回复
void CDialogMenuToolBarDlg::RecalToolBarPos(CDialog *pParentWnd)
{
ASSERT(pParentWnd!=NULL);
ASSERT(pParentWnd->IsKindOf(RUNTIME_CLASS(CDialog)));

CRect rectClientStart;
CRect rectClientNow;
//make the rectClientStart bigger than rectClientNow
pParentWnd->GetClientRect(rectClientStart);
pParentWnd->RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0,reposQuery,rectClientNow);

//shift the position of all the control
CPoint ptOffset(rectClientNow.left-rectClientStart.left,rectClientNow.top-rectClientStart.top);
CRect rectChild;
CWnd *pWndChild=pParentWnd->GetWindow(GW_CHILD);
while(pWndChild)
{
pWndChild->GetWindowRect(rectChild);
pParentWnd->ScreenToClient(rectChild);
rectChild.OffsetRect(ptOffset);
pWndChild->MoveWindow(rectChild,false);
pWndChild=pWndChild->GetNextWindow();
}

//enlarge the size of the dialog
CRect rectWindow;
pParentWnd->GetWindowRect(rectWindow);
rectWindow.right+=rectClientStart.Width()-rectClientNow.Width();
rectWindow.bottom+=rectClientStart.Height()-rectClientNow.Height();
pParentWnd->MoveWindow(rectWindow,false);

//set the proper postion of the toolbar!
pParentWnd->RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);
pParentWnd->CenterWindow();

}
GoogleGeek 2003-05-01
  • 打赏
  • 举报
回复
即使你在dialog中加入了mfc的默认的statusbar,你也必须自己添加默认的消息处理函数
否则在默认的情况下,他不会相应的

BOOL CDialogMenuToolBarDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

CRect rectClient;
this->GetClientRect(rectClient);
this->m_StaticDivide.MoveWindow(0,0,rectClient.Width(),2);


// TODO: Add extra initialization here
/*
BOOL CreateEx(
CWnd* pParentWnd,
DWORD dwCtrlStyle = TBSTYLE_FLAT,
DWORD dwStyle = WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP,
CRect rcBorders = CRect(0, 0, 0, 0),
UINT nID = AFX_IDW_TOOLBAR);

*/


if (!m_wndToolBar1.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar1.LoadToolBar(IDR_TOOLBAR_DIALOG))
{
TRACE0("Failed to create toolbar\n");
EndDialog(IDCANCEL);// fail to create
}

if (!m_wndToolBar24Bit.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar24Bit.LoadToolBar(IDR_TOOLBAR_NAVIGATE))
{
TRACE0("Failed to create toolbar\n");
EndDialog(IDCANCEL);// fail to create
}

// Screen designer control bar
if (!m_wndDynControlBar.CreateEx(this) ||
!m_wndDynControlBar.LoadToolBar(IDR_DYNCONTROLBAR))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}

if (!m_wndStatusBar.Create(this)//, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM)
|| !m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return FALSE; // fail to create
}

// Set up hot bar image lists.
CImageList imageList;
CBitmap bitmap;

// Create and set the normal toolbar image list.
bitmap.LoadBitmap(IDB_NAVIGATE_COLD);
imageList.Create(21, 20, ILC_COLORDDB|ILC_MASK, 6, 1);
imageList.Add(&bitmap, RGB(255,0,255));
m_wndToolBar24Bit.SendMessage(TB_SETIMAGELIST, 0, (LPARAM)imageList.m_hImageList);
imageList.Detach();
bitmap.Detach();

// Create and set the hot toolbar image list.
bitmap.LoadBitmap(IDB_NAVIGATE_HOT);
imageList.Create(21, 20, ILC_COLORDDB|ILC_MASK, 6, 1);
imageList.Add(&bitmap, RGB(255,0,255));
m_wndToolBar24Bit.SendMessage(TB_SETHOTIMAGELIST, 0, (LPARAM)imageList.m_hImageList);
imageList.Detach();
bitmap.Detach();
//repostion the toolbar
this->RecalToolBarPos(this);

return TRUE; // return TRUE unless you set the focus to a control
}
c0der 2003-05-01
  • 打赏
  • 举报
回复
其实你可以模仿多文档或者单文档的模板,很简单就可以实现的
马鸣风萧萧 2003-05-01
  • 打赏
  • 举报
回复
: psusong(爱因思念)
我再OnInitDialog中试过了,还是没有啊!PreCreateWindow、PreSubclassWindow都试了,都没有显示。。怎么回事啊?!!急死我了

您说您有现成的程序?能发给我看看吗?
我的mail: thebesghost@163.com
太感谢您了。。。
GoogleGeek 2003-05-01
  • 打赏
  • 举报
回复
你在OnInitDiallog()中加上上面的代码调用就行了,但是可能会对你的UI显示有影响
你最好自己写一个调整程序

我这边有一个写好了的
马鸣风萧萧 2003-05-01
  • 打赏
  • 举报
回复
: free_card()
我照你的方法做了,在对话框类里增加一个WM_CREATE消息句柄,然后在OnCreate()函数中加入你给我的代码,可是怎么什么都没有啊?

free_card 2003-04-30
  • 打赏
  • 举报
回复
在int Dlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
// ID_INDICATOR_CAPS,
// ID_INDICATOR_NUM,
// ID_INDICATOR_SCRL,
};
if (!m_wndStatusBar.Create(this)//, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM)
|| !m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return FALSE; // fail to create
}

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧