Virtual Key Codes

1
2
3
4
5
6
7
8
9
10
11
case WM_KEYDOWN:

			switch(wParam)

				case VK_LEFT:
					X -= 5;
					InvalidateRect(hWnd, NULL, TRUE);
				case VK_RIGHT:
					X += 5;
					InvalidateRect(hWnd, NULL, TRUE);
					break;


Hi, the X and Y variables are integers which are used here:

DrawIcon(handleDeviceContext, X, Y, hIcon);

So the X and Y are the location of the icon.

The problem I am having is that when i press the left arrow key, nothing happens, and when i press the right arrow key it DOES go right, but it also goes right when i press the up and down kep :S
try putting a break at the end of case VK_LEFT
No luck, when i do that the left key works, but not the right one :/
:) ?
lol idk bro. I started windows programming but i needed a resource editer to continue learning, so instead i started learning OpenGL.
:S
I think you need braces around the switch statements.
Just tried it and nope :P lol
He means like this:
1
2
3
4
switch(wParam)
{ //Open brace!!
  /*put cases in here*/
} //Close brace!! 
I know what he meant, and only the right one works if i do that.
Can you post more code?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
LRESULT CALLBACK MessageProcedure(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static int X = 250;
	static int Y = 250;
	HINSTANCE hInstance;
	hInstance = LoadLibrary (TEXT("Application01.exe"));

	switch(message)
	{
		case WM_CREATE:

			int MessageBoxID;
			MessageBoxID = MessageBox(hWnd, TEXT("         Are ya ready kids?"), TEXT("Are ya ready kids?"),
            MB_ICONQUESTION | MB_YESNO);

			if (MessageBoxID == IDNO)
			{
				PostQuitMessage(0);
			}

			if (MessageBoxID == IDYES)
			{
				UpdateWindow(hWnd);
			}

			

		case WM_PAINT:
				
				HICON hIcon;
				hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
				HDC handleDeviceContext; 
				PAINTSTRUCT PaintSt;
				handleDeviceContext = BeginPaint(hWnd, &PaintSt);
				DrawIcon(handleDeviceContext, X, Y, hIcon);
				EndPaint(hWnd, &PaintSt);
				break;
			

		case WM_KEYDOWN:

			switch(wParam)
			
				case VK_LEFT:
					X -= 5;
					InvalidateRect(hWnd, NULL, TRUE);
					break;
				case VK_RIGHT:
					X += 5;
					InvalidateRect(hWnd, NULL, TRUE);
					break;

		case WM_DESTROY:
            PostQuitMessage(0);
			break; 
		
		default:

			return DefWindowProc (hWnd, message, wParam, lParam);
	}

	return 0;
}
For starters, you need a return FALSE; after you're WM_CREATE statement.

Secondly, your return DefWindowProc(hWnd, message, wParam, lParam) should NOT be inside your switch(message) statement, which it is. It should be BELOW the brace, and should REPLACE the return 0;.

That could be thw whole problem. Either way, both of those errors are significant.
Your switch statement from 42-51 is missing curly braces {}, and your WM_KEYDOWN case is missing a break at the end. Also...I see you are declaring variables inside of switch cases. IIRC, that's illegal as the initialization might not occur if you miss the case, but the destruction will still attempt to occur at the end of the switch block. Force scopes around the case internals to fix this.
Hi, sorry for my late reply.

I have done everything besides force scopes and it still doesnt work.

Im not sure of how to force scopes around the case internals.

Thanks
Anyone ?
Last edited on
Topic archived. No new replies allowed.