#include#include #ifndef ULONG_PTR #define ULONG_PTR DWORD #endif #include using namespace Gdiplus; #pragma comment(lib, "Gdiplus.lib") #include "resource.h" void DrawTime(HDC hdc) { WCHAR SlideText[64]; SYSTEMTIME st = {sizeof(st)}; GetLocalTime(&st); Graphics graphics(hdc); FontFamily fontFamily(L"Times New Roman"); Font font(&fontFamily, 24, FontStyleRegular, UnitPixel); SolidBrush brush(Color(255, 0, 255, 0)); wsprintfW(SlideText, L"%04d/%02d/%02d 星期 %d %02d:%02d:%02d BJT", st.wYear, st.wMonth, st.wDay, st.wDayOfWeek, st.wHour, st.wMinute, st.wSecond); graphics.DrawString(SlideText, wcslen(SlideText), &font, PointF(400.0, 300.0), &brush); } // 定义三个基本的函数 LRESULT WINAPI ScreenSaverProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hDC; RECT rc; static UINT timerID; GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; // Initialize GDI+. GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); // 定时器 switch(message) { case WM_CREATE: timerID = SetTimer(hWnd, 1, 1000, NULL); // 设置定时器 break; case WM_ERASEBKGND: //空操作,交由DefScreenSaverProc处理 break; case WM_TIMER: hDC = GetDC(hWnd); // 清屏 SetRect(&rc, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); FillRect(hDC,&rc,(HBRUSH)GetStockObject(BLACK_BRUSH)); DrawTime(hDC); ReleaseDC(hWnd, hDC); break; case WM_DESTROY: KillTimer(hWnd, timerID);// 删除定时器 PostQuitMessage(0); return 0; default: return DefScreenSaverProc(hWnd, message, wParam, lParam); } GdiplusShutdown(gdiplusToken); return FALSE; } BOOL WINAPI ScreenSaverConfigureDialog(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch ( message ) { case WM_INITDIALOG: SendMessage(hWnd,WM_SETICON,ICON_BIG,(LPARAM)LoadIcon((HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE),MAKEINTRESOURCE(ID_APP))); SendMessage(hWnd,WM_SETICON,ICON_SMALL,(LPARAM)LoadIcon((HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE),MAKEINTRESOURCE(ID_APP))); return TRUE; case WM_COMMAND: if(LOWORD(wParam) == IDOK) { EndDialog(hWnd, LOWORD(wParam)); return TRUE; } break; } return FALSE; } BOOL WINAPI RegisterDialogClasses(HANDLE hInstance) {//一般不需要,仅返回TRUE return TRUE; }
欢迎光临 黑色海岸线论坛 (http://bbs.thysea.com/) | Powered by Discuz! 7.2 |