전에 API로 작업한 마우스좌표와 타이머의 내용을
메시지맵으로 구현한것 임.(간단 명료 ㅋㅋ)
#include<windows.h>
#define dim(x) (sizeof(x) / sizeof(x[0]))
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hInst;
LPCTSTR lpszClass=TEXT("First");
LRESULT MOUSEMOVE(HWND, UINT, WPARAM, LPARAM);
LRESULT LBUTTONUP(HWND, UINT, WPARAM, LPARAM);
LRESULT DESTROY(HWND, UINT, WPARAM, LPARAM);
struct decodeUINT
{
UINT Code;
LRESULT (*Fxn)(HWND, UINT, WPARAM, LPARAM);
};
const struct decodeUINT MainMessages[] = {
WM_MOUSEMOVE, MOUSEMOVE,
WM_LBUTTONUP, LBUTTONUP,
WM_DESTROY, DESTROY
};
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance
,LPSTR lpszCmdParam,int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
g_hInst = hInstance;
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);
hWnd=CreateWindow(lpszClass,lpszClass,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL,(HMENU)NULL,hInstance,NULL);
ShowWindow(hWnd,nCmdShow);
while(GetMessage(&Message,NULL,0,0)){
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return (int)Message.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
int i;
for(i = 0; i < dim(MainMessages); i++)
{
if(iMessage == MainMessages[i].Code)
{
return (*MainMessages[i].Fxn)(hWnd, iMessage, wParam, lParam);
}
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
LRESULT MOUSEMOVE(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
TCHAR str[128];
SYSTEMTIME st;
GetLocalTime(&st);
wsprintf(str,TEXT("X = %d. Y = %d. %d시 %d분 %d초"),LOWORD(lParam),HIWORD(lParam),
st.wHour, st.wMinute,st.wSecond);
SetWindowText(hWnd,str);
return 0;
}
LRESULT LBUTTONUP(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
static int x;
static int y;
hdc = GetDC(hWnd);
MoveToEx(hdc,x,y,NULL);
x = LOWORD(lParam);
y = HIWORD(lParam);
LineTo(hdc,x,y);
ReleaseDC(hWnd,hdc);
return 0;
}
LRESULT DESTROY(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
PostQuitMessage(0);
return 0;
}