其实不用处理WM_SIZE消息,但是为了练习,加上了:
头文件:
class CMyApp : public CWinApp {
virtual BOOL InitInstance();
};
class CMainWindow : public CFrameWnd {
public:
CMainWindow();
protected:
static const int num = 1000;
POINT pt[num];
int cxClient, cyClient;
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};
|
cpp:
#include <afxwin.h>
#include <math.h>
#include "sina.h"
CMyApp myApp;
BOOL CMyApp::InitInstance() {
m_pMainWnd = new CMainWindow;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
BEGIN_MESSAGE_MAP(CMainWindow, CFrameWnd)
ON_WM_SIZE()
ON_WM_PAINT()
END_MESSAGE_MAP()
CMainWindow::CMainWindow() {
Create(NULL, "看我来画正弦曲线曲线曲线!");
}
void CMainWindow::OnSize(UINT nType,
int cx,
int cy) {
cxClient = cx;
cyClient = cy;
}
void CMainWindow::OnPaint() {
CPaintDC dc(this);
dc.MoveTo(0, cyClient / 2);
dc.LineTo(cxClient, cyClient / 2);
for(int i = 0; i < num; i++) {
pt[i].x = i * cxClient / num;
pt[i].y = cyClient / 2 - (cyClient / 2) * sin(2 * 3.14159 * i / num);
}
dc.Polyline(pt, num);
}
|
运行结果:
阅读(1448) | 评论(0) | 转发(0) |