问题
Result
property meaning:
Specifies the value that is returned to window in response to handling the message
But MSDN
does not says anymore:
http://msdn.microsoft.com/en-us/library/system.windows.forms.message.result%28v=vs.110%29.aspx
I will remark this quote words from the user @Idle_Mind in this question Trying to write a better WndProc Handling:
You can set the Result() property to change the way the message is handled.
It is just like a winapi function return success value? Zero = true and non-zero = false, or what is?
Someone could explain me really what means the value of that propertie, in which circunstances I should need to use this value, and show me a code example of how I can use it handling messages from a wndproc
sub?
UPDATE:
Example of how I'm trying to handle WM_CREATE message...
Protected Overrides Sub WndProc(ByRef m As Message)
Select Case m.Msg
Case &H1 ' WM_CREATE
m.Result = -1
End Select
MyBase.WndProc(m)
End Sub
回答1:
Every window message (WM_CREATE, WM_DESTROY, WM_PAINT, WM_USER, etc, etc) is sent by something. Most message are sent by Windows in response to some user interaction or some API call. Others are sent by 3rd-party code (for example, when you call the Win32 API SendMessage
, it's the caller of SendMessage
that is directly sending the message). In any case, the sender of the message probably expects something in response. The expected response depends on the sender of the message and the message type.
In most cases, you'll probably want to follow the rules defined by Microsoft for the window message. For example, in the documentation for WM_CREATE, it says:
If an application processes this message, it should return zero to continue creation of the window. If the application returns –1, the window is destroyed and the CreateWindowEx or CreateWindow function returns a NULL handle.
When handling WM_CREATE messages, you should return the appropriate value as defined above. When handling other messages, you should return whatever the documentation says about that message. When handing a 3rd-party message such as WM_USER, the 3rd-party should clearly indicate what it expects.
回答2:
I depends on the message. According to the API reference it is bound to the specific message.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644950%28v=vs.85%29.aspx
E.g.:
Return value
An application returns zero if it processes this message.
http://msdn.microsoft.com/en-us/library/windows/desktop/dd145213%28v=vs.85%29.aspx
It can be used as a flag, indicating that the message doesn't need further attendance.
If your application handles, i.e. processes the message, a result of 0 will do.
回答3:
A classic example is the WM_NCHITTEST message, which is passed to your app when the system wants to know where over your form the mouse is so it can change the cursor appropriately and know how to react to user clicks and drags. By changing m.Result
, for example, you can prevent the form from being resized in a specific direction by telling the system that the mouse is not really over that particular edge so it prevents a drag and doesn't change the cursor to the resize one.
来源:https://stackoverflow.com/questions/19961694/what-does-the-result-property-of-a-windows-message-mean-and-when-and-how-to-use