One-day training of Windows APIs (14) dispatchmessage Function

Source: Internet
Author: User

The previous section describes how to obtain a message from the system queue, check the function of the shortcut key, and convert the character message function. The last thing to do is to call the dispatchmessage function, it means to send this message to windowproc, the message processing function in the window.

The dispatchmessage function is declared as follows:
Winuserapi
Lresult
Winapi
Dispatchmessagea (
_ In const MSG * lpmsg );
Winuserapi
Lresult
Winapi
Dispatchmessagew (
_ In const MSG * lpmsg );
# Ifdef Unicode
# Define dispatchmessage dispatchmessagew
# Else
# Define dispatchmessage dispatchmessagea
# Endif //! Unicode

Lpmsg refers to the message to be sent to the message processing function windowproc.

An example of calling this function is as follows:
#001 // master Program Portal
#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 calls the dispatchmessage function to send messages.

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/caimouse/archive/2007/07/24/1704627.aspx

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.