按名称捕获Windows注册消息



在Windows平板电脑上有两个屏幕键盘应用程序(据我所知),c:program filescommon filesmicrosoft sharedinktabtip.exe和C:WindowsSystem32 OSK.exe .

我想捕获这些应用程序在启动时发送给我的应用程序的消息,放置在我的应用程序顶部,以及当它们关闭时。

然后我可以检查IsIconic作为保险,尽可能多地知道键盘处于什么状态,这样我就可以相应地调整我的应用程序显示。

使用spy++,我为TabTip捕获了以下消息:

<000050> 00130426 p message:0xC298 [Registered:"ImmersiveFocusNotification"] wParam:FFFFFFFC lParam:00000000

<000051> 00130426 p message:0xC297 [Registered:"TipCloseMenus"] wParam:00000000 lParam:00000000

<000052> 00130426 p message:0xC061 [Registered:"TabletInputPanelOpening"] wParam:00000000 lParam:00000000

我认为有一个Windows API调用可以让我注册到操作系统来接收这些消息在我的应用程序的窗口过程中,或者使用消息处理程序来获得通知,但我似乎找不到它。

虽然这些消息显示在我的应用程序的消息队列在spy++中,我似乎无法识别他们在我的WindowProc,和Delphi不允许我指定一个消息处理过程为这些消息id在49xxx范围内。

有谁知道按名字注册这些消息的方法吗?我认为这可以通过使用像

这样的字符串来实现。

TabletInputPanelOpening

TipCloseMenus

以便当操作系统处理该名称的消息时,我的应用程序可以接收/处理它?

谢谢。

Update: With an Application。OnMessage处理程序,如果我忽略消息发送到的句柄,我就可以接收消息。我假设这意味着这是一个广播消息(?)。

我仍然需要知道如何注册以接收以下消息:

1)由PostMessage或SendMessage发送

2)使用RegisterWindowMessage

建立系统

3)有一个命名常量来标识消息,例如'TipCloseMenus'或'TaskbarCreated'

更新# 2:我发现了一个旧的例子,显示RegisterWindowMessage和GetClipboardFormatName似乎使用相同的内部表来存储注册的窗口消息和剪贴板格式。用TMsg调用GetClipboardFormatName。Message作为参数查找messageid的标签。显然,在某种程度上,这些消息存储在同一个内部表中。下面是一些示例代码来说明:

function GetRegisteredWindowMessageLabel(var Msg: TMsg): UnicodeString;
var
  ay: array[0..99] of Char;
  i: Integer;
begin
  Result := '';
  if (Msg.message <= $FFFF) and (Msg.message >= $C000) then
  begin
    i := GetClipboardFormatName(Msg.message,ay,Pred(SizeOf(ay)));
    if i > 0 then
      Result := StrPas(ay);
  end;
end;

谢谢。

不能为已注册消息编写编译时消息处理程序,因为它们不使用静态消息id。您必须在运行时调用RegisterWindowMessage(),然后使用注册的id过滤收到的消息,例如:

var
  msgImmersiveFocusNotification: UINT = 0;
  msgTipCloseMenus: UINT = 0;
  msgTabletInputPanelOpening: UINT = 0;
  msgTaskbarCreated: UINT = 0;
procedure TMainForm:FormCreate(Sender: TObject);
begin
  msgImmersiveFocusNotification := RegisterWindowMessage('ImmersiveFocusNotification');
  msgTipCloseMenus := RegisterWindowMessage('TipCloseMenus');
  msgTabletInputPanelOpening := RegisterWindowMessage('TabletInputPanelOpening');
  msgTaskbarCreated := RegisterWindowMessage('TaskbarCreated');
end;
procedure TMainForm.WndProc(var Message: TMessage);
begin
  inherited;
  if (msgImmersiveFocusNotification <> 0) and (Message.Msg = msgImmersiveFocusNotification) then
  begin
    //...
  end
  else if (msgTipCloseMenus <> 0) and (Message.Msg = msgTipCloseMenus) then
  begin
    //...
  end
  else if (msgTabletInputPanelOpening <> 0) and (Message.Msg = msgTabletInputPanelOpening) then
  begin
    //...
  end
  else if (msgTaskbarCreated <> 0) and (Message.Msg = msgTaskbarCreated) then
  begin
    //...
  end;
end;

最新更新