//Ruler.h头文件的
class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance ();
};
class CMainWindow : public CFrameWnd
{
public:
CMainWindow ();
protected:
afx_msg void OnPaint ();
DECLARE_MESSAGE_MAP ()
};
//.cpp的
#include <afxwin.h>
#include "Ruler.h"
CMyApp myApp;
/
// CMyApp member functions
BOOL CMyApp::InitInstance ()
{
m_pMainWnd = new CMainWindow;
m_pMainWnd->ShowWindow (m_nCmdShow);
m_pMainWnd->UpdateWindow ();
return TRUE;
}
/
// CMainWindow message map and member functions
BEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd)
ON_WM_PAINT ()
END_MESSAGE_MAP ()
CMainWindow::CMainWindow ()
{
Create (NULL, _T ("Ruler"));
}
void CMainWindow::OnPaint ()
{
CPaintDC dc (this);
dc.SetMapMode (MM_LOENGLISH);//设定模式
dc.SetTextAlign (TA_CENTER | TA_BOTTOM);
dc.SetBkMode (TRANSPARENT);//背景模式设为透明,所以背景是原来的背景色!!!
CBrush brush (RGB(255,255,0));
CBrush *OldBrush = dc.SelectObject(&brush);
dc.Rectangle(100,-100,1300,-200);
dc.SelectObject(OldBrush);
int i;
for( i=125;i<1300;i+=25)
{
//为什么从下面 画到 上面就会出界
/*
dc.MoveTo(i,-200);
dc.LineTo(i,-195);
*/
dc.MoveTo(i,-190);
dc.LineTo(i,-200);
}
for(i=150;i<1300;i+=50)
{
dc.MoveTo(i,-180);
dc.LineTo(i,-200);
}
char ch[256];
for(i=200;i<1300;i+=100)
{
dc.MoveTo(i,-170);
dc.LineTo(i,-200);
wsprintf(ch,"%d",(i/100)-1);
dc.TextOut(i,-170,ch);//三个参数分别为:横坐标,纵坐标,输出的字符串内容
/*
书上的模式
CString string;
string.Format (_T ("%d"), (i / 100) - 1);
dc.TextOut (i, -175, string);
*/
}
}
MFC学习笔记(二)
第二章的学习的一些代码总结