#include<Windows.h>
#include<TCHAR.h>
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR IpszCmdLine, int nCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS WndClass;
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(NULL, IDI_QUESTION);
WndClass.hCursor = LoadCursor(NULL, IDC_IBEAM);
WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = _T("Window Class Name");
RegisterClass(&WndClass);
hwnd = CreateWindow(_T("Window Class Name"), _T("Window Class Name"), WS_OVERLAPPEDWINDOW, 200, 300, 600, 410, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, 1);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
static HDC hdc;
PAINTSTRUCT ps;
static int x, y;
static RECT rcv;
static bool flag = false;
static HBRUSH hBrush, oldBrush;
switch (iMsg)
{
case WM_CREATE:
x = 20; y = 20;
GetClientRect(hwnd, &rcv);
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
Rectangle(hdc, 0, 0, 560, 360);
hBrush = CreateSolidBrush(RGB(255, 0, 0));
oldBrush = (HBRUSH)SelectObject(hdc, hBrush);
if (flag==true)
SelectObject(hdc, oldBrush);
Ellipse(hdc, x - 20, y - 20, x + 20, y + 20);
DeleteObject(hBrush);
EndPaint(hwnd, &ps);
break;
case WM_KEYDOWN:
if (wParam == VK_RIGHT)
{
x += 40;
if (x + 20 > rcv.right)
{
x -= 40;
flag = true;
}
else
flag = false;
}
else if (wParam == VK_LEFT)
{
x -= 40;
if (x + 0 < rcv.left)
{
x += 40;
flag = true;
}
else
flag = false;
}
else if (wParam == VK_UP)
{
y -= 40;
if (y + 0 < rcv.top)
{
y += 40;
flag = true;
}
else
flag = false;
}
else if (wParam == VK_DOWN)
{
y += 40;
if (y + 20 > rcv.bottom)
{
y -= 40;
flag = true;
}
else
flag = false;
}
InvalidateRgn(hwnd, NULL, TRUE);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
벽에 충돌하는 순간만 색깔이 바뀌었다가 다시 돌아오는걸로 해야하는데
나는 지금 벽에 닿아있을때 빨간색으로 되는것도 못하고 있어.. 도와줘 형들 ㅠㅠㅠㅠ
작성자 살아있냐?