| 1305 | } |
| 1306 | |
| 1307 | HRESULT ExecuteActionFromContextMenu(PCIDLIST_ABSOLUTE pidlDirectory, PCITEMID_CHILD *ppidl, |
| 1308 | HWND hwndOwner, int nFiles, const TCHAR *szAction, DWORD fMask) |
| 1309 | { |
| 1310 | IShellFolder *pShellParentFolder = NULL; |
| 1311 | IShellFolder *pShellFolder = NULL; |
| 1312 | IContextMenu *pContext = NULL; |
| 1313 | PCITEMID_CHILD pidlRelative = NULL; |
| 1314 | CMINVOKECOMMANDINFO cmici; |
| 1315 | HRESULT hr = S_FALSE; |
| 1316 | char szActionA[32]; |
| 1317 | |
| 1318 | if (nFiles == 0) |
| 1319 | { |
| 1320 | hr = SHBindToParent(pidlDirectory, IID_PPV_ARGS(&pShellParentFolder), &pidlRelative); |
| 1321 | |
| 1322 | if (SUCCEEDED(hr)) |
| 1323 | { |
| 1324 | hr = GetUIObjectOf( |
| 1325 | pShellParentFolder, hwndOwner, 1, &pidlRelative, IID_PPV_ARGS(&pContext)); |
| 1326 | |
| 1327 | pShellParentFolder->Release(); |
| 1328 | pShellParentFolder = NULL; |
| 1329 | } |
| 1330 | } |
| 1331 | else |
| 1332 | { |
| 1333 | hr = BindToIdl(pidlDirectory, IID_PPV_ARGS(&pShellFolder)); |
| 1334 | |
| 1335 | if (SUCCEEDED(hr)) |
| 1336 | { |
| 1337 | hr = GetUIObjectOf(pShellFolder, hwndOwner, nFiles, ppidl, IID_PPV_ARGS(&pContext)); |
| 1338 | pShellFolder->Release(); |
| 1339 | } |
| 1340 | } |
| 1341 | |
| 1342 | if (SUCCEEDED(hr)) |
| 1343 | { |
| 1344 | /* Action string MUST be ANSI. */ |
| 1345 | WideCharToMultiByte( |
| 1346 | CP_ACP, 0, szAction, -1, szActionA, SIZEOF_ARRAY(szActionA), NULL, NULL); |
| 1347 | |
| 1348 | cmici.cbSize = sizeof(CMINVOKECOMMANDINFO); |
| 1349 | cmici.fMask = fMask; |
| 1350 | cmici.hwnd = hwndOwner; |
| 1351 | cmici.lpVerb = szActionA; |
| 1352 | cmici.lpParameters = NULL; |
| 1353 | cmici.lpDirectory = NULL; |
| 1354 | cmici.nShow = SW_SHOW; |
| 1355 | |
| 1356 | hr = pContext->InvokeCommand(&cmici); |
| 1357 | |
| 1358 | pContext->Release(); |
| 1359 | pContext = NULL; |
| 1360 | } |
| 1361 | |
| 1362 | return hr; |
| 1363 | } |
| 1364 |
no test coverage detected