[This code is called from within the Inspector.Activate
event handler (first call), i.e. right before the inspector window is actually shown.]
For "native" mail inspectors I can simply QI the Inspector
interface to IOleWindow
and call its GetWindow
method. However, this will not work for Word inspectors which are in fact instances of Word with a special toolbar and do not implement IOleWindow
.
(Temporarily) setting Inspector.Caption
to some unique value and then looking for a window with that caption also does not work as accessing most properties of the Inspector
simply has no (immediate) effect on the actual inspector window when using the WordMail option. Neither does calling Activate
and then immediately querying GetForegroundWindow
work reliably: when there are multiple inspectors already open or when actual Word windows are present this will often just return the "oldest" instance instead of the most recent one.
I have tried a number of other approaches over the years but they all eventually turned out to be flawed in some way or another. Is there a moderately simple solution to this at all or will I have to go for a much more elaborate approach like keeping my own list of known window handles via a system hook and trying to match them up against the known inspectors somehow? (hat tip to P Daddy for the hint about using CBT hooks)