关于接收消息的问题(尚有疑问,未完待续)

本文介绍了在无需显示窗口的情况下接收消息的三种方法:自定义窗口句柄、建立隐藏窗口及创建消息窗口。消息窗口不具可见性,无Z顺序,不可枚举且不接收广播消息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由于接收消息必须要有hwnd,也就是需要有个窗口对应才能接收消息,但有些情况下不需要这个窗口却又想要能够接收消息,找了下,大概有这么些办法:

1、在一个BCB版块看到有个人提问在dll中不用窗口怎么接收消息的一个回答:

自定义一个窗口句柄:
  申请:AllocateHWnd  
  释放:DeallocateHWnd  
  就可以接受和发送消息啦

2、建立一个普通的隐藏窗口,只用于处理消息,不干其它事情

3、建立一个“消息窗口(Message-Only窗口)”,这种窗口仅仅用于处理消息,而不能被显示出来。

在创建时指定CreateWindowEx的参数hwndParent为HWND_MESSAGE.   或在创建窗口后SetParent(hWnd,   HWND_MESSAGE);即可建立一个“消息窗口”

附:

Message-Only   Windows  
  A   message-only   window   enables   you   to   send   and   receive   messages.   It   is   not   visible,   has   no   Z   order,   cannot   be   enumerated,   and   does   not   receive   broadcast   messages.   The   window   simply   dispatches   messages.    
   
  To   create   a   message-only   window,   specify   the   HWND_MESSAGE   constant   or   a   handle   to   an   existing   message-only   window   in   the   hWndParent   parameter   of   the   CreateWindowEx   function.   You   can   also   change   an   existing   window   to   a   message-only   window   by   specifying   HWND_MESSAGE   in   the   hWndNewParent   parameter   of   the   SetParent   function.    
   
  To   find   message-only   windows,   specify   HWND_MESSAGE   in   the   hwndParent   parameter   of   the   FindWindowEx   function.   In   addition,   FindWindowEx   searches   message-only   windows   as   well   as   top-level   windows   if   both   the   hwndParent   and   hwndChildAfter   parameters   are   NULL.

 

备注:第一个方法未测试。第三个方法关于“消息窗口”用百度搜索几乎找不到什么更多的资料,有待增加相关资料

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值