#include
#include
#include
#include
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg,
WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, 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("KKW");
RegisterClass(&WndClass);
hwnd = CreateWindow(_T("KKW"),
_T("홍길동의 첫 번째 윈도우"),
WS_OVERLAPPEDWINDOW,
200,//CW_USEDEFAULT,
300,//CW_USEDEFAULT,
600,//CW_USEDEFAULT,
400,//CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg,//WM_KEYDOWN, WM_CHAR
WPARAM wParam, LPARAM lParam)//wParam에는 문자
{
HDC hdc;
HBRUSH Brush, oBrush;
PAINTSTRUCT ps;
static int x, y, lef_rig, up_down; // 키를 눌렀을 때 값이 출력할 때도 갖고 있도록 static으로
static RECT rectView; // 윈도우 크기정보를 갖는 구조체
int randNumX = rand() T0;
int randNumY = rand() 40;
srand((unsigned)time(NULL));
switch (iMsg)
{
case WM_CREATE:
x = 20; y = 20; // 원 중심점
return 0;
case WM_PAINT:
GetClientRect(hwnd, &rectView);
hdc = BeginPaint(hwnd, &ps);
Brush = CreateSolidBrush(RGB(0, 255, 0));
oBrush = (HBRUSH)SelectObject(hdc, Brush);
Ellipse(hdc, randNumX - 20, randNumY - 20, randNumX + 20, randNumY + 20);
Brush = CreateSolidBrush(RGB(255, 0, 0));
oBrush = (HBRUSH)SelectObject(hdc, Brush);
Ellipse(hdc, x - 20, y - 20, x + 20, y + 20); // 키 누르면 원을 그림
EndPaint(hwnd, &ps);
return 0;
case WM_KEYDOWN:
SetTimer(hwnd, 1, 70, NULL);
switch (wParam) {
case VK_RIGHT:
up_down = 0;
lef_rig = +1;
break;
case VK_LEFT:
up_down = 0;
lef_rig = -1;
break;
case VK_UP:
lef_rig = 0;
up_down = -1;
break;
case VK_DOWN:
lef_rig = 0;
up_down = +1;
break;
}
break;
case WM_TIMER: // 시간이 경과하면 메시지 자동 생성
x = x + 40 * lef_rig;
if (x + 20 > rectView.right) x -= 40;
if (x - 20
y = y + 40 * up_down;
if (y + 20 > rectView.bottom) y -= 40;
if (y - 20
InvalidateRgn(hwnd, NULL, TRUE);
break;
case WM_DESTROY:
KillTimer(hwnd, 1); // 윈도우 종료시 타이머도 종료
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
첨부파일에 코드 올린게 제가 만든 코든데
이게
문제가
'빨간원을 방향화살표로 이동시켜서 초록색 원을 덮으면 또다른 초록색 원이 랜덤 위치에 나타난다.
빨간색원과 초록생원은 정확히 포개져야 한다.
빨간원이 초록원을 덮으면 빨간색이 점점 짙어진다. (255,0,0)=>(250,0,0)=>(245,0,0)=>240,0,0)=>...'
이건데 제가 어떻게해야될지몰라서..
혹시 도와주실분있으신가요...
해당 댓글은 삭제되었습니다.
오픈카톡 주소남겨둘게요..
https://docs.microsoft.com/en-us/windows/win32/gdi/region-functions
MSDN
이나 보세영
무ㅓ죠이게..