WM_USER

王朝百科·作者佚名  2012-03-11  
宽屏版  字体: |||超大  

为了防止用户定义的消息ID与系统的消息ID冲突,MS(Microsoft)定义了一个宏WM_USER,小于WM_USER的ID被系统使用,大于WM_USER的ID被用户使用。MSDN定义:The WM_USER constant is used by applications to help define private messages, usually of the form WM_USER+X, where X is an integer value.

#define WM_USER 0x0400RemarksThere are five ranges of message numbers:

Range

Meaning

0 through WM_USER – 1

Messages reserved for use by the system.

WM_USER through 0x7FFF

Integer messages for use by private window classes.

WM_APPthrough 0xBFFF

Messages available for use by applications.

0xC000 through 0xFFFF

String messages for use by applications.

Greater than 0xFFFF

Reserved by the system for future use.

Message numbers in the first range (0 through WM_USER – 1) are defined by the system. Values in this range that are not explicitly defined are reserved for future use by the system.

Message numbers in the second range (WM_USER through 0x7FFF) can be defined and used by an application to send messages within a private window class. These values cannot be used to define messages that are meaningful throughout an application, because some predefined window classes already define values in this range. For example, predefined control classes such as BUTTON, EDIT, LISTBOX, and COMBOBOX may use these values. Messages in this range should not be sent to other applications unless the applications have been designed to exchange messages and to attach the same meaning to the message numbers.

Message numbers in the third range (0x8000 through 0xBFFF) are available for application to use as private messages. Message in this range do not conflict with system messages.

Message numbers in the fourth range (0xC000 through 0xFFFF) are defined at run time when an application calls theRegisterWindowMessagefunction to retrieve a message number for a string. All applications that register the same string can use the associated message number for exchanging messages. The actual message number, however, is not a constant and cannot be assumed to be the same between different sessions.

Message numbers in the fifth range (greater than 0xFFFF) are reserved for future use by the system.

QuickInfoWindows NT:Requires version 3.1 or later.

Windows:Requires Windows 95 or later.

Windows CE:Requires version 1.0 or later.

Header:Declared in winuser.h.所以自定义消息的步骤:(一)先在头文件中定义自己消息的ID,如 #define WM_MY_FIRST_MESSAGE (WM_USER + 0x001)

(二)再声明自己的消息处理函数:afx_msg void OnMyFirstMessage();

(三)在CPP文件中添加消息映射宏:

在BEGIN_MESSAGE_MAP 和END_MESSAGE_MAP代码块中添加消息映射宏ON_MESSAGE,(建议添加到//}}后面)如下:

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)

//{{AFX_MSG_MAP(CAboutDlg)

// No message handlers

//}}AFX_MSG_MAP

ON_MESSAGE(WM_MY_FIRST_MESSAGE, OnMyFirstMessage)

END_MESSAGE_MAP()

(四)最后定义消息处理函数:

OnMyFirstMessage()

{

// TODO: 在此添加控件通知处理程序代码

}

 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝百科 版权所有