Windows API one-day training (11) getmessage Function

Source: Internet
Author: User
In order to obtain a steady stream of messages, the application needs to call the getmessage function, because all input messages in the window will be placed in the message queue of the application, then, it is sent to the callback function in the window for processing.
The getmessage function declaration is as follows:
Winuserapi
Bool
Winapi
Getmessagea (
_ Out lpmsg,
_ In_opt hwnd,
_ In uint wmsgfiltermin,
_ In uint wmsgfiltermax );
Winuserapi
Bool
Winapi
Getmessagew (
_ Out lpmsg,
_ In_opt hwnd,
_ In uint wmsgfiltermin,
_ In uint wmsgfiltermax );
# Ifdef Unicode
# Define getmessage getmessagew
# Else
# Define getmessage getmessagea
# Endif //! Unicode
LpmsgIs the message pointer obtained from the thread message queue.
HwndIt is the message of the window to be retrieved. If it is set to null, It is the message of all windows.
WmsgfilterminIs to obtain the minimum value of the Message ID number. If it is smaller than this value, it is not returned.
WmsgfiltermaxIs the maximum value of the Message ID. If the value is greater than this value, it is not returned.
The Return Value of the function may be 0, greater than 0, or equal to-1. If a non-wm_quit message is obtained successfully, a value greater than 0 is returned. If a wm_quit message is obtained, a value of 0 is returned. If an error occurs, the value of-1 is returned.
 
An example of calling this function is as follows:
#001 // main program entry
#002 //
#003 // Cai junsheng 2007/07/19
#004 // QQ: 9073204.
#005 //
#006 int apientry _ twinmain (hinstance,
#007 hinstance hprevinstance,
#008 lptstr lpcmdline,
#009 int ncmdshow)
#010 {
#011 unreferenced_parameter (hprevinstance );
#012 unreferenced_parameter (lpcmdline );
#013
#014 //
#015 MSG;
#016 haccel hacceltable;
#017
#018 // load the global string.
#019 loadstring (hinstance, ids_app_title, sztitle, max_loadstring );
#020 loadstring (hinstance, idc_testwin, szwindowclass, max_loadstring );
#021 myregisterclass (hinstance );
#022
#023 // application initialization:
#024 if (! Initinstance (hinstance, ncmdshow ))
#025 {
#026 return false;
#027}
#028
#029 hacceltable = loadaccelerators (hinstance, makeintresource (idc_testwin ));
#030
#031 // message loop:
#032 bool Bret;
#033 While (Bret = getmessage (& MSG, null, 0, 0 ))! = 0)
#034 {
#035 if (Bret =-1)
#036 {
#037 // handling error.
#038
#039}
#040 else if (! Translateaccelerator (msg. hwnd, hacceltable, & MSG ))
#041 {
#042 translatemessage (& MSG );
#043 dispatchmessage (& MSG );
#044}
#045}
#046
#047 return (INT) msg. wparam;
#048}
#049
 
Row 3 is used to retrieve messages from all windows.
Related Article

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.