개발자료/MFC&WIN32

SetLocalTime

구룡포과메기 2011. 2. 16. 21:00

원형
BOOL SetLocalTime(CONST SYSTEMTIME *lpSystemTime);

인수
lpSystemTime : 설정할 로컬 시간을 가지고 있는 SYSTEMTIME 구조체

return
성공하면 0이 아닌 값을 리턴하고 실패하면 0을 리턴한다

현재 로컬 시간을 lpSystemTime 구조체가 가진 시간으로 변경

LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
	HDC hdc;
	PAINTSTRUCT ps;
	static SYSTEMTIME old;
	SYSTEMTIME st;
	char str[128];

	switch(iMessage) {
	case WM_CREATE:
		SetTimer(hWnd, 1, 1000, NULL);
		return 0;
	case WM_LBUTTONDOWN:
		GetLocalTime(&old);
		st.wYear=2002;
		st.wMonth=5;
		st.wDay=5;
		st.wHour=5;
		st.wMinute=5;
		st.wSecond=0;
		st.wMilliseconds=0;
		SetLocalTime(&st);
		return 0;
	case WM_RBUTTONDOWN:
		SetLocalTime(&old);
		return 0;
	case WM_TIMER:
		hdc=GetDC(hWnd);
		GetLocalTime(&st);
		wsprintf(str, "%d년 %d월 %d일 %d:%d:%d",
			st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
		TextOut(hdc,10,10,str,lstrlen(str));
		ReleaseDC(hWnd, hdc);
		return 0;
	case WM_PAINT:
		hdc=BeginPaint(hWnd, &ps);
		EndPaint(hWnd, &ps);
		return 0;
	case WM_DESTROY:
		KillTimer(hWnd, 1);
		SetLocalTime(&old);
		PostQuitMessage(0);
		return 0;
	}
	return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}