www.gusucode.com > VC圆形钟表源码,电子钟-源码程序 > VC圆形钟表源码,电子钟-源码程序/code/SZxscxjmView.cpp
//Download by http://www.NewXing.com // SZxscxjmView.cpp : implementation of the CSZxscxjmView class // #include "stdafx.h" #include "SZxscxjm.h" #include "SZxscxjmDoc.h" #include "SZxscxjmView.h" #include <cmath> #define pi 2.0*asin(1.0) #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CSZxscxjmView IMPLEMENT_DYNCREATE(CSZxscxjmView, CView) BEGIN_MESSAGE_MAP(CSZxscxjmView, CView) //{{AFX_MSG_MAP(CSZxscxjmView) ON_WM_TIMER() //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSZxscxjmView construction/destruction CSZxscxjmView::CSZxscxjmView() { // TODO: add construction code here } CSZxscxjmView::~CSZxscxjmView() { } BOOL CSZxscxjmView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CSZxscxjmView drawing void CSZxscxjmView::OnDraw(CDC* pDC) { CSZxscxjmDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here time = CTime::GetCurrentTime(); if(hour>12) { hour=hour-12; } sec = time.GetSecond(); min = time.GetMinute(); hour = time.GetHour(); //画上层透明位图 DrawTransparent(pDC,20,0,RGB(255,255,255)); SetTimer(1,1000,NULL); } ///////////////////////////////////////////////////////////////////////////// // CSZxscxjmView printing BOOL CSZxscxjmView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CSZxscxjmView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CSZxscxjmView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CSZxscxjmView diagnostics #ifdef _DEBUG void CSZxscxjmView::AssertValid() const { CView::AssertValid(); } void CSZxscxjmView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CSZxscxjmDoc* CSZxscxjmView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSZxscxjmDoc))); return (CSZxscxjmDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CSZxscxjmView message handlers void CSZxscxjmView::DrawTransparent(CDC *pDC, int x, int y, COLORREF crColour) { CDC dc,dc1; CBitmap bmp; bmp.LoadBitmap(IDB_BITMAP1); //IDB_BITMAP1是待显示位图的资源ID BITMAP bm;bmp.GetBitmap(&bm); int nWidth=bm.bmWidth,nHeight=bm.bmHeight; dc1.CreateCompatibleDC(pDC); dc.CreateCompatibleDC(pDC); CBitmap* pOldBitmapImage=dc1.SelectObject(&bmp); CBitmap bitmapMask; bitmapMask.CreateBitmap(nWidth, nHeight, 1, 1, NULL); CBitmap* pOldBitmapMask = dc.SelectObject(&bitmapMask); dc1.SetBkColor(crColour);//crColor是位图中的透明色 dc.BitBlt(0, 0, nWidth, nHeight, &dc1, 0, 0, SRCCOPY); pDC->BitBlt(x, y, nWidth, nHeight, &dc1, 0, 0, SRCINVERT); pDC->BitBlt(x, y, nWidth, nHeight, &dc, 0, 0, SRCAND); pDC->BitBlt(x, y, nWidth, nHeight, &dc1, 0, 0, SRCINVERT); //恢复原先设置 dc1.SelectObject(pOldBitmapImage); dc.SelectObject(pOldBitmapMask); } void CSZxscxjmView::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default CDC *pDC=this->GetDC(); CRect m_rect; this->GetClientRect(m_rect); CRgn rgn; HRGN m_hrgn; m_hrgn = ::CreateEllipticRgn(64,40,186,165); rgn.Attach(m_hrgn); CBrush m_brush (1,RGB(255,255,255)); pDC->SelectClipRgn(&rgn,0); pDC->FillRgn(&rgn,&m_brush); int x=120; int y=100; pDC->MoveTo (x,y); pDC->LineTo (x+(long)55*cos(pi/2-2*pi*sec/60.0),y-(long)55*sin(pi/2-2*pi*sec/60.0)); pDC->MoveTo (x,y); pDC->LineTo (x+(long)45*cos(pi/2-2*pi*min/60.0),y-(long)45*sin(pi/2-2*pi*min/60.0)); pDC->MoveTo (x,y); pDC->LineTo (x+(long)35*cos(pi/2-5*2*pi*hour/60.0),y-(long)35*sin(pi/2-5*2*pi*hour/60.0)); sec = sec+1; if(sec==60) { sec=0; min=min+1; if(min==60) { min=0; hour=hour+1; } } CView::OnTimer(nIDEvent); }