How does winProc Get called?

I know you set a pointer to the function

but when does that lpfnWndProc get called???
After reading API documentation....

The DispatchMessage calls the WinProc? is that right?
You may have to reword your question...

If your asking how to call it, then you set the object of the window class - lpfnWndProc - to your Window Procedure function when you register WNDCLASSEX (or WNDCLASS, I prefer the EX class).

If you meant something else, then you may have to edit your question or reply to your thread... Because I am completely lost :P
My question is where in the code does the function call to winProc exist..

I am pretty sure its in the dispatchMessage.. Inside the main loop while the window is receiving messages.


http://msdn.microsoft.com/en-us/library/windows/desktop/ms644934(v=vs.85).aspx
Last edited on
You never call the Window Procedure from within your code. Never. When an object of type WNDCLASSEX is registered, one of the members is the runtime address of the Window Procedure. Windows (the Operating System) calls that function through the function pointer passed in through the member. I might add that the entire subject of function pointers is usually glossed over or not taught in modern C++ it seems. It is a critically important concept in Windows Programming, and if you don't thouroughly understand function pointers and how to use them, you need to immediately stop what you are doing and learn how to use and recognize function pointers. Anyone who came to C++ by first mastering C would have a good understanding of this.
freddie1: Windows (the Operating System) calls that function through the function pointer passed in through the member.

My 2 cents: novellof is actually right that DispatchMessage() "calls" WndProc.

From a thread point of view: Your programm calls DispatchMessage() and that same call continues to call the WndProc() of your own program. So you basically (indirectly) call WndProc() yourself via DispatchMessage(). But as freddie1 said: NEVER call WndProc directly!

It's not actually the OS that makes that call.

DispatchMessage() does not return until your WndProc() returns.

It's more like:
OS --call--> WinMain() -> {message loop} --call--> DispatchMessage() --call--> WndProc() --call--> whatever()

And then:
whatever() --return--> WndProc() --return--> DispatchMessage() --return--> {and we're back in our message loop}


The interaction with the OS happens in GetMessage()

NOTE: AFAIK some calls to SendMessage() from inside your own process bypass GetMessage() and call the WndProc() directly.
Last edited on
Topic archived. No new replies allowed.