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写代码,经常遇到的一个问题就是切换中文输入法麻烦,输入完注释//,要切换到中文,输入完引号,要输入中文,然后还需要切换回来,有没有? 有时候中文输入法忽然失效有没有?明明 ...
随机推荐
- dell omsa管理工具
dell服务器raid管理工具 lsiutil dell sas6i/r MegaCli dell prec omsa管理raid分区 显示物理硬盘信息 omreport storage pdisk ...
- 用户管理的设计--3.jquery的ajax实现二级联动
页面效果 实现步骤 1.引入struts整合json的插件包 2.页面使用jquery的ajax调用二级联动的js //ajax的二级联动,使用选择的所属单位,查询该所属单位下对应的单位名称列表 fu ...
- 解决频繁自动弹出“QQ拼音升级程序”,可使用旧版QQ输入法
QQ输入法(2017年9月6日版本)下载地址: http://dlc2.pconline.com.cn/filedown_90891_8506339/BZXMP3fp/QQPinyin_Setup_5 ...
- 816 Ambiguous Coordinates (many cases problem)
https://www.cnblogs.com/Java3y/p/8846955.html -- link of the problem 816 IDEA: check the dot and int ...
- cesium 加载倾斜摄影模型(这里有一坑)
代码如下: // Construct the default list of terrain sources. var terrainModels = Cesium.createDefaultTerr ...
- uva题库爬取
每次进uva都慢的要死,而且一步一步找到自己的那个题目简直要命. 于是,我想到做一个爬取uva题库,记录一下其中遇到的问题. 1.uva题目的链接是一个外部的,想要获取https资源,会报出SNIMi ...
- 【转】Druid连接池一个设置引发的血案
https://my.oschina.net/haogrgr/blog/224010 今天在一台配置很低的机器上运行批量更新的程序~~~ 大概跑了三十分钟~~~这配置~~~这程序~~~ 然后华丽丽的报 ...
- Spring详解篇之IoC控制反转
###一.Spring概况 spring是一个开源框架 是一个轻量的控制反转和面向切面的容器框架 大小和开销都是轻量的. 通过控制反转技术可以达到松耦合的目的 切面编程,允许通过分离应用的业务逻辑. ...
- Java分享笔记:Map集合(接口)的基本方法程序演示
package pack02; import java.util.*; public class MapDemo { public static void main(String[] args) { ...
- mysql 数据库设计规范
MySQL数据库设计规范 目录 1. 规范背景与目的 2. 设计规范 2.1 数据库设计 2.1.1 库名 2.1.2 表结构 2.1.3 列数据类型优化 2.1.4 索引设计 2.1.5 分库分表. ...