Luo Cao

First, the return value depends on which message gets processed.

Most of processed messages return 0, whereas some are handles, some are Booleans, etc.

I¡¯m a little bit confused with who will use these non zero return value of DefWindowProc, and why designed it in this way.

Thanks.




Re: Windows Forms General What¡¯s the general purpose when return value of DefWindowProc doesn¡¯t equal Zero?

nobugz

It indeed depends on the message. Generally, a zero return value means "I didn't use it" and Windows passes the message on to the parent window. Some messages are not posted but sent directly with SendMessage() and the return value then returns a result (like a handle) which the code that called SendMessage() uses.





Re: Windows Forms General What¡¯s the general purpose when return value of DefWindowProc doesn¡¯t equal Zero?

Luo Cao

0 means "I didn't use it" not exactly. However, MSDN always declares that "An application should return zero if it processes this message".
From your words, likely sometimes SendMessage() internally calls DefWindowProc() and returns the value which is returned by DefWindowProc().
Besides, non-zero return value must mean that the message gets processed, right




Re: Windows Forms General What¡¯s the general purpose when return value of DefWindowProc doesn¡¯t equal Zero?

nobugz

Reiterating, this is a per-message defined return value. The WndProc handler for WM_SETCURSOR for example should return 1 if it processed the message. This behavior is specific to WM_SETCURSOR. Note that SendMessage does *not* call DefWndProc(), it calls the WndProc() handler. That handler then inspects the message number and implements custom behavior as needed. If it doesn't have any use for the message, it should delegate the message to DefWndProc(). The Windows' supplied handler for DefWndProc() (DefWindowProc) passes the WM_SETCURSOR message to the parents of the window until one of its parent handlers returns 1.





Re: Windows Forms General What¡¯s the general purpose when return value of DefWindowProc doesn¡¯t equal Zero?

Luo Cao

So, in summary, no matter what returen value is (0 or non 0), we can't assume any return value about specific message, that make me hard to determine which message is processed.
So I still can't quite follow what you said "Generally, a zero return value means "I didn't use it" ". Could you explain that more thanks.

In general, is there any good idea about how to determin whether the messages get processed or not






Re: Windows Forms General What¡¯s the general purpose when return value of DefWindowProc doesn¡¯t equal Zero?

nobugz

Let's tackle this from the other end, it is too tricky to talk about generalities when there are none. What problem are you trying to solve





Re: Windows Forms General What¡¯s the general purpose when return value of DefWindowProc doesn¡¯t equal Zero?

Luo Cao

I had a custom Win32 control, then I wanted to embed it into another container control (a winForm). In container control, I had to directly call custom child control wndproc, just like,

if (childControl.WndProc() == 0)
base.WndProc();

the above code assumed that if return value equaled 0, means that it didn't handle the msg and parent needs to do further process. I'm afraid it's not quite reasonable. But it worked though.






Re: Windows Forms General What¡¯s the general purpose when return value of DefWindowProc doesn¡¯t equal Zero?

nobugz

Odd stuff. How did you access the protected method What message did you post





Re: Windows Forms General What¡¯s the general purpose when return value of DefWindowProc doesn¡¯t equal Zero?

Luo Cao

So, if necessary, the parent will judge if the message got processed according to return value by DefWindowProc and determine to how to do further processing. Is that right Then we should not bother to what return value we expect.