LuvSea
타이머를 이용한 시계 본문
#include<windows.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hInst;
LPCTSTR lpszClass=TEXT("My Timer");
// WinMain 시작
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevlnstance, LPSTR lpszCmdParam, int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
g_hInst=hInstance;
// 1. 윈도우 속성값 등록
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=WndProc;
WndClass.lpszClassName=lpszClass;
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW|CS_VREDRAW;
RegisterClass(&WndClass); // 주소에 Write
// 2. 윈도우 생성
hWnd=CreateWindow(lpszClass,lpszClass,WS_OVERLAPPEDWINDOW
,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,
(HMENU)NULL,hInstance,NULL);
ShowWindow(hWnd,nCmdShow); // 화면에 뿌려줌
// 3. 메세지 처리 (무한반복)
while(GetMessage(&Message,NULL,0,0))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return (int)Message.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM IParam)
{
HDC hdc;
PAINTSTRUCT ps;
SYSTEMTIME st;
static TCHAR sTime[128];
static RECT rt = { 100, 100, 400, 120};
switch(iMessage)
{
case WM_CREATE:
SetTimer(hWnd, 1, 1000, NULL);
return 0;
case WM_TIMER:
GetLocalTime(&st);
wsprintf(sTime, TEXT("지금시간은 %d : %d : %d 입니다"), st.wHour, st.wMinute, st.wSecond);
InvalidateRect(hWnd, &rt, TRUE);
return 0;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
TextOut(hdc, 100, 100, sTime, lstrlen(sTime));
EndPaint(hWnd, &ps);
return 0;
case WM_DESTROY:
KillTimer(hWnd,1);
PostQuitMessage(0);
return 0;
}
return(DefWindowProc(hWnd,iMessage,wParam,IParam));
}
'sTudy' 카테고리의 다른 글
작업영역 (0) | 2009.07.06 |
---|---|
타이머를 이용한 애니메이션 (0) | 2009.07.06 |
키 입력과 무효 영역 (0) | 2009.07.06 |
Message Box (0) | 2009.07.06 |
직선, 원, 사각형 그리기 (0) | 2009.07.06 |