1 创建程序对象
2 创建窗体对象
3 实现Initstance ,MainwinAPP ,mainframe
1 在Onpaint实现
2 DC 设置 获取brush ,绘制尺子
案例
#include "rule.h"
MainWinApp mainapp;
BOOL MainWinApp::InitInstance()
{
m_pMainWnd = new MainFrame();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
//注册消息
BEGIN_MESSAGE_MAP(MainFrame,CFrameWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
//实现窗体
MainFrame::MainFrame()
{
Create(NULL,TEXT("Draw Ruler"));
}
void MainFrame::OnPaint()
{
CPaintDC dc(this);
dc.SetMapMode(MM_LOENGLISH);
dc.SetTextAlign(TA_CENTER|TA_BOTTOM);
CBrush brush(RGB(255,255,0));
CBrush *pbrush = dc.SelectObject(&brush);
dc.Rectangle(100,100,1300,-200);
dc.SelectObject(pbrush);
for (int i = 125; i < 1300; i += 25)
{
dc.MoveTo(i, -192);
dc.LineTo(i, -200);
}
//文本显示
for (int i = 125; i < 1300; i += 100)
{
dc.MoveTo(i, -175);
dc.LineTo(i, -200);
CString string;
string.Format(TEXT("%d"),(i/100)-1);
dc.TextOutA(i,-175,string);
}
}
#ifndef _AFXDLL
#define _AFXDLL
#endif
#include <afx.h>
#include <afxwin.h>
//定义程序对象
class MainWinApp :public CWinApp
{
public :
virtual BOOL InitInstance();
};
//窗体对象‘
class MainFrame:public CFrameWnd
{
public:
MainFrame();
protected:
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP();
};