여기는 저의 2004~2007년까지의 기록입니다. 이 블로그는 이제 Tistory로 옮겼습니다.
2008년부터의 기록은 http://blog.studioego.info 로 가시기 바랍니다.

StudioEgo's Thoughts, seasonⅡ


움직이는 공
Win32 API로 "움직이는 공" 프로그램을 만들어봤습니다. 삽질 조금 했더니 재미있는 프로그램이 나오군요.



//ball.cpp
#include <windows.h>

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hInst;
LPSTR lpszClass="ball";

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)WndProc;
WndClass.lpszClassName=lpszClass;
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&WndClass);

hWnd=CreateWindow(lpszClass,"움직이는공",WS_OVERLAPPEDWINDOW ^WS_MINIMIZEBOX^ WS_MAXIMIZEBOX^WS_THICKFRAME,
CW_USEDEFAULT,CW_USEDEFAULT,550,800,
NULL,(HMENU)NULL,hInstance,NULL);
ShowWindow(hWnd,nCmdShow);

while(GetMessage(&Message,0,0,0)) {
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
#include "resource.h"

LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{

HDC hdc,MemDC;
PAINTSTRUCT ps;
HBITMAP MyBitmap, OldBitmap;
static int x, y, vx, vy;
static RECT rt;
const int speed = 5;
switch(iMessage) {
case WM_CREATE:
MyBitmap=LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_BITMAP1));
x = 0, y = 0;
vx = speed;
vy = speed;
SetTimer(hWnd, 1, 100, NULL);
return 0;

case WM_TIMER:
GetClientRect(hWnd, &rt);
x +=vx;
y +=vy;
if(x<0)
vx = speed;
if(y<0)
vy = speed;
if(x+100>rt.right)
vx = -speed;
if(y+100>700)
vy = -speed;
InvalidateRect(hWnd,NULL,TRUE);
return 0;

case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
SetTextAlign(hdc, TA_CENTER);
TextOut(hdc,280,730,"움직이는 공입니다 - 제작자 : 성대현",35);
Rectangle(hdc,0,0,rt.right,705);
MemDC=CreateCompatibleDC(hdc);
MyBitmap=LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_BITMAP1));
OldBitmap=(HBITMAP)SelectObject(MemDC, MyBitmap);
BitBlt(hdc, x,y,100,100,MemDC,0,0,SRCCOPY);
SelectObject(MemDC,OldBitmap);
DeleteObject(MyBitmap);
DeleteDC(MemDC);

EndPaint(hWnd, &ps);


return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
by Egoo | 2005/09/28 01:14 | 컴퓨터 | 트랙백 | 덧글(2)
트랙백 주소 : http://sungdh86.egloos.com/tb/1783849
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
Commented by 인클루드 at 2005/09/28 03:44
엇! ㅊㄱㅅ 시네요~
Commented by Astralleno at 2005/10/08 20:31
앗 과거에 했었던... 다만.. 이제... 머리속에 잊혀진 ㅜㅜ

:         :

:

비공개 덧글

< 이전페이지 다음페이지 >