간단하게 예제로 보면
//원형 시계
//ExClock.c #include <windows.h> #include <stdlib.h> #include <time.h> #define CLOCKTIMER 1 #define CLOCKSIZE 100 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); VOID CALLBACK TimeProc(HWND hwnd,UINT iMsg,UINT wParam,DWORD lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static char szAppName[] = "ExClock"; HWND hwnd; MSG msg; WNDCLASSEX wndclass; int cx,x; wndclass.cbSize = sizeof(wndclass); wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szAppName; wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); RegisterClassEx(&wndclass); //스크린의 가로 크기를 얻는다. cx=GetSystemMetrics(SM_CXFULLSCREEN); x=cx-CLOCKSIZE; hwnd = CreateWindow(szAppName, "원형시계 예제:ExClock", WS_POPUP | WS_VISIBLE, x, 0, CLOCKSIZE, CLOCKSIZE, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, iCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; HBRUSH hBrush,oldBrush; HPEN hPen,oldPen; HRGN rgn; switch(iMsg) { case WM_CREATE: SetTimer(hwnd,CLOCKTIMER,100,(TIMERPROC)TimeProc); rgn=CreateRoundRectRgn(0,0,CLOCKSIZE,CLOCKSIZE,CLOCKSIZE,CLOCKSIZE); SetWindowRgn(hwnd,rgn,FALSE); return 0; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); hBrush=CreateSolidBrush(RGB(0,0,200)); hPen=CreatePen(PS_SOLID,3,RGB(200,200,91)); oldBrush=SelectObject(hdc,hBrush); oldPen=SelectObject(hdc,hPen); RoundRect(hdc,0,0,CLOCKSIZE,CLOCKSIZE,CLOCKSIZE,CLOCKSIZE); SelectObject(hdc,CreateSolidBrush(RGB(0,0,0))); RoundRect(hdc,15,30,85,60,20,20); SelectObject(hdc,oldBrush); SelectObject(hdc,oldPen); DeleteObject(hBrush); DeleteObject(hPen); EndPaint (hwnd, &ps) ; return 0; case WM_DESTROY: KillTimer(hwnd,CLOCKTIMER); PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, iMsg, wParam, lParam); } VOID CALLBACK TimeProc(HWND hwnd,UINT iMsg,UINT wParam,DWORD lParam) { time_t curtime; struct tm cur; char curdate[80]; HDC hdc; time(&curtime); cur=*localtime(&curtime); wsprintf(curdate,"%02d:%02d:%02d",cur.tm_hour,cur.tm_min,cur.tm_sec); hdc=GetDC(hwnd); SetBkColor(hdc,RGB(0,0,0)); SetTextColor(hdc,RGB(255,255,0)); TextOut(hdc,20,37,curdate,strlen(curdate)); ReleaseDC(hwnd,hdc); }