Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct return value of "WindowProc" in a Win32 application

Tags:

windows

winapi

In MSDN's Win32-Api documentation (at http://msdn.microsoft.com/en-us/library/ms633573%28VS.85%29.aspx) on the WindowProc, it states: The return value is the result of the message processing and depends on the message sent.

Since I have to implement this (callback) procedure, I'd like to know what it depends on, and what I have to return. Can someone shed some light on this?

like image 648
René Nyffenegger Avatar asked Jan 10 '11 19:01

René Nyffenegger


People also ask

What is Lresult callback?

LRESULT is an integer value that your program returns to Windows. It contains your program's response to a particular message. The meaning of this value depends on the message code. CALLBACK is the calling convention for the function.

What is hInstance C++?

hInstance is something called a "handle to an instance" or "handle to a module." The operating system uses this value to identify the executable (EXE) when it is loaded in memory. The instance handle is needed for certain Windows functions—for example, to load icons or bitmaps.

What is Wm_create?

A WM_CREATE message is sent to your window procedure during the window's CreateWindowEx call. The lp argument contains a pointer to a CREATESTRUCT which contains the arguments passed to CreateWindowEx . If an application returns 0 from WM_CREATE, the window is created.


2 Answers

It is dependent on the exact message you are processing. You need to refer to the documentation for that message to see the expected values and meanings of the return value.

For instance, for WM_CREATE, you should return zero to continue window creation, and -1 to fail and destroy the window. For WM_GETICON, you should return a handle to the icon for your window.

For messages that you do not explictly handle, you should call DefWindowProc, passing to it all the parameters to your window proc, and return its return value to the caller.

like image 147
Michael Avatar answered Oct 17 '22 10:10

Michael


Michael's answer answers the question perfectly, but just for reference, the usual return value will always be 0. For most messages it means that your application has processed the message. But always consult the MSDN page for the actual message to know for sure.

like image 42
Cray Avatar answered Oct 17 '22 11:10

Cray