I'm trying to move static TCHAR greeting[] = _T("123"); by using arrows, but it doesn't move at all. MessageBox is used as a confirmation of getting keyboard input.
void move(HWND hWnd, WPARAM wParam, LPARAM lParam, unsigned int *x, unsigned int * y) {
RECT rt;
if (wParam == VK_LEFT) {
GetClientRect(hWnd, &rt);
x = x - 5;
InvalidateRect(hWnd, &rt, FALSE);
MessageBox(hWnd, LPCSTR("123"), LPCSTR("123"), MB_OK);
}
if (wParam == VK_DOWN) {
GetClientRect(hWnd, &rt);
y = y - 5;
InvalidateRect(hWnd, &rt, FALSE);
}
if (wParam == VK_UP) {
GetClientRect(hWnd, &rt);
y = y + 5;
InvalidateRect(hWnd, &rt, FALSE);
}
if (wParam == VK_RIGHT) {
GetClientRect(hWnd, &rt);
x = x + 5;
InvalidateRect(hWnd, &rt, FALSE);
}
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT ps;
HDC hdc;
static TCHAR greeting[] = _T("123");
unsigned int x = 50;
unsigned int y = 50;
switch (message)
{
case WM_PAINT: {
hdc = BeginPaint(hWnd, &ps);
TextOut(hdc,
x, y,
greeting, 3);
EndPaint(hWnd, &ps);
break;
}
case WM_KEYDOWN:
move(hWnd, wParam, lParam, &x, &y);
break;
case WM_DESTROY: {
PostQuitMessage(0);
break;
default: {
return DefWindowProc(hWnd, message, wParam, lParam);
break;
}
}
return 0;
}
}
Can somebody explain, what is wrong here? I'm still trying to learn about <Windows.h> so pls don't try to make the code much more complicated.