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 BUTTONEDITLISTBOX, 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的更多相关文章

  1. Delphi消息的广播方式(先RegisterWindowMessage,后SendMessage HWND_BROADCAST,最后改写接收窗口的WndProc)

    ///////消息广播只能将消息传递到接收消息的主程序中,MDIChild窗体不能接收到广播消息:///////// unit Unit1; interface uses Windows, Messa ...

  2. RegisterWindowMessage介绍

    该函数为windows API之一 msdn地址:https://msdn.microsoft.com/en-us/library/windows/desktop/ms644947(v=vs.85). ...

  3. C# Invoke或者BeginInvoke的使用

    在Invoke或者BeginInvoke的使用中无一例外地使用了委托Delegate. 一.为什么Control类提供了Invoke和BeginInvoke机制? 关于这个问题的最主要的原因已经是do ...

  4. C#调用SendMessage 用法

    函数功能:该函数将指定的消息发送到一个或多个窗口.此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回.该函数是应用程序和应用程序之间进行消息传递的主要手段之一.    函数原型:LRESUL ...

  5. Windows API 函数列表 附帮助手册

    所有Windows API函数列表,为了方便查询,也为了大家查找,所以整理一下贡献出来了. 帮助手册:700多个Windows API的函数手册 免费下载 API之网络函数 API之消息函数 API之 ...

  6. GetWord 3.3 屏幕取词

    1. 缘起 要搞一个作弊软件,需要把屏幕上的试题取下来. 据说针对IE的取词很难,所以也就打消了自己开发的念头,找一找好用的控件. 发现了两个可以用的,一个是金山词霸的XdictGrb.dll文件,一 ...

  7. 利用C# Winform做Windows系统任务栏

    最近公司做一个考试系统,需要一个答题栏,要求:占用屏幕上方一部分区域,而且始终置顶,当其他窗口最大化时"答题栏"始终置前并且不遮挡最大化窗口的任何部分!就像windows任务栏一样 ...

  8. windows消息机制详解(转载)

    消息,就是指Windows发出的一个通知,告诉应用程序某个事情发生了.例如,单击鼠标.改变窗口尺寸.按下键盘上的一个键都会使Windows发送一个消息给应用程序.消息本身是作为一个记录传递给应用程序的 ...

  9. 在 Visual Studio 等编辑器/IDE中自动切换输入法,不需要手动的有没有?

    使用Visual Studio写代码,经常遇到的一个问题就是切换中文输入法麻烦,输入完注释//,要切换到中文,输入完引号,要输入中文,然后还需要切换回来,有没有? 有时候中文输入法忽然失效有没有?明明 ...

随机推荐

  1. 数组模拟栈(C语言)

    用数组模拟栈的实现: #include <stdio.h> #include <stdlib.h> #define STACK_SIZE 100 typedef struct ...

  2. meta详解(常用)

    1.<meta http-equiv="X-UA-Compatible" content="IE=edge"> 说明:设置浏览器的兼容模式版本.表示 ...

  3. QT学习之QString的arg方法

    在QT的QString中,arg方法类似于C中的printf中使用的格式输出符(只是有点类似). 在QT5的帮助文档中,可以看出以下几点: 使用arg(str1, str2, str3)这种方法进行替 ...

  4. Java中调用MatLab返回值

    当在Java中使用MatLab函数时,由于语言语法的不同,Matlab返回多个数据时,想在Java中获取到并进行使用.查阅了网上资料,翻箱倒柜加上自己实战,得出方法如下: 如MatLab函数返回的是N ...

  5. 贪心,二叉树搜索,ZOJ(2315)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1315 解题报告: #include <stdio.h> ...

  6. spring中使用i18n(国际化)

    简单了解i18n i18n(其来源是英文单词internationalization的首末字符i和n,18为中间的字符数)是“国际化”的简称.在资讯领域,国际化(i18n)指让产品(出版物,软件,硬件 ...

  7. CUDA中多维数组以及多维纹理内存的使用

    纹理存储器(texture memory)是一种只读存储器,由GPU用于纹理渲染的图形专用单元发展而来,因此也提供了一些特殊功能.纹理存储器中的数据位于显存,但可以通过纹理缓存加速读取.在纹理存储器中 ...

  8. java设计模式——外观模式(门面模式)

    一. 定义与类型 定义:门面模式,提供一个统一的接口,用来访问子系统中的一群接口,门面模式定义了一个高层接口,让子系统更容易使用 类型:结构性 二. 使用场景 子系统越来越复杂,增加外观模式提供简单调 ...

  9. C# do while语句

    一.C# do while语句 do while语句是先执行一次循环体,然后再判断是否需要重复执行循环体的循环控制语句. 语法格式如下: do{    embedded-statement}while ...

  10. mask r-cnn

    mask R-cnn, kaiming he的新作.可以同时完成object detection和segmentation,还可以做pose estimation,简直就是功能多多啊.在coco上测试 ...