WindowProc and C++ Input

I'm making a game right now and we need different input for like main menu, playing out game, and our built in level editor. the switch statement has gotten so big that I wanna split it up based on the previously mentioned states. when I try to make functions for menu input, playing input, and editor input it complains about stuff like "WM_KEYDOWN" being an illegal case. Is there something I can do to fix this or better yet some other way I can go about doing my input?
Thanks.
Switch statements works only in integral constants which can be interpreted at compile-time. Use an 'if' statement instead which does not have this limitation.
You can split up your switch statement, sort of. I have a ton of code in my switch statements due to the fact that I'm dealing with many tabbed windows. Accordingly, I put most of my switch commands in a completely different file, one that is dedicated strictly to handle the switch statements. It goes more or less like this --

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
case WM_COMMAND:

...I handle my list boxes and combo boxes here with if() loops combined with LOWORD(wParam)

...then I call the function which is contained in
my other file and which is dedicated to the remainder
of my WM_COMMAND statements. I pass the hwnd
and the LOWORD(wParam) paramaters to the function,
and there is NOT a "break" statement after the
above code, i.e., after I handle my combo and list boxes,
I simply call the function...

MyMenuFunction(hwnd, LOWORD(wParam));

break;


Notice that the "break" statement must come AFTER the function call, or WM_COMMAND will intercept nothing whatsoever.

In MyMenuFunction() it accepts the switch, like this...

1
2
3
4
5
6
7
8
MyMenuFunction(HWND hw, int iCommand)
{
.... declare whatever variables you want here, then...

switch(iCommand)
{
....handle the remainder of your switch statements.
}


This alleviates a huge main.cpp file and allows me to dedicate a "switch" file for each of my tabbed windows, so that if I am handling Tab_1, then the Tab_1 "switch" file is utilized, and for Tab_2, the Tab_2 "switch" file is utilized, et cetera.
Last edited on
Gdschaf, are you using a single window proc for all your different windows/views?
I believe polled input is much more efficient than window messages in a real-time game. Because all input is available at request rather than at the convenience of the queuing system you can have statements like this(for example):

1
2
if (Input.LeftMouseButton())
    Player.MoveTo(Input.MouseX(), Input.MouseY());

Topic archived. No new replies allowed.