为什么我开始运行这个程序的时候 缺生成不了
#include <afxwin.h>#include <math.h>
class CMyWnd : public CFrameWnd
{
public:
CMyWnd();
protected:
afx_msg void OnPaint();
afx_msg void OnSize(UINT uType, int cx, int cy);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnTimer(UINT_PTR nIdEvent);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
DECLARE_MESSAGE_MAP()
private:
CDC m_memDC;
};
class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance()
{
m_pMainWnd = new CMyWnd;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
m_pMainWnd->SetTimer(10, 1000, NULL);
return TRUE;
}
};
CMyApp myApp;
BEGIN_MESSAGE_MAP(CMyWnd, CFrameWnd)
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_ERASEBKGND()
ON_WM_PAINT()
ON_WM_TIMER()
END_MESSAGE_MAP()
int CMyWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
CDC * pDC = GetDC();
this->m_memDC.CreateCompatibleDC(pDC);
ReleaseDC(pDC);
return 0;
}
BOOL CMyWnd::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}
void CMyWnd::OnSize(UINT uType, int cx, int cy)
{
CBitmap tmp;
CDC * pDC = GetDC();
tmp.CreateCompatibleBitmap(pDC, cx, cy);
m_memDC.SelectObject(&tmp);
tmp.DeleteObject();
CBrush brush(RGB(255,255,255));
m_memDC.FillRect(CRect(0, 0, cx, cy),&brush);
ReleaseDC(pDC);
}
CMyWnd::CMyWnd()
{
Create(NULL, _T ("MFC时钟"));
}
void CMyWnd::OnTimer(UINT_PTR nIdEvent)
{
Invalidate();
}
void CMyWnd::OnPaint()
{
RECT rect;
GetClientRect(&rect);
POINT mid;
mid.x = rect.right / 2;
mid.y = rect.bottom / 2;
int l, t, r, b;
double rr;
if(rect.right > rect.bottom) {
l = (rect.right - rect.bottom) / 2;
t = 0;
r = rect.bottom + l;
b = rect.bottom;
rr = b/2;
} else {
l = 0;
t = (rect.bottom - rect.right) / 2;
r = rect.right;
b = rect.right + t;
rr = r/2;
}
m_memDC.Ellipse(l, t, r, b);
m_memDC.SetPixel(mid.x, mid.y, RGB(0, 0, 0));
const double PI = 4.0 * atan( 1.0 );
const double AG = 180.0 / PI;
POINT p1, p2, p3;
int len;
#pragma warning(push)
#pragma warning(disable:4244)
for(int i = 0; i < 360; i += 6)
{
if(i % 30 == 0)
len = rr/10;
else
len = rr/20;
p1.x = (rr-len)*cos(i/AG) + mid.x;
p1.y = (rr-len)*sin(i/AG) + mid.y;
p2.x = rr*cos(i/AG) + mid.x;
p2.y = rr*sin(i/AG) + mid.y;
m_memDC.MoveTo(p1.x, p1.y);
m_memDC.LineTo(p2.x, p2.y);
}
SYSTEMTIME st;
GetLocalTime(&st);
double h, m, s;
s = st.wSecond;
m = st.wMinute + s/60;
h = st.wHour + m/60;
p1.x = 0.8*rr*cos((s*6-90)/AG) + mid.x;
p1.y = 0.8*rr*sin((s*6-90)/AG) + mid.y;
m_memDC.MoveTo(p1.x, p1.y);
m_memDC.LineTo(mid.x, mid.y);
CRgn rgn1, rgn2;
CBrush br(RGB(0, 0, 0));
p1.x = 0.8*rr*cos((m*6-90)/AG) + mid.x;
p1.y = 0.8*rr*sin((m*6-90)/AG) + mid.y;
p3.x = -0.1*rr*cos((m*6-90)/AG) + mid.x;
p3.y = -0.1*rr*sin((m*6-90)/AG) + mid.y;
p2.x = 0.1*rr*cos((m*6-75)/AG) + mid.x;
p2.y = 0.1*rr*sin((m*6-75)/AG) + mid.y;
m_memDC.BeginPath();
m_memDC.MoveTo(p3.x, p3.y);
m_memDC.LineTo(p2.x, p2.y);
m_memDC.LineTo(p1.x, p1.y);
p2.x = 0.1*rr*cos((m*6-105)/AG) + mid.x;
p2.y = 0.1*rr*sin((m*6-105)/AG) + mid.y;
m_memDC.MoveTo(p3.x, p3.y);
m_memDC.LineTo(p2.x, p2.y);
m_memDC.LineTo(p1.x, p1.y);
m_memDC.EndPath();
rgn1.CreateFromPath(&m_memDC);
p1.x = 0.7*rr*cos((h*30-90)/AG) + mid.x;
p1.y = 0.7*rr*sin((h*30-90)/AG) + mid.y;
p3.x = -0.1*rr*cos((h*30-90)/AG) + mid.x;
p3.y = -0.1*rr*sin((h*30-90)/AG) + mid.y;
p2.x = 0.1*rr*cos((h*30-60)/AG) + mid.x;
p2.y = 0.1*rr*sin((h*30-60)/AG) + mid.y;
m_memDC.BeginPath();
m_memDC.MoveTo(p3.x, p3.y);
m_memDC.LineTo(p2.x, p2.y);
m_memDC.LineTo(p1.x, p1.y);
p2.x = 0.1*rr*cos((h*30-120)/AG) + mid.x;
p2.y = 0.1*rr*sin((h*30-120)/AG) + mid.y;
m_memDC.MoveTo(p3.x, p3.y);
m_memDC.LineTo(p2.x, p2.y);
m_memDC.LineTo(p1.x, p1.y);
m_memDC.EndPath();
rgn2.CreateFromPath(&m_memDC);
(&rgn1, &rgn2, RGN_OR);
m_memDC.FillRgn(&rgn2, &br);
#pragma warning(pop)
CPaintDC(this).BitBlt(rect.left, rect.top, rect.right, rect.bottom, &m_memDC, 0, 0, SRCCOPY);
}