How can I reliably determine the window handle for a given Outlook inspector window with WordMail enabled from COM-Addin (Outlook <= 2003)?

[This code is called from the event handler Inspector.Activate(first call), that is, right before the inspector window is actually displayed.]

For native mail inspectors, I can simply use the QI interface Inspectorfor IOleWindowand call its method GetWindow. However, this will not work for Word inspectors, who are actually instances of Word with a special toolbar and do not implement it IOleWindow.

(Temporarily) setting Inspector.Captionfor some unique value and then searching for a window with this title also does not work, since access to most of the properties Inspectorsimply does not have an (immediate) effect on the actual inspector window when using the WordMail option. It also doesn’t make a call Activate, and then immediately the request GetForegroundWindowworks reliably: when several inspectors are already open or when actual Word windows are present, it often just returns the “oldest” instance instead of the last one.

, . , , , - ? ( P Daddy CBT)

+3
2

- , , . , , , , EnumWindows, () , .. IsWindowVisible False (, Inspector.Activate , ).

- , ( ), .

: , , (Delphi) . , , , , .

function GetWindowClassName(const AHandle: HWND): String;
var
  lClass: array[0..255] of Char;
begin
  if GetClassName(AHandle, lClass, SizeOf(lClass)) > 0 then
    Result := lClass
  else
    Result := '';
end;

type
  TWordSearchInfo = record
    Result: HWND;
  end;
  PWordSearchInfo = ^TWordSearchInfo;

function CheckWnd(AWnd: HWND; ASearchInfo: PWordSearchInfo): Boolean; stdcall;
begin
  Result := True;
  try
    if GetWindowClassName(AWnd) = 'OpusApp' then
      if not IsWindowVisible(AWnd) then
        begin
          ASearchInfo.Result := AWnd;
          Exit(False);
        end;
  except
    //plop!
  end;
end;

function GetNewestWordHandle: Cardinal;
var
  lSearchInfo: TWordSearchInfo;
begin
  lSearchInfo.Result := 0;
  EnumWindows(@CheckWnd, Integer(@lSearchInfo));
  Result := lSearchInfo.Result;
end;

: Activate -event Outlook < 12, IsWordMail -property True.

+1

, .

#

inspectorWindow = Win32.FindWindowEx(IntPtr.Zero, IntPtr.Zero, "OpusApp", "Microsoft Word");

, ( " " ). , Microsoft Word, , - , , , .

0

Source: https://habr.com/ru/post/1699710/


All Articles