mystatusbar.cpp
来自「故障诊断工作涉及的领域相当广泛」· C++ 代码 · 共 231 行
CPP
231 行
// MyStautsBar.cpp : implementation file
//
#include "stdafx.h"
#include "Cad.h"
#include "MyStatusBar.h"
#include "CadDoc.h"
#include "CadView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyStatusBar
CMyStatusBar::CMyStatusBar()
{
}
CMyStatusBar::~CMyStatusBar()
{
}
BEGIN_MESSAGE_MAP(CMyStatusBar, CStatusBar)
ON_WM_LBUTTONDBLCLK()
//{{AFX_MSG_MAP(CMyStatusBar)
ON_WM_TIMER()
ON_WM_CREATE()
// ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyStatusBar message handlers
#define ID_STATUS 0
#define ID_MOUSE 1
#define ID_SNAP 2
#define ID_GRID 3
#define ID_ORTHO 4
static UINT indicators[] =
{
ID_SEPARATOR, //ID_STATUS
ID_SEPARATOR, //ID_MOUSE
ID_SEPARATOR, //ID_SNAP
ID_SEPARATOR, //ID_GRID
ID_SEPARATOR, //ID_ORTHO
};
void CMyStatusBar::OnLButtonDblClk(UINT nFlags, CPoint point)
{
int nIsRedraw=0;
CRect rect;
COLORREF crBackground,crText;
GetItemRect(ID_SNAP,rect);
if(rect.PtInRect(point))
{
g_bSnap=!g_bSnap;
if(g_bSnap)
crText=RGB(0,0,0);
else
crText=RGB(128,128,128);
nIsRedraw=ID_SNAP;
}
if(nIsRedraw==FALSE)
{
GetItemRect(ID_GRID,rect);
if(rect.PtInRect(point))
{
g_bGrid=!g_bGrid;
if(g_bGrid)
crText=RGB(0,0,0);
else
crText=RGB(128,128,128);
nIsRedraw=ID_GRID;
CDC* pDC=g_pCurView->GetDC();
g_pCurView->DrawGrid(pDC);
}
}
if(nIsRedraw==FALSE)
{
GetItemRect(ID_ORTHO,rect);
if(rect.PtInRect(point))
{
g_bOrtho=!g_bOrtho;
if(g_bOrtho)
crText=RGB(0,0,0);
else
crText=RGB(128,128,128);
nIsRedraw=ID_ORTHO;
}
}
//检查是否需要重画
if(nIsRedraw==FALSE) return;
CDC* pDC=GetDC();
//设置文本和背景颜色
crBackground=pDC->GetPixel(rect.left+1,rect.top+1);
pDC->SetBkColor(crBackground);
pDC->SetTextColor(crText);
rect.left+=3;
rect.top+=2;
rect.right-=3;
rect.bottom-=2;
switch(nIsRedraw)
{
case ID_SNAP:
pDC->ExtTextOut(rect.left+3,rect.top,ETO_OPAQUE,rect,"SNAP",4,NULL);
break;
case ID_GRID:
pDC->ExtTextOut(rect.left+3,rect.top,ETO_OPAQUE,rect,"GRID",4,NULL);
break;
case ID_ORTHO:
pDC->ExtTextOut(rect.left+3,rect.top,ETO_OPAQUE,rect,"ORTHO",5,NULL);
break;
default:
break;
}
}
int CMyStatusBar::Init(CWnd* pMainWnd)
{
if (!Create(pMainWnd) ||
!SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
//设置状态条窗格的宽度
SetPaneInfo(0,ID_SEPARATOR,ID_STATUS,360);
SetPaneInfo(1,ID_SEPARATOR,ID_MOUSE,120);
SetPaneInfo(2,ID_SEPARATOR,ID_SNAP,42);
SetPaneInfo(3,ID_SEPARATOR,ID_GRID,40);
SetPaneInfo(4,ID_SEPARATOR,ID_ORTHO,52);
SetTimer(1,500,NULL);
return 1;
}
void CMyStatusBar::OnTimer(UINT nIDEvent)
{
static int nCount=0;
m_progress.StepIt();
if(++nCount==10)
{
nCount=0;
m_progress.SetPos(0);
KillTimer(1);
m_progress.MoveWindow(CRect(0,0,0,0));
}
}
int CMyStatusBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CStatusBar::OnCreate(lpCreateStruct) == -1)
return -1;
m_progress.Create(WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,100);
m_progress.SetRange(0,10);
m_progress.SetPos(0);
m_progress.SetStep(1);
return 0;
}
void CMyStatusBar::Redraw()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect rect;
COLORREF crBackground,crText;
//设置文本和背景颜色
crBackground=GetSysColor(COLOR_MENU);
dc.SetBkColor(crBackground);
GetItemRect(ID_SNAP,rect);
rect.left+=3;
rect.top+=2;
rect.right-=3;
rect.bottom-=2;
if(g_bSnap)
crText=RGB(0,0,0);
else
crText=RGB(128,128,128);
dc.SetTextColor(crText);
dc.ExtTextOut(rect.left+3,rect.top,ETO_OPAQUE,rect,"SNAP",4,NULL);
GetItemRect(ID_GRID,rect);
rect.left+=3;
rect.top+=2;
rect.right-=3;
rect.bottom-=2;
if(g_bGrid)
crText=RGB(0,0,0);
else
crText=RGB(128,128,128);
dc.SetTextColor(crText);
dc.ExtTextOut(rect.left+3,rect.top,ETO_OPAQUE,rect,"GRID",4,NULL);
GetItemRect(ID_ORTHO,rect);
rect.left+=3;
rect.top+=2;
rect.right-=3;
rect.bottom-=2;
if(g_bOrtho)
crText=RGB(0,0,0);
else
crText=RGB(128,128,128);
dc.SetTextColor(crText);
dc.ExtTextOut(rect.left+3,rect.top,ETO_OPAQUE,rect,"ORTHO",5,NULL);
// Do not call CFrameWnd::OnPaint() for painting messages
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?