
求MFC 模拟时钟 代码
1个回答
2013-08-06
展开全部
#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;
}
#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;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询