一、静态成员的使用,如下例所示:
class Point
{
public:
void output()
{
x = 0;
y = 0; //静态成员变量
init(); //静态成员函数因为已经有内存空间所以可以调用
}
static void init()
{
// x = 0;
// y = 0; 静态成员函数只能访问静态成员变量
}
private:
static int x,y;
};
int x = 0; //静态成员初始化要在类外边
int y = 0; //静态成员初始化要带类型
void main()
{
// Point pt;
// pt.init();
// pt.output();
Point::init(); //类的静态成员函数可以直接调用
// Point::output(); 类的成员函数不能直接调用
}
二、图形的简单绘制
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
/* CWindowDC dc(this);
// CWindowDC dc(GetParent());
CWindowDC dc(GetDesktopWindow()); 桌面窗口
dc.MoveTo(m_pOrigin);
dc.LineTo(point);
CView::OnLButtonUp(nFlags, point); */
/* CDC *pdc = GetDC();
pdc->MoveTo(m_pOrigin);
pdc->LineTo(point);
ReleaseDC(pdc); */
/* HDC hdc = ::GetDC(m_hWnd);
MoveToEx(hdc,m_pOrigin.x,m_pOrigin.y,&m_pOrigin);
LineTo(hdc,point.x,point.y);
::ReleaseDC(m_hWnd,hdc); */
/* CClientDC dc(this); view窗口
// CClientDC dc(GetParent()); mainframe窗口
dc.MoveTo(m_pOrigin);
dc.LineTo(point); */
/* CClientDC dc(this);
CPen pen(PS_SOLID,1,RGB(255,0,0));
CPen *pOldpen = dc.SelectObject(&pen); //画笔
// dc.MoveTo(m_pOrigin);
// dc.LineTo(point);
dc.Rectangle(CRect(m_pOrigin,point));
dc.SelectObject(pOldpen); */
/* CClientDC dc(this);
CBrush *brush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH)); //透明画刷
CBrush *pOldBrush = dc.SelectObject(brush);
dc.Rectangle(CRect(m_pOrigin,point));
dc.SelectObject(pOldBrush); */
CClientDC dc(this);
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP1);
CBrush Brush(&bitmap);
dc.FillRect(CRect(m_pOrigin,point),&Brush); //以位图填充
}