您的位置:首页 > 其它

加载状态栏

2016-04-15 10:30 465 查看
1.定义结构体:

static UINT BASED_CODE indicators[] =
{

ID_SEPARATOR,           // status line Indicator
ID_INDICATOR_POS,        //  Cursor Position Indicator
ID_INDICATOR_OBJSIZE,    //  Cursor Position Indicator
ID_INDICATOR_CAPS,        // Caps Lock Indicator
ID_INDICATOR_NUM,        // Num Lock Indicator
ID_INDICATOR_SCRL,        // Scroll Lock Indicator
ID_INDICATOR_CLOCK,        // Clock Indicator
ID_INDICATOR_PAPER_SIZE,//page size
};


2.加载指示器

CStatusBar  m_wndStatusBar;
m_wndStatusBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM | CBRS_TOOLTIPS);
m_wndStatusBar.SetIndicators(indicators,sizeof(indicators)/sizeof(UINT));


3.添加相关文本

CRect RectTemp;
GetClientRect(RectTemp);
int nLength;
nLength=0;
nLength=abs(RectTemp.right-RectTemp.left);
for(int k=0; k<=7; k++)
{
UINT nID,nStyle;
int nWidth;
m_wndStatusBar.GetPaneInfo(k, nID, nStyle, nWidth);
m_wndStatusBar.SetPaneInfo(k, nID, nStyle, nLength/8);
m_wndStatusBar.SetPaneText(k,"Test");
}
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
m_wndStatusBar.ShowWindow(SW_SHOW);


 

单文档和多文档程序默认加载状态栏

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;

if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("未能创建工具栏\n");
return -1;      // 未能创建
}

if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("未能创建状态栏\n");
return -1;      // 未能创建
}

// TODO: 如果不需要工具栏可停靠,则删除这三行
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);

return 0;
}


修改

void CDrawView::OnMouseMove(UINT nFlags, CPoint point)
{
CString CursorPos;
CString tmpstr = "X= -XXX   Y= -YYY";
CPoint curPoint(point);
ClientToDoc(curPoint);
CursorPos.Format("x= %-4d   y= %-4d", curPoint.x, curPoint.y);
CStatusBar *pStatusBar = (CStatusBar *)((CMainFrame *)(AfxGetApp()->m_pMainWnd))->GetDescendantWindow(AFX_IDW_STATUS_BAR);

if (pStatusBar == NULL)
return;

UINT nIDPos;
UINT nStylePos;
int nWidth;

CClientDC dc(pStatusBar);
CFont* pOldFont = dc.SelectObject(pStatusBar->GetFont());
CSize szExtent  = dc.GetTextExtent(tmpstr);
dc.SelectObject(pOldFont);
int nIndexPos = pStatusBar->CommandToIndex(ID_INDICATOR_POS);

pStatusBar->GetPaneInfo(nIndexPos, nIDPos, nStylePos, nWidth);
pStatusBar->SetPaneInfo(nIndexPos, nIDPos, nStylePos, szExtent.cx);
pStatusBar->SetPaneText(nIndexPos,CursorPos);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: