获取Path所有打开的Windows - WinAPI [英] Get Path all of opened Windows - WinAPI

查看:67
本文介绍了获取Path所有打开的Windows - WinAPI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,



我有一些打开的目录和应用程序出现在任务栏中。如何获取它们的路径?



例如:有1个打开的目录:C:\ Windows和2个应用程序D:\ Data\Word.doc和D:\ Data\text.txt。



我想通过调用EnumWindow来获取Window Handle的路径



你有什么解决方案吗?



谢谢

解决方案

I可以帮助你入门:



首先查询拥有你正在查询的窗口的processID



GetWindowThreadProcessId [ ^ ]



然后打开一个句柄,使用PROCESS_QUERY_INFORMATION访问该过程:



OpenProcess [ ^ ]



使用流程句柄,您可以获取名称正在运行该程序的应用程序:



GetProcessImageFileName [ ^ ]



要实际获取某些打开文件的路径,很可能取决于程序,以确保您的信息可靠。可能Explorer.exe更改了当前文件夹的工作目录,但我不确定。基于文档的程序,您可以查看该过程的打开文件句柄,但也无法保证。



特别适用于基于Word和MS Office的应用程序,我会调查他们的脚本对象。他们很可能能够报告他们正在为每个流程实例使用哪个文档。


您可能会收到错误,因为您没有指定所需的Windows API版本。



启用Windows 7级API的示例:



 #define WINVER 0x0601 
#include< windows.h>







来源:http://msdn.microsoft.com/en-us/library/6sehtctf.aspx


Dear all,

I have some opened directories and application appear in taskbar. How to get path of them?

For example: There are 1 opened directory: C:\Windows and 2 application D:\Data\Word.doc and D:\Data\text.txt.

I want to get path of them by their Window Handle by calling EnumWindow

Do you have any solution?

Thank you

解决方案

I can help get you started:

Start by querying for the processID that owns the window you are querying

GetWindowThreadProcessId[^]

Then open a handle with PROCESS_QUERY_INFORMATION access to the process:

OpenProcess[^]

With the process handle, you can get the name of the application that is running the process:

GetProcessImageFileName[^]

To actually get the path of some open file, it will most likely be program dependent for your information to be reliable. Possibly Explorer.exe changes the working directory for the current folder, but I dont know for sure. Document based programs you could possibly look at the open file handles for that process, but there is no guarantee for that either.

For Word and MS Office based apps specifically, I would investigate their scripting objects. They will most likely be able to report which document they are using for each process instance.


You probably getting an error because you didn't specify version of windows api you want.

Example to enable windows 7 level api:

#define WINVER 0x0601
#include <windows.h>




Source:http://msdn.microsoft.com/en-us/library/6sehtctf.aspx


这篇关于获取Path所有打开的Windows - WinAPI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆