我指的是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