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写代码,经常遇到的一个问题就是切换中文输入法麻烦,输入完注释//,要切换到中文,输入完引号,要输入中文,然后还需要切换回来,有没有? 有时候中文输入法忽然失效有没有?明明 ...
随机推荐
- ansible使用6-Conditionals
when tasks: - name: "shutdown Debian flavored systems" command: /sbin/shutdown -t now when ...
- Linux目录与文件的权限意义
ls -l和ls -al的区别:第一个不会显示隐藏文件,第二个会显示隐藏文件(以点(.)开头的文件) 一.权限对文件(r.w.x主要针对文件的内容而言)的重要性 r:可读取文件内容 w:可以编辑.新增 ...
- JavaScript基础:字符串转换函数——String()和toString()
1..toString()可以将所有的的数据都转换为字符串,但是要排除null 和 undefined 例如将false转为字符串类型 <script> var str = false ...
- 数据结构(C#):图的最短路径问题、(Dijkstra算法)
今天曾洋老师教了有关于图的最短路径问题,现在对例子进行一个自己的理解和整理: 题目: 要求:变成计算出给出结点V1到结点V8的最短路径 答: 首先呢,我会先通过图先把从V1到V8的各种路径全部计算下来 ...
- 西门子触摸屏利用VBScript脚本创建csv文件
功能描述:利用VBScript脚本创建csv/txt文件 有时需要将PLC或运动控制器Simotion中的数据写到SD卡或U盘上.一种实现方法是,如果使用的是精致面板(comfort panel),可 ...
- 从windows CMD 命令行(CMD promp)运行Docker
英文原帖 Running Docker from Windows CMD prompt https://medium.com/@neil.avery_68603/running-docker-from ...
- April 27 2017 Week 17 Thursday
Had I not seen the sun, I could have borne the shade. 我本可以忍受黑暗,如果我不曾见过阳光. A poem by Emily Dickinson, ...
- UE4的蓝图都能做什么
创建关卡脚本 蓝图具有和虚幻3中Kismet一样的功能,每个关卡都由自己的蓝图,他可以: 引用和操控actors 控制使用Matinee的过场 管理关卡流,存档点以及其他关卡相关的系统 和关卡中的类蓝 ...
- CSS:响应式下的折叠菜单(条纹式)
原文:CSS: Responsive Navigation Menu 译文:CSS:响应式导航菜单 译者:dwqs 写在之前,关于如何制作响应式的下拉菜单:响应式下的下拉菜单 之前,我写了一篇关于怎么 ...
- react里面 react-router4 跳转
在react里面跳转的时候,一般可以用 <Link to='/tradeList' /> 但是我们在运用组件组合的时候经常会通过传参去判断,如果props传过来是参数,如果有link进行跳 ...