hmm... I tried it and it crashed too. Never mind, I found a better way. This example lists all the selected items and displays them in a message box:HWND hWndBrowser = ::GetAncestor(m_hWnd, GA_ROOT); char szBuf[4096]; IShellBrowser *pISB = (IShellBrowser*)SendMessage(hWndBrowser, WM_USER+7, 0, NULL); if (pISB) { IShellView *pISV = NULL; if (SUCCEEDED(pISB->QueryActiveShellView(&pISV))) { IDataObject *pIDO; HDROP hDrop; UINT uNumFiles; char szFile[MAX_PATH]; pISV->GetItemObject(SVGIO_SELECTION, IID_IDataObject, (void**)&pIDO); FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM stg = { TYMED_HGLOBAL }; if ( FAILED( pIDO->GetData ( &etc, &stg ))) return E_INVALIDARG; hDrop = (HDROP) GlobalLock ( stg.hGlobal ); if ( !hDrop ) { ReleaseStgMedium ( &stg ); return E_INVALIDARG; } uNumFiles = DragQueryFile ( hDrop, 0xFFFFFFFF, NULL, 0 ); szBuf[0] = '\0'; for (UINT uFile = 0; uFile < uNumFiles; uFile++) { if (!DragQueryFile( hDrop, uFile, szFile, MAX_PATH )) continue; wsprintf(szBuf, "%s\n%s", szBuf, szFile); } MessageBox(lpcmi->hwnd, szBuf, "Selected Files", MB_OK); GlobalUnlock ( stg.hGlobal ); ReleaseStgMedium ( &stg ); pIDO->Release(); pISV->Release(); } }
This is called from within a band object's IContextMenu::InvokeCommand() method, m_hWnd
is the band object's window handle. Since you already have the handle to the main explorer window, you won't have to call GetAncestor().