RegisterWindowMessage
RegisterWindowMessage function
Defines a new window message that is guaranteed to be unique throughout the system. The message value can be used when sending or posting messages.
Syntax
UINT WINAPI RegisterWindowMessage(
_In_ LPCTSTR lpString
);
Parameters
- lpString [in]
-
Type: LPCTSTR
The message to be registered.
Return value
Type:
Type: UINT
If the message is successfully registered, the return value is a message identifier in the range 0xC000 through 0xFFFF.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
The RegisterWindowMessage function is typically used to register messages for communicating between two cooperating applications.
If two different applications register the same message string, the applications return the same message value. The message remains registered until the session ends.
Only use RegisterWindowMessage when more than one application must process the same message. For sending private messages within a window class, an application can use any integer in the range WM_USERthrough 0x7FFF. (Messages in this range are private to a window class, not to an application. For example, predefined control classes such as BUTTON, EDIT, LISTBOX, and COMBOBOX may use values in this range.)
Samples:
1.sender
static UINT sBroadcastCommand = ::RegisterWindowMessage( _T("BroadcastCommand"));
int _tmain(int argc, _TCHAR* argv[])
{
::PostMessage( (HWND)HWND_BROADCAST, sBroadcastCommand, , );
return ;
}
2.receiver
static UINT UM_BROADCAST_CMD = ::RegisterWindowMessage( _T("BroadcastCommand"));
BEGIN_MESSAGE_MAP(Ctest_receive_broadcastmsgDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_REGISTERED_MESSAGE(UM_BROADCAST_CMD, OnBroadcastCommand)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// Ctest_receive_broadcastmsgDlg message handlers
LRESULT Ctest_receive_broadcastmsgDlg::OnBroadcastCommand(WPARAM wParam, LPARAM lParam)
{
printf("OnBroadcastCommand: %d , %d \n", wParam, lParam);
return S_OK;
}
3.console application receiver test failed.
int _tmain(int argc, _TCHAR* argv[])
{ DWORD pid = GetCurrentProcessId();
DWORD tid = GetCurrentThreadId();
UINT UM_BROADCAST_CMD = ::RegisterWindowMessage( _T("BroadcastCommand"));
UINT msgSigInt = RegisterWindowMessage((LPCWSTR)"SIGINT");
UINT msgSigTerm = RegisterWindowMessage((LPCWSTR)"SIGTERM");
MSG msg;/* Make a message queue -- this is the method suggested by MS */ //PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE); printf("My process id: %d\n", pid);
printf("My thread id: %d\n", tid);
printf("SIGINT message id: %d\n", msgSigInt);
printf("SIGTERM message id: %d\n", msgSigTerm);
printf("Entering loop...\n");
fflush(stdout); while (GetMessage(&msg, NULL, , ))
{
printf("Received message: %d\n", msg.message);
if (msg.message == msgSigInt)
{
printf("SIGINT received, continuing.\n");
}
else if (msg.message == msgSigTerm)
{
printf("SIGTERM received, continuing.\n");
}
else if (msg.message == UM_BROADCAST_CMD)
{
//////////////////////////////////////////////////////////////////////////
//HWND_BROADCAST:消息被寄送到系统的所有顶层窗口,包括无效或不可见的非自身拥有的窗口、 被覆盖的窗口和弹出式窗口。消息不被寄送到子窗口
//导致失败。。。。。。。。。。。。。。。。。控制台接收不到。
printf("sBroadcastCommand received, continuing %d:%d.\n", msg.wParam, msg.lParam);
}
fflush(stdout);
} printf("Exiting.\n");
fflush(stdout); return ;
}
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644947(v=vs.85).aspx
RegisterWindowMessage的更多相关文章
- Delphi消息的广播方式(先RegisterWindowMessage,后SendMessage HWND_BROADCAST,最后改写接收窗口的WndProc)
///////消息广播只能将消息传递到接收消息的主程序中,MDIChild窗体不能接收到广播消息:///////// unit Unit1; interface uses Windows, Messa ...
- RegisterWindowMessage介绍
该函数为windows API之一 msdn地址:https://msdn.microsoft.com/en-us/library/windows/desktop/ms644947(v=vs.85). ...
- C# Invoke或者BeginInvoke的使用
在Invoke或者BeginInvoke的使用中无一例外地使用了委托Delegate. 一.为什么Control类提供了Invoke和BeginInvoke机制? 关于这个问题的最主要的原因已经是do ...
- C#调用SendMessage 用法
函数功能:该函数将指定的消息发送到一个或多个窗口.此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回.该函数是应用程序和应用程序之间进行消息传递的主要手段之一. 函数原型:LRESUL ...
- Windows API 函数列表 附帮助手册
所有Windows API函数列表,为了方便查询,也为了大家查找,所以整理一下贡献出来了. 帮助手册:700多个Windows API的函数手册 免费下载 API之网络函数 API之消息函数 API之 ...
- GetWord 3.3 屏幕取词
1. 缘起 要搞一个作弊软件,需要把屏幕上的试题取下来. 据说针对IE的取词很难,所以也就打消了自己开发的念头,找一找好用的控件. 发现了两个可以用的,一个是金山词霸的XdictGrb.dll文件,一 ...
- 利用C# Winform做Windows系统任务栏
最近公司做一个考试系统,需要一个答题栏,要求:占用屏幕上方一部分区域,而且始终置顶,当其他窗口最大化时"答题栏"始终置前并且不遮挡最大化窗口的任何部分!就像windows任务栏一样 ...
- windows消息机制详解(转载)
消息,就是指Windows发出的一个通知,告诉应用程序某个事情发生了.例如,单击鼠标.改变窗口尺寸.按下键盘上的一个键都会使Windows发送一个消息给应用程序.消息本身是作为一个记录传递给应用程序的 ...
- 在 Visual Studio 等编辑器/IDE中自动切换输入法,不需要手动的有没有?
使用Visual Studio写代码,经常遇到的一个问题就是切换中文输入法麻烦,输入完注释//,要切换到中文,输入完引号,要输入中文,然后还需要切换回来,有没有? 有时候中文输入法忽然失效有没有?明明 ...
随机推荐
- jQuery-prepend、append、before、after的区别
举例说明,原始html代码如下: <ol> <li>List item 1</li> <li>List item 2</li> <li ...
- 双网卡(一外一内)都启用,将内网卡默认网关去除即可正常连接Internet
- node入口文件分析和目录初始化
1.需要安装的模块 npm install express npm install jade npm install mongoose npm install bower -g npm install ...
- 重载<<操作符
回头看我们之前的 rational.cpp,你满意了吗?反正我是觉得那些代码的可读性仍然欠佳:main 函数里边要多次调用 print 方法才能实现分数打印,酱紫不行! 如何通过重载 << ...
- Deep Learning Libraries by Language
Deep Learning Libraries by Language Tweet Python Theano is a python library for defining and ...
- openstack cinder api对应的命令行接口
a) Create Volume cinder create 1 --display-name admin-volume1 cinder create --display-na ...
- vue项目不能同时被localhost和ip地址同时访问的方法
方法1.将index.js中的host的值改为‘0.0.0.0’ 方法2.修改package.json中script下dev的值,在后面加入--host 0.0.0.0 也可以解决
- 泉五培训Day2
T1 旅游 题目 [题目描述] 幻想乡有n个景点(从1开始标号),有m条双向的道路连在景点之间,每条道路有一个人气值d,表示这条道路的拥挤程度.小G不会经过那些人气值大于x的道路,她想知道有多少对景点 ...
- 3.2.5 Magic Squares 魔板
3.2.5 Magic Squares 魔板 成功地发明了魔方之后,鲁比克先生发明了它的二维版本,称作魔板.这是一张有8个大小相同的格子的魔板: 1 2 3 4 8 7 6 5 我们知道魔板的每一个方 ...
- http2.2配置
http: 超文本传输协议,工作在应用层 CentOS 6程序环境:httpd-2.2 配置文件: /etc/httpd/conf/httpd.conf /etc/httpd/conf.d/*.con ...