Windows Messaging mechanism-driven client program Getmssage ()

Source: Internet
Author: User

To get the message out of the message queue, we need to call the GetMessage () function, which has the following prototype declaration:

BOOL GetMessage (

lpmsg lpmsg,//address of structure with message

HWND hwnd,//Handle of window

UINT Wmsgfiltermin,//First message

UINT Wmsgfiltermax//Last message

);

Parameters lpmsg point to a message ( MSG ) Structural body, GetMessage The message information that is removed from the thread's message queue is saved in the struct object.

Parameters hWnd specifies the message to receive which window belongs to. Typically we set it to NULLtoreceive window messages belonging to all windows of the calling thread.

Parameters Wmsgfiltermin specifies the minimum value of the message to get, usually set to 0 .

Parameters Wmsgfiltermax Specifies the maximum value of the message to get. If both Wmsgfiltermin and wmsgfilter Max are set to 0, all messages are received.

GetMessage function receives the exception Wm_quit non-0 values are returned for messages outside the For wm_quit messages, the function returns zero. If an error occurs, the function returns -1, for example, when the parameter hWnd is an invalid window handle or lpmsg is an invalid pointer.

Second, the message selection model

The Windows Messaging mechanism writes the method of the socket client program. Using the Windows Messaging mechanism to write the socket program has the following advantages: First, we can put most of the recv operations and close operations into the message handler function, in order to facilitate the maintenance of code, and second, when there is data readable, the local program will receive the corresponding message, We can read the data at this time.


This is a network model under Winsock.
Example: int Ierrorcode=wsaasyncselect (Mysocket.m_clientsocket,m_hwnd,wm_client_read,fd_read | Fd_close);
such a code, it tells the system, now I this mysocket.m_clientsocket, only focus on Fd_read | Fd_close Two network events, once these two events, I will post a wm_client_read message, which is a custom message
and then respond to the message in the message loop.

Windows Messaging mechanism-driven client program Getmssage ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.