What does the Result property of a windows message mean and when and how to use it?

前端 未结 3 954
悲哀的现实
悲哀的现实 2021-01-15 21:18

Result property meaning:

Specifies the value that is returned to window in response to handling the message

But <

相关标签:
3条回答
  • 2021-01-15 21:41

    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.

    0 讨论(0)
  • 2021-01-15 21:41

    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.

    0 讨论(0)
  • 2021-01-15 21:52

    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.

    0 讨论(0)
提交回复
热议问题