【发布时间】:2016-04-05 14:43:03
【问题描述】:
我正在尝试打开默认文件属性对话框,但无法为其在不同目录中的文件设置工作属性。
我需要为不同目录(甚至驱动器)中的文件获取IContextMenu* 接口指针。
我希望在属性对话框中看到“各种文件夹”。
这是我幼稚的做法:
int main() {
CoInitialize(NULL);
LPOLESTR pszFile = OLESTR("c:\\Windows\\notepad.exe");
LPOLESTR pszFile2 = OLESTR("c:\\Windows\\System32\\notepad.exe");
LPITEMIDLIST pidl;
LPITEMIDLIST pidl2;
LPCITEMIDLIST pidlItem;
LPCITEMIDLIST pidlItem2;
HRESULT hr;
IShellFolder* pFolder;
IContextMenu* pContextMenu;
CMINVOKECOMMANDINFO cmi;
hr = SHGetDesktopFolder(&pFolder);
if (FAILED(hr)) return 0;
hr = pFolder->ParseDisplayName(HWND_DESKTOP, NULL, pszFile, NULL, &pidl, NULL);
hr = pFolder->ParseDisplayName(HWND_DESKTOP, NULL, pszFile2, NULL, &pidl2, NULL);
pFolder->Release();
if (FAILED(hr)) return 0;
hr = SHBindToParent(pidl, IID_IShellFolder, (void **)&pFolder, &pidlItem);
if (FAILED(hr)) {
SHFree(pidl);
return 0;
}
//pFolder->Release();
hr = SHBindToParent(pidl2, IID_IShellFolder, (void **)&pFolder, &pidlItem2);
if (FAILED(hr)) {
SHFree(pidl2);
return 0;
}
LPCITEMIDLIST list[] = {pidlItem, pidlItem2};
hr = pFolder->GetUIObjectOf(HWND_DESKTOP, 2, (LPCITEMIDLIST *)list, IID_IContextMenu, NULL, (void **)&pContextMenu);
pFolder->Release();
if (SUCCEEDED(hr)) {
ZeroMemory(&cmi, sizeof(cmi));
cmi.cbSize = sizeof(cmi);
cmi.lpVerb = "properties";
cmi.nShow = SW_SHOWNORMAL;
hr = pContextMenu->InvokeCommand(&cmi);
MessageBox(0, _T("Dummy message box"), 0, 0);
Sleep(10000); // Give the system time to show the dialog before exiting
pContextMenu->Release();
}
SHFree(pidl);
return 0;
}
我也试过this,但它也根本不起作用。 我还尝试使用桌面 IShellFolder 作为我的 PIDL 的父级,但它也无法正常工作。
有什么想法吗?
【问题讨论】: