Windows Mobile上實現絢麗時鐘效果

來源:互聯網
上載者:User

利用上篇的文章《Windows Mobile上實現圖片任意角度旋轉》,可以實現效果非常絢麗的始終效果。每個始終我們需要三張圖片,鐘盤、時針、分針三張png圖片。

如:

 

 

 

 

圖片是從android中取出的。

實現代碼如下:

void DrawClock(HDC hdc, RECT rc)<br />{<br />SYSTEMTIME systemTime;</p><p>GetLocalTime(&systemTime);</p><p>IImage *pCurClockHour = NULL;<br />IImage *pCurClockMin = NULL;<br />ImageInfo imDialInfo;<br />ImageInfo imHourInfo;<br />ImageInfo imMinInfo;</p><p>LPBYTEpHourBuf = NULL;<br />LPBYTE pMinBuf = NULL;<br />POINT ptClockCenter;<br />RECT rcDial;<br />RECT rcHour;<br />RECT rcMin;</p><p>GetClientRect(g_hWnd, &rc);</p><p>HDC hdcOffSet = CreateCompatibleDC(hdc);<br />HBITMAP hbmpOffset = CreateCompatibleBitmap(hdc, rc.right - rc.left, rc.bottom - rc.top);<br />SelectObject(hdcOffSet, hbmpOffset);<br />FillRect(hdcOffSet, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH));<br />// Load the image from the JPG file.</p><p>if(pClockDial == NULL)<br />pImgFactory->CreateImageFromFile(TEXT("//clockgoog_dial.png"),&pClockDial);<br />if(pClockHour == NULL)<br />pImgFactory->CreateImageFromFile(TEXT("//clockgoog_hour.png"),&pClockHour);<br />if(pClockMin == NULL)<br />pImgFactory->CreateImageFromFile(TEXT("//clockgoog_minute.png"),&pClockMin);</p><p>/*<br />if(pClockDial == NULL)<br />pImgFactory->CreateImageFromFile(TEXT("//clockdroid2_dial.png"),&pClockDial);<br />if(pClockHour == NULL)<br />pImgFactory->CreateImageFromFile(TEXT("//clockdroid2_hour.png"),&pClockHour);<br />if(pClockMin == NULL)<br />pImgFactory->CreateImageFromFile(TEXT("//clockdroid2_minute.png"),&pClockMin);<br />*/<br />pClockDial->GetImageInfo(&imDialInfo);<br />rcDial.left = ((rc.right - rc.left) - imDialInfo.Width)/2 + rc.left;<br />rcDial.top = ((rc.bottom - rc.top) - imDialInfo.Height)/2 + rc.top;<br />rcDial.right = rcDial.left + imDialInfo.Width;<br />rcDial.bottom = rcDial.top + imDialInfo.Height;</p><p>ptClockCenter.x = rcDial.left + imDialInfo.Width/2;<br />ptClockCenter.y = rcDial.top + imDialInfo.Height/2;</p><p>RotateImage(pImgFactory, pClockHour, pCurClockHour, pHourBuf, systemTime.wHour * 6 *3.14/180);<br />RotateImage(pImgFactory, pClockMin, pCurClockMin, pMinBuf, (systemTime.wMinute * 6 + systemTime.wSecond/10) *3.14/180);</p><p>pCurClockHour->GetImageInfo(&imHourInfo);<br />pCurClockMin->GetImageInfo(&imMinInfo);</p><p>rcHour.left = ptClockCenter.x - imHourInfo.Width/2;<br />rcHour.right = rcHour.left + imHourInfo.Width;<br />rcHour.top = ptClockCenter.y - imHourInfo.Height/2;<br />rcHour.bottom = rcHour.top + imHourInfo.Height;</p><p>rcMin.left = ptClockCenter.x - imMinInfo.Width/2;<br />rcMin.right = rcMin.left + imMinInfo.Width;<br />rcMin.top = ptClockCenter.y - imMinInfo.Height/2;<br />rcMin.bottom = rcMin.top + imMinInfo.Height;</p><p>pClockDial->Draw(hdcOffSet, &rcDial, NULL);<br />pCurClockHour->Draw(hdcOffSet, &rcHour, NULL);<br />pCurClockMin->Draw(hdcOffSet, &rcMin, NULL);</p><p>pCurClockHour->Release();<br />pCurClockMin->Release();</p><p>delete pHourBuf;<br />delete pMinBuf;<br />BitBlt(hdc, rc.left,rc.top, rc.right-rc.left, rc.bottom - rc.left, hdcOffSet, 0,0,SRCCOPY);</p><p>DeleteDC(hdcOffSet);<br />DeleteObject(hbmpOffset);<br />}

 

最終效果:

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.