我指的是this thread来刷新Windows资源管理器,我只想刷新一些窗口,这意味着我想根据它们的标题或路径来过滤打开的窗口。让我的代码从线程复制更多的澄清:InvokeMember获取特定属性值的可能值
Guid CLSID_ShellApplication = new Guid("13709620-C279-11CE-A49E-444553540000");
Type shellApplicationType = Type.GetTypeFromCLSID(CLSID_ShellApplication, true);
object shellApplication = Activator.CreateInstance(shellApplicationType);
object windows = shellApplicationType.InvokeMember("Windows", System.Reflection.BindingFlags.InvokeMethod, null, shellApplication, new object[] { });
Type windowsType = windows.GetType();
object count = windowsType.InvokeMember("Count", System.Reflection.BindingFlags.GetProperty, null, windows, null);
for (int i = 0; i < (int)count; i++)
{
object item = windowsType.InvokeMember("Item", System.Reflection.BindingFlags.InvokeMethod, null, windows, new object[] { i });
Type itemType = item.GetType();
string itemName = (string)itemType.InvokeMember("Name", System.Reflection.BindingFlags.GetProperty, null, item, null);
if (itemName == "Windows Explorer")
{
// Here I want to check whether this window need to be refreshed
// based on the opened path in that window
// or with the title of that window
// How do I check that here
itemType.InvokeMember("Refresh", System.Reflection.BindingFlags.InvokeMethod, null, item, null);
}
}
我从上面的代码理解的是:通过使用此行windowsType.InvokeMember("Item", System.Reflection.BindingFlags.InvokeMethod, null, windows, new object[] { i });
我们将获得当前的窗口对象,然后我们使用.InvokeMember("Name"..
得到该对象的名称,明智的是什么,我应该通过InvokeMember
方法来获取该对象的路径或该窗口的标题?或者任何人都可以在上面的说明中告诉我"Name"
的可能替代值?
什么我期待像下面的一些代码:
string itemPath = (string)itemType.InvokeMember("Something here", System.Reflection.BindingFlags.GetProperty, null, item, null);
OR
string itemTitle = (string)itemType.InvokeMember("Something here", System.Reflection.BindingFlags.GetProperty, null, item, null);
,如果你需要我可以给你更多的信息,希望专家的建议来解决这个问题,
在此先感谢
谢谢先生,我会upvote一旦我得到15 – Learning