How can you know if the Outlook application has focus?

  • Thread starter Thread starter Robert Davidson
  • Start date Start date
R

Robert Davidson

I would like to find out whether the Outlook application (not one of its
child windows) has the focus.

I am able to do this in Word and Excel by calling the GetFocus API with the
Application.hwnd property.

Outlook's Application object does not have an hwnd property - does anyone
know how to find out whether it has the focus?

I tried working around it by assigning OlActive = True during the Activate
event of the ActiveExplorer and OlActive = False during the Deactivate
event, but those events trigger whenever an item has focus, not only when
the pplication has focues.

Best Regards,

Robert Davidson
 
Robert-

Off the top of my head, you could use the API function
GetForegroundWindow() to get the handle of the Foreground
window, get its caption using the GetWindowText() API, and
search the caption text for "Microsoft Outlook" - which
should appear at the end of the caption. I can't think of
a better way at the moment, but this will work.

If you want to then set the focus to Outlook, once you
have its window's handle, pass it to SetForegroundWindow().

Declares & exapmles for all these APIs are available at
http://www.mentalis.org/index2.shtml .

HTH,

-Andrew Cushen
=======================================
 
Back
Top