您的位置:首页 > 其它

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

2007-12-04 21:55 393 查看
由于接收消息必须要有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.

备注:第一个方法未测试。第三个方法关于“消息窗口”用百度搜索几乎找不到什么更多的资料,有待增加相关资料
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: