What is uMsg????
I've just start to program in windows and I was wondering was uMsg is. Ive seen it like a prototype
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
and I cant figure it out what it is??? Could someone please enlight me
Thx in advance
You see, when you declare/define a window procedure, you specify the parameters.
-type HWND is the window in which the message is being sent-
-type UINT (your uMsg) is a simple number that specifies the message being sent to your window procedure-
-type WPARAM is just another part of the message you can process-
-type LPARAM is another part of the message you can process-
the uMsg is the actual message sent to your window, you should make a big switch and make a handler for each message of your interest
Yeah, uMsg is pretty much what you base your decisions (the program's decisions) on.
I made a simply windows app with the console still enabled and put a cout in my callback function and found that it calls my callback function everytime the mouse moves jsut a little bit, passing my pointer across the window causes my function to be called at least a hundred times, if I didn't need to do anything when the mouse is moved should I make my callback function something like for the purose of not doing much processing just for a little mouse movment
I'm sure I've gotten the switch case syntax wrong, but you got the idea
LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
case(WM_MOUSEMOVE)://or whatever the mouse move message is
return(DefWindowProc(hwnd, msg, wparam, lparam));// Don't do anything cause I don't need to or call another function to handle the movement
// Call another function to handle other messages
if(ScndMsgHandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam))return (1);
return(DefWindowProc(hwnd, msg, wparam, lparam));
So that a long switch case with all the messsages doesn't have to be processed for the frequent mouse movements
I'm asking would it be a good way to do things? I'm wondering on the side of my mind how exactly a switch case is processed, how much longer it takes if more messages are added to it
If you do not want to process mouse msg's don't.
case WM_COMMAND://or what ever
and the return at the end of the switch.
But I don't want it to search through a long switch case a hundred times everytime someone passes a mouse over my window.
Um...that's what the window procedure is. Just one big switch case test.
But instead of having that long switch case in the first function, I can have the switch case for all the messages I want to handle in a secondary procedure, and in the main procedure check to see if it's just an annoying mouse movement , if it's not then I call the second procedure. That way I don't process the long switch case everytime the system calls my procedure because of a move message, and move messages happen many many times more than any other meaningful message. Look at the code I posted. I don't mean to sound like I'm the end all of it, I haven't been doing winapi for long, I just don't think you see what I'm getting at. If you create a console win32 project and make a window and in the callback procedure function put a cout<<Msg; you'll see everytime you move the mouse just a tiny bit the function gets called and it's just about always the same message, assuming it's the mouse move message, but I only see it as an integer when it's outputted of course.