Routing messages from WndProc()

With this:

1
2
3
4
5
LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
{
// Route all Windows messages to the game engine
return GameEngine::GetEngine()->HandleEvent(hWindow, msg, wParam, lParam);
}


Here i am routing windows messages to my game engine so that HandleEvent can be the function to process the messagess. Can you tell me if im right in saying this:

When the OS calls upon WndProc() to send messages to my window I call HandleEvent() to do its jobs (process the messages with a switch statement), and thats the main purpose of this code. Instead of just calling the HandleEvent() function we return it so that we return the return value of HandleEvent seeing as the WndProc() requires an integer to be returned.

Also, would this work:

1
2
3
4
5
6
LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
{
// Route all Windows messages to the game engine
GameEngine::GetEngine()->HandleEvent(hWindow, msg, wParam, lParam);
return 0;
}


Am i right :)
Also, if the OS gives WndProc() the message to process, how does my HandleEvent function get ahold of the message?
TpOreilly wrote:
Also, if the OS gives WndProc() the message to process, how does my HandleEvent function get ahold of the message?

Silly Question.


TpOreilly wrote:
Also, would this work:
1
2
3
4
5
6
LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
{
// Route all Windows messages to the game engine
GameEngine::GetEngine()->HandleEvent(hWindow, msg, wParam, lParam);
return 0;
}

Strictly speaking no - As the GameEngine::GetEngine()->HandleEvent function is responsible for processing the messages - you should return whatever value that function returns (which may not be 0);

Last edited on
Why is that a silly question, if WndProc() is the function we write to receive messages directed at our window, how does my HandleEvent function get ahold of the message?
It is a silly question because in your original post you say:
Here i am routing windows messages to my game engine so that HandleEvent can be the function to process the messagess.

You then proceed to call your game engine function passing the message information that was sent by windows as parameters to the game engine function:
return GameEngine::GetEngine()->HandleEvent(hWindow, msg, wParam, lParam);

so yes - it was a silly question.
Last edited on
I know WHAT is happening, but i dont know HOW its happening. :)
Last edited on
When i predefine the HandleEvent() function i write it like so...

 
HandleEvent(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam);


...obviously, when i define this function its parameters are empty.

So, i assume that when i put...

 
GameEngine::GetEngine()->HandleEvent(hWindow, msg, wParam, lParam);


...i am passing the "updated" variables hWindow, msg, wParam and lParam.

Now, the part which throws me is...

As windows passes the message to the WndProc() and fills in WndProc()'s parameters, how am i passing those parameters to HandleEvent(), because i thought that parameters only belonged to one function and can only be used in that one function, answer me that :D, thanks.
Tp, I keep telling you, but you apparently don't listen - it's painfully obvious you are trying to do something that's way over your head. You would be far better off first getting a grip on basic programming before you attempt anything like a game.
TpOreilly wrote:
As windows passes the message to the WndProc() and fills in WndProc()'s parameters, how am i passing those parameters to HandleEvent(), because i thought that parameters only belonged to one function and can only be used in that one function, answer me that :D, thanks.


You do know that functions can call other functions don't you??
And when a function call another function calls another funtion, it can pass values to that function (either by copy, by reference or by pointer).

1
2
3
4
5
6
7
8
9
void functionA (int A, float X)
{
     functionB(A); //pass (by copy) the value of variable A to functionB
}

void functionB( int Y)
{
  //some code here
}


Because if you don't, then I suggest you go and read up on functions.
Last edited on
You would be far better off first getting a grip on basic programming before you attempt anything like a game WinAPI.


Fixed.

With the right lib, making games isn't so complicated.

WinAPI, on the other hand, is very difficult for a beginner.

With the right lib, making games isn't so complicated.


Look at his other posts. He doesn't understand the simplest things right now. Sure there are some relatively easy to use higher level libs, but there is no such thing as a magic library that removes the requirement of understanding programming in general and in particular the language you are working with at least to a certain degree.

And not complicated? Maybe if you're talking about tetris or something, but most games are. Maybe we have different definitions of complicated, but he is a complete beginner.
guestgulkan, thanks, that helped.
maybe you're right @ hanst. I haven't actually looked at his other posts.

*shrug*
Topic archived. No new replies allowed.