LuvSea
키 입력과 무효 영역 본문
#include<windows.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hInst;
LPCTSTR lpszClass=TEXT("first");
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevlnstance, 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 IParam)
{
HDC hdc;
PAINTSTRUCT ps;
static TCHAR str[256];
int len=0;
static int x = 100;
static int y = 100;
switch(iMessage)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_KEYDOWN:
switch(WParam){
case VK_UP:
y-=15;
break;
case VK_DOWN:
y+=15;
break;
case VK_LEFT:
x-=15;
break;
case VK_RIGHT:
x+=15;
break;
}
//무효영역
InvalidateRect(hWnd,NULL,FALSE); // 덧붙이기
//InvalidateRect(hWnd,NULL,TRUE); 전체 갱신
return 0;
case WM_PAINT:
hdc = BeginPaint(hWnd,&ps);
TextOut(hdc,x,y,"A",1);
EndPaint(hWnd,&ps);
return 0;
}
return(DefWindowProc(hWnd,iMessage,WParam,IParam));
}
'sTudy' 카테고리의 다른 글
타이머를 이용한 애니메이션 (0) | 2009.07.06 |
---|---|
타이머를 이용한 시계 (0) | 2009.07.06 |
Message Box (0) | 2009.07.06 |
직선, 원, 사각형 그리기 (0) | 2009.07.06 |
API 기본 출력 소스 (0) | 2009.07.06 |