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. Java Map应用

    一.基本API使用方法 直接上代码,注释讲解 package com.map; import java.util.HashMap; import java.util.Iterator; import ...

  2. Office加载项安装

    出自我的个人主页 Alvin Blog 前言 Excel加载项离不开安装,Excel加载项本身安装及其简单,但这是在申请下来Office开发者账户之后,再次之前都得自行安装 线上安装 微软申请开发者账 ...

  3. Properties的使用以及配置文件值的获取

    一.项目的部署如下,现在要获取SystemGlobals.properties中的值 二.代码如下: package com.util; import java.io.IOException; imp ...

  4. IIS7 http自动跳转到https(通过编辑Web.config实现)

    本文摘自:https://www.cnblogs.com/wxbug/p/7054972.html 1.下载安装URL重写模块:Microsoft URL Rewrite Module 32位:htt ...

  5. STM32开发-MDK新建工程及配置

    本人也是接触stm32没多久,之前用的MDK是5.1,现在用的是5.13,MDK5.0之前的版本(本人简称旧版)和之后的版本(本人简称新版)新建工程有很大区别.对于刚开始用学stm32的新手来说,基本 ...

  6. 20145238-荆玉茗 《Java程序设计》第8周学习总结

    20145238 <Java程序设计>第8周学习总结 教材学习内容总结 第15章 通用API 15.1.1 ·java.util.logging包提供了日志功能相关类与接口,使用日志的起点 ...

  7. MySQL 中while loop repeat 的基本用法

    -- MySQL中的三中循环 while . loop .repeat 求 1-n 的和 -- 第一种 while 循环 -- 求 1-n 的和 /* while循环语法: while 条件 DO 循 ...

  8. HTTP head meta

    HTTP(HyperTextTransferProtocol)即超文本传输协议,目前网页传输的的通用协议.HTTP协议采用了请求/响应模型,浏览器或其他客户端发出请求,服务器给与响应.就整个网络资源传 ...

  9. Ecliplse 重命名后web.xml 报错Attribute "xmlns" was already specified for element "web-app".

      报错信息:Attribute "xmlns" was already specified for element "web-app" 由于项目的重命名,出现 ...

  10. 【转】javascript中not defined、undefined、null以及NaN的区别

    原文链接(点击跳转) 第一:not defined 演示代码:   <span style="font-size:12px;"><span style=" ...