티스토리 뷰
// 원이 이동하는 프로그램///
//엔터를 누를시 스타트//
//스페이스를 누를시 정지//
// 이동시 X,Y좌료를 출력//
#include <windows.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hInst;
LPCTSTR lpszClass=TEXT("First");
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,700,
NULL,(HMENU)NULL,hInstance,NULL);
ShowWindow(hWnd,nCmdShow);
while (GetMessage(&Message,NULL,0,0)) {
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return (int)Message.wParam;
}
#define START 1;
#define STOP 2;
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
static int x=0,y=50,v=300,z=500;
//static int nx1=0,xy1=40,nx2=20,ny2=60;
RECT rt={100,600,100,700};
static TCHAR Tvew[128];
HPEN hpen;
static select;
switch (iMessage) {
case WM_KEYDOWN:
switch(wParam)
{
case VK_RETURN:
SetTimer(hWnd,1,10,NULL);
SendMessage(hWnd,WM_TIMER,1,0);
select=START;
break;
case VK_SPACE:
KillTimer(hWnd,1);
break;
}
case WM_TIMER:
InvalidateRect(hWnd,NULL,TRUE);
UpdateWindow(hWnd);
wsprintf(Tvew,TEXT("%d %d %d %d"),x,v,y,z);
switch(select)
{
case 1:
x+=5;
y+=5;
if(y==700)
{
select=2;
}
break;
case 2:
x-=5;
y-=5;
if(x==0)
{
select=2;
}
break;
}
return 0;
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
hpen=CreatePen(PS_SOLID,2,RGB(255,0,0));
SelectObject(hdc,hpen);
TextOut(hdc,10,10,Tvew,lstrlen(Tvew));
Ellipse(hdc,x,300,y,350);
EndPaint(hWnd,&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}