1

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
Community
  • 1
  • 1
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • Your question is entirely too vague. What you return as a result of something varies depending on what that something is; are you asking specifically about the result you return from your WndProc? – Ken White Nov 13 '13 at 18:46
  • if you're handing one or more messages on your own, then you have to return the result for the sender; in some cases it tells Windows that things were already handled and not to do anything. So the `Result` you set would depend on the Message you handled. Also, `Result` is an 'IntPtr' not Boolean. – Ňɏssa Pøngjǣrdenlarp Nov 13 '13 at 18:46
  • 1
    Ken White no, also I'm asking about how to return the result and in which circunstances need to be returned? any code example would be great, maybe the title of the question should be "how to response a windows message"? because the result value would be used to response...or I'm wrong? – ElektroStudios Nov 13 '13 at 18:49
  • "how to respond" depends on the message - see Stefan's answer. you'd have to look up the correct result for each Message you intend on handling. – Ňɏssa Pøngjǣrdenlarp Nov 13 '13 at 18:50
  • Here's more info regarding [WindowProc](http://msdn.microsoft.com/en-us/library/ms633573.aspx). See what it says about the `Result` on that page. – Ken White Nov 13 '13 at 18:50
  • Thanks @Plutonix and Ken White ok – ElektroStudios Nov 13 '13 at 18:50

3 Answers3

4

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.

Community
  • 1
  • 1
Stefan
  • 17,448
  • 11
  • 60
  • 79
4

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.

Michael Gunter
  • 12,528
  • 1
  • 24
  • 58
  • @Michael Gunter sorry but I still don't get how to return the Result property for any message, I'm trying just to process the WM_CREATE (&H1) message and change the value property like this: `m.Result = -1` but it does nothing so after that I've tried this else and the window is not created (but I'm trying to pass the 0 value not the -1 so I'm returnning bad the message) `MyBase.WndProc(New Message With {.HWnd = m.HWnd, .Msg = m.Msg, .LParam = m.LParam, .WParam = m.WParam, .Result = 0})` could you please give a code example? – ElektroStudios Nov 13 '13 at 19:22
  • How are you attempting to process WM_CREATE? – Michael Gunter Nov 13 '13 at 20:38
  • 1
    When you call `MyBase.WndProc`, it's overwriting your `m.Result` value. When overriding `WndProc`, either don't call `MyBase.WndProc`, or change `m.Result` *after* calling `MyBase.WndProc`. In either case, you *must* understand the ramifications of doing so. – Michael Gunter Nov 15 '13 at 17:00
2

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.

Idle_Mind
  • 38,363
  • 3
  • 29
  • 40
  • I still don't get it, what should happen when changing the result property when processing that message?, I've tried to specify that the cursor really is in a maximize button or in a close button, but nothing strange happens: `m.Result = 9 ' In maximize button` – ElektroStudios Nov 13 '13 at 19:12