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 ()