Tech Support > Microsoft Windows > Development Resources > file path with getforegroundwindow
file path with getforegroundwindow
Posted by carolinevdp@hotmail.com on June 28th, 2007


Hi,

I have a program that returns the current active window using
GetForegroundWindow.
If the window is a word doc for e.g., is there a way to get the
absolute path of the file.

Thanks

Posted by Scott McPhillips [MVP] on June 29th, 2007


carolinevdp@hotmail.com wrote:
SendMessage(WM_GETTEXT, ...) will get you the text from the window's
title bar. That will include the file name but not the full path.

For Word and the other Office applications it is possible to use their
object model, via COM, to query the full path and file name.

--
Scott McPhillips [MVP VC++]


Posted by carolinevdp@hotmail.com on June 29th, 2007


Thank Scott,

I settled for getting information on the file, the
BY_HANDLE_FILE_INFORMATION
but when I do (GetFileInformationByHandle(foregroundWindow,&st1) ) it
returns 0 ,the error code is 6 ("The handle is invalid").
Any idea why?

Thanks

On Jun 28, 5:28 pm, "Scott McPhillips [MVP]" <org-dot-mvps-at-
scottmcp> wrote:


Posted by Scott Seligman [MSFT] on June 29th, 2007


carolinevdp@hotmail.com wrote:
GetFileInformationByHandle expects a handle to a file, not a handle to
a window.

There is no generic way to get what you want, since a given window
will not necessarily be backed by a file. If you want to know what
file an application has open, you'll need to ask it. For Office apps
this can be done with the Office COM object model. For other
applications the technique will differ.

--
Scott Seligman [MSFT]
This posting is provided AS IS with no warranties, and confers
no rights.


Similar Posts