在尝试使用 ShellExecute 来打开文件属性对话框的时候,发现下面的调用总是失败,属性对话框不能打开,返回值是 SE_ERR_NOASSOC:
ShellExecute(hWnd, _T(
"properties"
), szFile, NULL, NULL, SW_SHOWNORMAL);
|
百思不得其解,后来参考了一下AutoHotkey的代码转用 ShellExecuteEx,总算可以打开属性对话框了:
1
2
3
4
5
6
7
8
9
10
11
|
SHELLEXECUTEINFO sei = {0};
sei.cbSize =
sizeof
(sei);
// SEE_MASK_INVOKEIDLIST is needed for the "properties" verb to work reliably.
sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI | SEE_MASK_INVOKEIDLIST;
sei.lpDirectory = NULL;
// OK if NULL or blank; that will cause current dir to be used.
sei.nShow = SW_SHOWNORMAL;
sei.lpVerb = _T(
"properties"
);
sei.lpFile = GetDocument()->GetPathName();
sei.lpParameters = NULL;
sei.hwnd = GetSafeHwnd();
BOOL
bRet = ShellExecuteEx(&sei);
|
ps.有几点要记录一下:
1、hwnd 指向的窗口如果是隐藏的时候会有一些副作用;
2、lpVerb必须是 "properties ","Properties"会失败。
转自:http://www.cnblogs.com/yonken/archive/2010/02/23/ShellExecute_Fail_To_Open_Properties_Dialog.html