[try Beta version]
Not logged in

 
Virtual Key Codes

Jul 3, 2011 at 7:01pm
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
Jul 3, 2011 at 7:06pm
try putting a break at the end of case VK_LEFT
Jul 4, 2011 at 2:34pm
No luck, when i do that the left key works, but not the right one :/
Jul 4, 2011 at 6:14pm
:) ?
Jul 4, 2011 at 7:30pm
lol idk bro. I started windows programming but i needed a resource editer to continue learning, so instead i started learning OpenGL.
Jul 4, 2011 at 7:34pm
:S
Jul 4, 2011 at 8:12pm
I think you need braces around the switch statements.
Jul 4, 2011 at 8:18pm
Just tried it and nope :P lol
Jul 4, 2011 at 8:24pm
He means like this:
1
2
3
4
switch(wParam)
{ //Open brace!!
  /*put cases in here*/
} //Close brace!! 
Jul 4, 2011 at 8:27pm
I know what he meant, and only the right one works if i do that.
Jul 4, 2011 at 9:05pm
Can you post more code?
Jul 4, 2011 at 10:09pm
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;
}
Jul 4, 2011 at 11:46pm
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.
Jul 5, 2011 at 2:59am
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.
Jul 12, 2011 at 7:09pm
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
Jul 14, 2011 at 5:29pm
Anyone ?
Last edited on Jul 15, 2011 at 2:42pm
Topic archived. No new replies allowed.