BCGControlBar使用(九)
狀態欄的使用
StatusBarDemo
const int nStatusIcon = 0;
const int nStatusInfo = 1;
const int nStatusProgress = 2;
const int nStatusLabel = 3;
const int nStatusAnimation = 4;
?
static UINT indicators[] =
{
?ID_INDICATOR_ICON,??// status icon
?ID_SEPARATOR,?????????? // status line indicator
?ID_INDICATOR_PROGRESS,?// progress bar
?ID_INDICATOR_LABEL,??// text label
?ID_INDICATOR_ANIMATION,?// animation pane
?ID_INDICATOR_CAPS,
?ID_INDICATOR_NUM,
?ID_INDICATOR_SCRL,
};
?
CMainFrame::OnCreate
?if (!m_wndStatusBar.Create(this) ||
??!m_wndStatusBar.SetIndicators(indicators,
??? sizeof(indicators)/sizeof(UINT)))
?{
??TRACE0("Failed to create status bar\n");
??return -1;????? // fail to create
?}
?m_wndStatusBar.SetPaneStyle (nStatusIcon, SBPS_NOBORDERS);
?m_wndStatusBar.SetPaneStyle (nStatusAnimation, SBPS_NOBORDERS);
?m_wndStatusBar.SetPaneStyle (nStatusInfo, SBPS_STRETCH | SBPS_NOBORDERS);
?m_wndStatusBar.SetPaneWidth (nStatusProgress, 80);
?m_wndStatusBar.EnablePaneDoubleClick ();
?
?
?CBCGPStatusBar& GetStatusBar () const
?{
??return ((CMainFrame*) AfxGetMainWnd ())->GetStatusBar ();
?}
?
void CStatusBarDemoView::OnInitialUpdate()
{
?CFormView::OnInitialUpdate();
?m_wndTextColor.EnableAutomaticButton (_T("Default"), globalData.clrBtnText);
?m_wndTextColor.EnableOtherButton (_T("Other..."));
?m_wndTextColor.SetColor ((COLORREF)-1);
?m_wndBackColor.EnableAutomaticButton (_T("Default"), globalData.clrBtnFace);
?m_wndBackColor.EnableOtherButton (_T("Other..."));
?m_wndBackColor.SetColor ((COLORREF)-1);
?if (m_imlStatusAnimation.GetSafeHandle () == NULL)//m_imlStatusAnimation為CImageList
?{
??m_imlStatusAnimation.Create (IDB_ANIMATION, 16, 0, RGB (255, 0, 255));
?}
?const UINT uiLoadImageFlags = LR_CREATEDIBSECTION | LR_LOADMAP3DCOLORS;
?if (m_bmpIcon1.GetSafeHandle () == NULL)
?{
??HBITMAP hbmp = (HBITMAP) ::LoadImage (
???AfxGetResourceHandle (),
???MAKEINTRESOURCE(IDB_ICON1),
???IMAGE_BITMAP,
???0, 0,
???uiLoadImageFlags);
??m_bmpIcon1.Attach (hbmp);
?}
?if (m_bmpIcon2.GetSafeHandle () == NULL)
?{
??HBITMAP hbmp = (HBITMAP) ::LoadImage (
???AfxGetResourceHandle (),
???MAKEINTRESOURCE(IDB_ICON2),
???IMAGE_BITMAP,
???0, 0,
???uiLoadImageFlags);
??m_bmpIcon2.Attach (hbmp);
?}
?GetStatusBar ().SetPaneIcon (nStatusIcon, m_bmpIcon1);
?GetStatusBar ().SetTipText (nStatusIcon, _T("This is a tooltip"));//圖標的提示
}
void CStatusBarDemoView::OnStartProgress()
{
?if (m_bInProgress)
?{
??KillTimer (ID_PROGRESS_TIMER);
??m_wndStartProgress.SetWindowText (_T("Start Progress"));
??GetStatusBar ().EnablePaneProgressBar (nStatusProgress, -1);
??m_bInProgress = FALSE;
??return;
?}
?GetStatusBar ().EnablePaneProgressBar (nStatusProgress, PROGRESS_MAX);
?m_nProgressCurr = 0;
?m_bInProgress = TRUE;
?SetTimer (ID_PROGRESS_TIMER, 200, NULL);
?m_wndStartProgress.SetWindowText (_T("Stop Progress"));
}
void CStatusBarDemoView::OnStartAnimation()
{
?if (m_bInAnimation)
?{
??m_wndStartAnimation.SetWindowText (_T("Start Animation"));
??GetStatusBar ().SetPaneAnimation (nStatusAnimation, NULL);
??m_bInAnimation = FALSE;
??return;
?}
?GetStatusBar ().SetPaneAnimation (nStatusAnimation, m_imlStatusAnimation);
?GetStatusBar ().SetPaneText (nStatusAnimation, _T(""));
?GetStatusBar ().SetPaneWidth (nStatusAnimation, 16);
?m_wndStartAnimation.SetWindowText (_T("Stop Animation"));
?m_bInAnimation = TRUE;
}
void CStatusBarDemoView::OnIcon()
{
?UpdateData ();
?GetStatusBar ().SetPaneIcon (nStatusIcon, m_nIcon == 0 ? m_bmpIcon1 : m_bmpIcon2);
}
void CStatusBarDemoView::OnBackColor()
{
?GetStatusBar ().SetPaneBackgroundColor (nStatusLabel, m_wndBackColor.GetColor ());
}
void CStatusBarDemoView::OnTextColor()
{
?GetStatusBar ().SetPaneTextColor (nStatusLabel, m_wndTextColor.GetColor ());
}
void CStatusBarDemoView::OnIndicatorLabel()
//ID_INDICATOR_LABEL("Simple text")的響應函數
{
?MessageBox (_T("Status bar pane double-click..."));
}
void CStatusBarDemoView::OnTimer(UINT_PTR nIDEvent)
{
?if (nIDEvent == ID_PROGRESS_TIMER)
?{
??m_nProgressCurr += 5;
??if (m_nProgressCurr > PROGRESS_MAX)
??{
???m_nProgressCurr = 0;
??}
??GetStatusBar ().SetPaneProgress (nStatusProgress, m_nProgressCurr);
?}
?
?CFormView::OnTimer(nIDEvent);
}
總結
以上是生活随笔為你收集整理的BCGControlBar使用(九)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 手握五大成功秘密武器
- 下一篇: 再谈 查询长期未登录AD的用户