static void test_IShellFolderView(void) { IShellFolderView *folderview; IShellFolder *desktop; IShellView *view; IDataObject *obj; UINT i; HRESULT hr; hr = SHGetDesktopFolder(&desktop); ok(hr == S_OK, "got (0x%08x)\n", hr); hr = IShellFolder_CreateViewObject(desktop, NULL, &IID_IShellView, (void**)&view); ok(hr == S_OK, "got (0x%08x)\n", hr); hr = IShellView_QueryInterface(view, &IID_IShellFolderView, (void**)&folderview); if (hr != S_OK) { win_skip("IShellView doesn't provide IShellFolderView on this platform\n"); IShellView_Release(view); IShellFolder_Release(desktop); return; } /* ::MoveIcons */ obj = IDataObjectImpl_Construct(); hr = IShellFolderView_MoveIcons(folderview, obj); ok(hr == E_NOTIMPL || broken(hr == S_OK) /* W98 */, "got (0x%08x)\n", hr); IDataObject_Release(obj); /* ::SetRedraw without list created */ hr = IShellFolderView_SetRedraw(folderview, TRUE); ok(hr == S_OK, "got (0x%08x)\n", hr); /* ::QuerySupport */ hr = IShellFolderView_QuerySupport(folderview, NULL); ok(hr == S_OK, "got (0x%08x)\n", hr); i = 0xdeadbeef; hr = IShellFolderView_QuerySupport(folderview, &i); ok(hr == S_OK, "got (0x%08x)\n", hr); ok(i == 0xdeadbeef, "got %d\n", i); /* ::RemoveObject */ i = 0xdeadbeef; hr = IShellFolderView_RemoveObject(folderview, NULL, &i); ok(hr == S_OK, "got (0x%08x)\n", hr); ok(i == 0 || i == -1 /* Win7 */ || broken(i == 0xdeadbeef) /* Vista, 2k8 */, "got %d\n", i); IShellFolderView_Release(folderview); IShellView_Release(view); IShellFolder_Release(desktop); }
static HRESULT create_folder(NewMenuImpl *This, IShellView *view) { IFolderView *folder_view = NULL; IShellFolder *desktop = NULL; IShellFolder *parent = NULL; ISFHelper *helper = NULL; LPITEMIDLIST pidl = NULL; WCHAR nameW[MAX_PATH]; HRESULT hr; if (view) { hr = IShellView_QueryInterface(view, &IID_IFolderView, (void **)&folder_view); if (FAILED(hr)) return hr; hr = IFolderView_GetFolder(folder_view, &IID_IShellFolder, (void **)&parent); if (FAILED(hr)) goto out; } else { hr = SHGetDesktopFolder(&desktop); if (FAILED(hr)) goto out; hr = IShellFolder_BindToObject(desktop, This->pidl, NULL, &IID_IShellFolder, (void **)&parent); if (FAILED(hr)) goto out; } IShellFolder_QueryInterface(parent, &IID_ISFHelper, (void **)&helper); if (FAILED(hr)) goto out; hr = ISFHelper_GetUniqueName(helper, nameW, MAX_PATH); if (FAILED(hr)) goto out; hr = ISFHelper_AddFolder(helper, 0, nameW, &pidl); if (FAILED(hr)) goto out; if (view) { IShellView_SelectItem(view, pidl, SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE | SVSI_FOCUSED | SVSI_SELECT); } out: if (pidl) SHFree(pidl); if (helper) ISFHelper_Release(helper); if (parent) IShellFolder_Release(parent); if (desktop) IShellFolder_Release(desktop); if (folder_view) IFolderView_Release(folder_view); return hr; }
static void test_IOleWindow(void) { IShellFolder *desktop; IShellView *view; IOleWindow *wnd; HRESULT hr; hr = SHGetDesktopFolder(&desktop); ok(hr == S_OK, "got (0x%08x)\n", hr); hr = IShellFolder_CreateViewObject(desktop, NULL, &IID_IShellView, (void**)&view); ok(hr == S_OK, "got (0x%08x)\n", hr); hr = IShellView_QueryInterface(view, &IID_IOleWindow, (void**)&wnd); ok(hr == E_NOINTERFACE, "got (0x%08x)\n", hr); /* IShellView::ContextSensitiveHelp */ hr = IShellView_ContextSensitiveHelp(view, TRUE); ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr); hr = IShellView_ContextSensitiveHelp(view, FALSE); ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr); IShellView_Release(view); IShellFolder_Release(desktop); }
static IShellFolder* get_starting_shell_folder(parameters_struct* params) { IShellFolder* desktop,*folder; LPITEMIDLIST root_pidl; HRESULT hres; SHGetDesktopFolder(&desktop); if (!params->root[0]) { return desktop; } hres = IShellFolder_ParseDisplayName(desktop,NULL,NULL, params->root,NULL, &root_pidl,NULL); if(FAILED(hres)) { return desktop; } hres = IShellFolder_BindToObject(desktop,root_pidl,NULL, &IID_IShellFolder, (void**)&folder); if(FAILED(hres)) { return desktop; } IShellFolder_Release(desktop); return folder; }
static HRESULT ShellItem_get_parent_shellfolder(ShellItem *This, IShellFolder **ppsf) { LPITEMIDLIST parent_pidl; IShellFolder *desktop; HRESULT ret; ret = ShellItem_get_parent_pidl(This, &parent_pidl); if (SUCCEEDED(ret)) { ret = SHGetDesktopFolder(&desktop); if (SUCCEEDED(ret)) { if (_ILIsDesktop(parent_pidl)) { *ppsf = desktop; } else { ret = IShellFolder_BindToObject(desktop, parent_pidl, NULL, &IID_IShellFolder, (void**)ppsf); IShellFolder_Release(desktop); } } ILFree(parent_pidl); } return ret; }
/* Tests for Control Panel */ static void test_parse_for_control_panel(void) { /* path of My Computer\Control Panel */ static WCHAR control_panel_path[] = { ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-','A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}','\\', ':',':','{','2','1','E','C','2','0','2','0','-','3','A','E','A','-','1','0','6','9','-','A','2','D','D','-','0','8','0','0','2','B','3','0','3','0','9','D','}', 0 }; IShellFolder *psfDesktop; HRESULT hr; DWORD eaten = 0xdeadbeef; LPITEMIDLIST pidl; DWORD attr = ~0; hr = SHGetDesktopFolder(&psfDesktop); ok(hr == S_OK, "SHGetDesktopFolder failed with error 0x%x\n", hr); hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, control_panel_path, &eaten, &pidl, &attr); ok(hr == S_OK, "IShellFolder_ParseDisplayName failed with error 0x%x\n", hr); todo_wine ok(eaten == 0xdeadbeef, "eaten should not have been set to %u\n", eaten); todo_wine ok((attr == (SFGAO_CANLINK | SFGAO_FOLDER)) || /* Win9x, NT4 */ (attr == (SFGAO_CANLINK | SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_STREAM)) || /* W2K */ (attr == (SFGAO_CANLINK | SFGAO_FOLDER | SFGAO_HASSUBFOLDER)) || /* W2K, XP, W2K3 */ (attr == (SFGAO_CANLINK | SFGAO_NONENUMERATED)) || /* Vista */ (attr == SFGAO_CANLINK), /* Vista, W2K8 */ "Unexpected attributes : %08x\n", attr); ILFree(pidl); IShellFolder_Release(psfDesktop); }
static HRESULT WINAPI ShellItem_GetAttributes(IShellItem2 *iface, SFGAOF sfgaoMask, SFGAOF *psfgaoAttribs) { ShellItem *This = impl_from_IShellItem2(iface); IShellFolder *parent_folder; LPITEMIDLIST child_pidl; HRESULT ret; TRACE("(%p,%x,%p)\n", iface, sfgaoMask, psfgaoAttribs); if (_ILIsDesktop(This->pidl)) ret = SHGetDesktopFolder(&parent_folder); else ret = ShellItem_get_parent_shellfolder(This, &parent_folder); if (SUCCEEDED(ret)) { child_pidl = ILFindLastID(This->pidl); *psfgaoAttribs = sfgaoMask; ret = IShellFolder_GetAttributesOf(parent_folder, 1, (LPCITEMIDLIST*)&child_pidl, psfgaoAttribs); *psfgaoAttribs &= sfgaoMask; IShellFolder_Release(parent_folder); if (SUCCEEDED(ret)) { if(sfgaoMask == *psfgaoAttribs) return S_OK; else return S_FALSE; } } return ret; }
int WINAPI wWinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPWSTR cmdline, int cmdshow) { parameters_struct parameters; HRESULT hres; MSG msg; IShellFolder *folder; memset(¶meters,0,sizeof(parameters)); explorer_hInstance = hinstance; parse_command_line(cmdline,¶meters); hres = OleInitialize(NULL); if(!SUCCEEDED(hres)) { WINE_ERR("Could not initialize COM\n"); ExitProcess(EXIT_FAILURE); } register_explorer_window_class(); folder = get_starting_shell_folder(¶meters); make_explorer_window(folder); IShellFolder_Release(folder); while(GetMessageW( &msg, NULL, 0, 0 ) != 0) { TranslateMessage(&msg); DispatchMessageW(&msg); } return 0; }
static LRESULT BrsFolder_Treeview_Expand( browse_info *info, NMTREEVIEWW *pnmtv ) { IShellFolder *lpsf2 = NULL; LPTV_ITEMDATA lptvid = (LPTV_ITEMDATA) pnmtv->itemNew.lParam; HRESULT r; TRACE("TVN_ITEMEXPANDINGA/W\n"); if ((pnmtv->itemNew.state & TVIS_EXPANDEDONCE)) return 0; if (!_ILIsEmpty(lptvid->lpi)) { r = IShellFolder_BindToObject( lptvid->lpsfParent, lptvid->lpi, 0, &IID_IShellFolder, (void**)&lpsf2 ); } else { lpsf2 = lptvid->lpsfParent; IShellFolder_AddRef(lpsf2); r = S_OK; } if (SUCCEEDED(r)) { FillTreeView( info, lpsf2, lptvid->lpifq, pnmtv->itemNew.hItem, lptvid->pEnumIL); IShellFolder_Release( lpsf2 ); } /* My Computer is already sorted and trying to do a simple text * sort will only mess things up */ if (!_ILIsMyComputer(lptvid->lpi)) SendMessageW( info->hwndTreeView, TVM_SORTCHILDREN, FALSE, (LPARAM)pnmtv->itemNew.hItem ); return 0; }
static HRESULT pidl_to_shellfolder(LPITEMIDLIST pidl, LPWSTR *displayname, IShellFolder **out_folder) { IShellFolder* parent_folder=NULL; LPCITEMIDLIST relative_pidl=NULL; STRRET strret; HRESULT hr; hr = SHBindToParent(pidl, &IID_IShellFolder, (void**)&parent_folder, &relative_pidl); if (displayname) { if (SUCCEEDED(hr)) hr = IShellFolder_GetDisplayNameOf(parent_folder, relative_pidl, SHGDN_INFOLDER, &strret); if (SUCCEEDED(hr)) hr = StrRetToStrW(&strret, NULL, displayname); } if (SUCCEEDED(hr)) hr = IShellFolder_BindToObject(parent_folder, relative_pidl, NULL, &IID_IShellFolder, (void**)out_folder); if (parent_folder) IShellFolder_Release(parent_folder); return hr; }
static void update_shell_folder_listview(HWND dialog) { int i; LVITEMW item; LONG lSelected = SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_GETNEXTITEM, -1, MAKELPARAM(LVNI_SELECTED,0)); SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_DELETEALLITEMS, 0, 0); for (i=0; i<NUM_ELEMS(asfiInfo); i++) { WCHAR buffer[MAX_PATH]; HRESULT hr; LPITEMIDLIST pidlCurrent; /* Some acrobatic to get the localized name of the shell folder */ hr = SHGetFolderLocation(dialog, asfiInfo[i].nFolder, NULL, 0, &pidlCurrent); if (SUCCEEDED(hr)) { LPSHELLFOLDER psfParent; LPCITEMIDLIST pidlLast; hr = SHBindToParent(pidlCurrent, &IID_IShellFolder, (LPVOID*)&psfParent, &pidlLast); if (SUCCEEDED(hr)) { STRRET strRet; hr = IShellFolder_GetDisplayNameOf(psfParent, pidlLast, SHGDN_FORADDRESSBAR, &strRet); if (SUCCEEDED(hr)) { hr = StrRetToBufW(&strRet, pidlLast, buffer, MAX_PATH); } IShellFolder_Release(psfParent); } ILFree(pidlCurrent); } /* If there's a dangling symlink for the current shell folder, SHGetFolderLocation * will fail above. We fall back to the (non-verified) path of the shell folder. */ if (FAILED(hr)) { hr = SHGetFolderPathW(dialog, asfiInfo[i].nFolder|CSIDL_FLAG_DONT_VERIFY, NULL, SHGFP_TYPE_CURRENT, buffer); } item.mask = LVIF_TEXT | LVIF_PARAM; item.iItem = i; item.iSubItem = 0; item.pszText = buffer; item.lParam = (LPARAM)&asfiInfo[i]; SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_INSERTITEMW, 0, (LPARAM)&item); item.mask = LVIF_TEXT; item.iItem = i; item.iSubItem = 1; item.pszText = strdupU2W(asfiInfo[i].szLinkTarget); SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_SETITEMW, 0, (LPARAM)&item); HeapFree(GetProcessHeap(), 0, item.pszText); } /* Ensure that the previously selected item is selected again. */ if (lSelected >= 0) { item.mask = LVIF_STATE; item.state = LVIS_SELECTED; item.stateMask = LVIS_SELECTED; SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_SETITEMSTATE, lSelected, (LPARAM)&item); } }
/************************************************************************** * ISvItemCm_fnRelease */ static ULONG WINAPI ISvItemCm_fnRelease(IContextMenu *iface) { ICOM_THIS(ItemCmImpl, iface); TRACE("(%p)->()\n",This); shell32_ObjCount--; if (!--(This->ref)) { TRACE(" destroying IContextMenu(%p)\n",This); if(This->pSFParent) IShellFolder_Release(This->pSFParent); if(This->pidl) SHFree(This->pidl); /*make sure the pidl is freed*/ _ILFreeaPidl(This->apidl, This->cidl); HeapFree(GetProcessHeap(),0,This); return 0; } return This->ref; }
HRESULT SHELL32_ParseNextElement (IShellFolder2 * psf, HWND hwndOwner, LPBC pbc, LPITEMIDLIST * pidlInOut, LPOLESTR szNext, DWORD * pEaten, DWORD * pdwAttributes) { LPITEMIDLIST pidlOut = NULL, pidlTemp = NULL; IShellFolder *psfChild; HRESULT hr; TRACE ("(%p, %p, %p, %s)\n", psf, pbc, pidlInOut ? *pidlInOut : NULL, debugstr_w (szNext)); /* get the shellfolder for the child pidl and let it analyse further */ hr = IShellFolder2_BindToObject (psf, *pidlInOut, pbc, &IID_IShellFolder, (LPVOID *) & psfChild); if (SUCCEEDED(hr)) { hr = IShellFolder_ParseDisplayName (psfChild, hwndOwner, pbc, szNext, pEaten, &pidlOut, pdwAttributes); IShellFolder_Release (psfChild); if (SUCCEEDED(hr)) { pidlTemp = ILCombine (*pidlInOut, pidlOut); if (!pidlTemp) hr = E_OUTOFMEMORY; } if (pidlOut) ILFree (pidlOut); } ILFree (*pidlInOut); *pidlInOut = pidlTemp; TRACE ("-- pidl=%p ret=0x%08x\n", pidlInOut ? *pidlInOut : NULL, hr); return hr; }
/* Tests for My Network Places */ static void test_parse_for_entire_network(void) { static WCHAR my_network_places_path[] = { ':',':','{','2','0','8','D','2','C','6','0','-','3','A','E','A','-', '1','0','6','9','-','A','2','D','7','-','0','8','0','0','2','B','3','0','3','0','9','D','}', 0 }; static WCHAR entire_network_path[] = { ':',':','{','2','0','8','D','2','C','6','0','-','3','A','E','A','-', '1','0','6','9','-','A','2','D','7','-','0','8','0','0','2','B','3','0','3','0','9','D', '}','\\','E','n','t','i','r','e','N','e','t','w','o','r','k',0 }; IShellFolder *psfDesktop; HRESULT hr; DWORD eaten = 0xdeadbeef; LPITEMIDLIST pidl; DWORD attr = ~0; DWORD expected_attr; hr = SHGetDesktopFolder(&psfDesktop); ok(hr == S_OK, "SHGetDesktopFolder failed with error 0x%x\n", hr); hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, my_network_places_path, &eaten, &pidl, &attr); ok(hr == S_OK, "IShellFolder_ParseDisplayName failed with error 0x%x\n", hr); todo_wine ok(eaten == 0xdeadbeef, "eaten should not have been set to %u\n", eaten); expected_attr = SFGAO_HASSUBFOLDER|SFGAO_FOLDER|SFGAO_FILESYSANCESTOR|SFGAO_DROPTARGET|SFGAO_HASPROPSHEET|SFGAO_CANRENAME|SFGAO_CANLINK; todo_wine ok((attr == expected_attr) || /* Win9x, NT4 */ (attr == (expected_attr | SFGAO_STREAM)) || /* W2K */ (attr == (expected_attr | SFGAO_CANDELETE)) || /* XP, W2K3 */ (attr == (expected_attr | SFGAO_CANDELETE | SFGAO_NONENUMERATED)), /* Vista */ "Unexpected attributes : %08x\n", attr); ILFree(pidl); /* Start clean again */ eaten = 0xdeadbeef; attr = ~0; hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, entire_network_path, &eaten, &pidl, &attr); IShellFolder_Release(psfDesktop); if (hr == HRESULT_FROM_WIN32(ERROR_BAD_NET_NAME) || hr == HRESULT_FROM_WIN32(ERROR_NO_NET_OR_BAD_PATH) || hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER)) { win_skip("'EntireNetwork' is not available on Win9x, NT4 and Vista\n"); return; } ok(hr == S_OK, "IShellFolder_ParseDisplayName failed with error 0x%x\n", hr); todo_wine ok(eaten == 0xdeadbeef, "eaten should not have been set to %u\n", eaten); expected_attr = SFGAO_HASSUBFOLDER|SFGAO_FOLDER|SFGAO_FILESYSANCESTOR|SFGAO_HASPROPSHEET|SFGAO_CANLINK; todo_wine ok(attr == expected_attr || /* winme, nt4 */ attr == (expected_attr | SFGAO_STREAM) || /* win2k */ attr == (expected_attr | SFGAO_STORAGEANCESTOR), /* others */ "attr should be 0x%x, not 0x%x\n", expected_attr, attr); ILFree(pidl); }
static HRESULT WINAPI ShellItem_BindToHandler(IShellItem2 *iface, IBindCtx *pbc, REFGUID rbhid, REFIID riid, void **ppvOut) { ShellItem *This = impl_from_IShellItem2(iface); HRESULT ret; TRACE("(%p,%p,%s,%p,%p)\n", iface, pbc, shdebugstr_guid(rbhid), riid, ppvOut); *ppvOut = NULL; if (IsEqualGUID(rbhid, &BHID_SFObject)) { IShellFolder *psf; ret = ShellItem_get_shellfolder(This, pbc, &psf); if (SUCCEEDED(ret)) { ret = IShellFolder_QueryInterface(psf, riid, ppvOut); IShellFolder_Release(psf); } return ret; } else if (IsEqualGUID(rbhid, &BHID_SFUIObject)) { IShellFolder *psf_parent; if (_ILIsDesktop(This->pidl)) ret = SHGetDesktopFolder(&psf_parent); else ret = ShellItem_get_parent_shellfolder(This, &psf_parent); if (SUCCEEDED(ret)) { LPCITEMIDLIST pidl = ILFindLastID(This->pidl); ret = IShellFolder_GetUIObjectOf(psf_parent, NULL, 1, &pidl, riid, NULL, ppvOut); IShellFolder_Release(psf_parent); } return ret; } else if (IsEqualGUID(rbhid, &BHID_DataObject)) { return ShellItem_BindToHandler(&This->IShellItem2_iface, pbc, &BHID_SFUIObject, &IID_IDataObject, ppvOut); } FIXME("Unsupported BHID %s.\n", debugstr_guid(rbhid)); return MK_E_NOOBJECT; }
static void test_selection(void) { HRESULT resCoInit, hr; BROWSEINFOA bi; LPITEMIDLIST pidl = NULL; IShellFolder *desktop_object; WCHAR selected_folderW[MAX_PATH]; const CHAR title[] = "test_selection"; resCoInit = CoInitialize(NULL); if(!(resCoInit == S_OK || resCoInit == S_FALSE)) { skip("COM could not be initialized %u\n", GetLastError()); return; } if (!GetCurrentDirectoryW(MAX_PATH, selected_folderW)) { skip("GetCurrentDirectoryW failed %u\n", GetLastError()); } /* Initialize browse info struct for SHBrowseForFolder */ bi.hwndOwner = NULL; bi.pszDisplayName = NULL; bi.lpszTitle = title; bi.lpfn = selection_callback; hr = SHGetDesktopFolder(&desktop_object); ok (SUCCEEDED(hr), "SHGetDesktopFolder failed with hr 0x%08x\n", hr); if (FAILED(hr)) { skip("SHGetDesktopFolder failed - skipping\n"); return; } desktop_object->lpVtbl->ParseDisplayName(desktop_object, NULL, NULL, selected_folderW, 0UL, &selected_folder_pidl, 0UL); bi.pidlRoot = selected_folder_pidl; /* test without flags */ bi.ulFlags = 0; pidl = SHBrowseForFolderA(&bi); if (pidl) CoTaskMemFree(pidl); /* test with flag */ bi.ulFlags = BIF_NEWDIALOGSTYLE; pidl = SHBrowseForFolderA(&bi); if (pidl) CoTaskMemFree(pidl); IShellFolder_Release(desktop_object); CoUninitialize(); }
/****************************************************************************** * FillTreeView [Internal] * * For each child (given by lpe) of the parent shell folder, which is given by * lpsf and whose PIDL is pidl, insert a treeview-item right under hParent * * PARAMS * info [I] data for the dialog * lpsf [I] IShellFolder interface of the parent shell folder * pidl [I] ITEMIDLIST of the parent shell folder * hParent [I] The treeview item that represents the parent shell folder * lpe [I] An iterator for the children of the parent shell folder */ static void FillTreeView( browse_info *info, IShellFolder * lpsf, LPITEMIDLIST pidl, HTREEITEM hParent, IEnumIDList* lpe) { HTREEITEM hPrev = 0; LPITEMIDLIST pidlTemp = 0; ULONG ulFetched; HRESULT hr; HWND hwnd = GetParent( info->hwndTreeView ); TRACE("%p %p %p %p\n",lpsf, pidl, hParent, lpe); /* No IEnumIDList -> No children */ if (!lpe) return; SetCapture( hwnd ); SetCursor( LoadCursorA( 0, (LPSTR)IDC_WAIT ) ); while (NOERROR == IEnumIDList_Next(lpe,1,&pidlTemp,&ulFetched)) { ULONG ulAttrs = SFGAO_HASSUBFOLDER | SFGAO_FOLDER; IEnumIDList* pEnumIL = NULL; IShellFolder* pSFChild = NULL; IShellFolder_GetAttributesOf(lpsf, 1, (LPCITEMIDLIST*)&pidlTemp, &ulAttrs); if (ulAttrs & SFGAO_FOLDER) { hr = IShellFolder_BindToObject(lpsf,pidlTemp,NULL,&IID_IShellFolder,(LPVOID*)&pSFChild); if (SUCCEEDED(hr)) { DWORD flags = BrowseFlagsToSHCONTF(info->lpBrowseInfo->ulFlags); hr = IShellFolder_EnumObjects(pSFChild, hwnd, flags, &pEnumIL); if (hr == S_OK) { if ((IEnumIDList_Skip(pEnumIL, 1) != S_OK) || FAILED(IEnumIDList_Reset(pEnumIL))) { IEnumIDList_Release(pEnumIL); pEnumIL = NULL; } } IShellFolder_Release(pSFChild); } } if (!(hPrev = InsertTreeViewItem(info, lpsf, pidlTemp, pidl, pEnumIL, hParent))) goto done; SHFree(pidlTemp); /* Finally, free the pidl that the shell gave us... */ pidlTemp=NULL; } done: ReleaseCapture(); SetCursor(LoadCursorW(0, (LPWSTR)IDC_ARROW)); SHFree(pidlTemp); }
static void test_CreateViewWindow(void) { IShellFolder *desktop; HWND hwnd_view, hwnd2; FOLDERSETTINGS settings; IShellView *view; IDropTarget *dt; HRESULT hr; RECT r = {0}; hr = SHGetDesktopFolder(&desktop); ok(hr == S_OK, "got (0x%08x)\n", hr); hr = IShellFolder_CreateViewObject(desktop, NULL, &IID_IShellView, (void**)&view); ok(hr == S_OK, "got (0x%08x)\n", hr); if (0) { /* crashes on native */ IShellView_CreateViewWindow(view, NULL, &settings, NULL, NULL, NULL); } settings.ViewMode = FVM_ICON; settings.fFlags = 0; hwnd_view = (HWND)0xdeadbeef; hr = IShellView_CreateViewWindow(view, NULL, &settings, NULL, NULL, &hwnd_view); ok(hr == E_UNEXPECTED, "got (0x%08x)\n", hr); ok(hwnd_view == 0, "got %p\n", hwnd_view); hwnd_view = (HWND)0xdeadbeef; hr = IShellView_CreateViewWindow(view, NULL, &settings, NULL, &r, &hwnd_view); ok(hr == E_UNEXPECTED, "got (0x%08x)\n", hr); ok(hwnd_view == 0, "got %p\n", hwnd_view); hwnd_view = NULL; hr = IShellView_CreateViewWindow(view, NULL, &settings, &test_shellbrowser, &r, &hwnd_view); ok(hr == S_OK, "got (0x%08x)\n", hr); ok(hwnd_view != 0, "got %p\n", hwnd_view); hwnd2 = (HWND)0xdeadbeef; hr = IShellView_CreateViewWindow(view, NULL, &settings, &test_shellbrowser, &r, &hwnd2); ok(hr == E_UNEXPECTED, "got (0x%08x)\n", hr); ok(hwnd2 == NULL, "got %p\n", hwnd_view); /* ::DragLeave without drag operation */ hr = IShellView_QueryInterface(view, &IID_IDropTarget, (void**)&dt); ok(hr == S_OK, "got (0x%08x)\n", hr); hr = IDropTarget_DragLeave(dt); ok(hr == S_OK, "got (0x%08x)\n", hr); IDropTarget_Release(dt); IShellView_Release(view); IShellFolder_Release(desktop); }
static void test_desktop_folder(void) { IShellFolder *psf; HRESULT hr; hr = SHGetDesktopFolder(&psf); ok(hr == S_OK, "Got %x\n", hr); hr = IShellFolder_QueryInterface(psf, &IID_IShellFolder, NULL); ok(hr == E_POINTER, "Got %x\n", hr); IShellFolder_Release(psf); }
static LRESULT BrsFolder_Treeview_Delete( browse_info *info, NMTREEVIEWW *pnmtv ) { LPTV_ITEMDATA lptvid = (LPTV_ITEMDATA)pnmtv->itemOld.lParam; TRACE("TVN_DELETEITEMA/W %p\n", lptvid); IShellFolder_Release(lptvid->lpsfParent); if (lptvid->pEnumIL) IEnumIDList_Release(lptvid->pEnumIL); SHFree(lptvid->lpi); SHFree(lptvid->lpifq); SHFree(lptvid); return 0; }
static ULONG WINAPI RecycleBinMenu_Release(IContextMenu2 *iface) { RecycleBinMenu *This = impl_from_IContextMenu2(iface); UINT result; TRACE("(%p)\n", This); result = InterlockedDecrement(&This->refCount); if (result == 0) { TRACE("Destroying object\n"); _ILFreeaPidl(This->apidl,This->cidl); IShellFolder_Release(This->folder); SHFree(This); } return result; }
/************************************************************************** * ISF_NetworkPlaces_fnGetAttributesOf */ static HRESULT WINAPI ISF_NetworkPlaces_fnGetAttributesOf (IShellFolder2 * iface, UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut) { IGenericSFImpl *This = impl_from_IShellFolder2(iface); HRESULT hr = S_OK; TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n", This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0); if (!rgfInOut) return E_INVALIDARG; if (cidl && !apidl) return E_INVALIDARG; if (*rgfInOut == 0) *rgfInOut = ~0; if (cidl == 0) { IShellFolder *psfParent = NULL; LPCITEMIDLIST rpidl = NULL; hr = SHBindToParent(This->pidlRoot, &IID_IShellFolder, (void**)&psfParent, &rpidl); if(SUCCEEDED(hr)) { SHELL32_GetItemAttributes (psfParent, rpidl, rgfInOut); IShellFolder_Release(psfParent); } } else { while (cidl > 0 && *apidl) { pdump (*apidl); SHELL32_GetItemAttributes ((IShellFolder *)&This->IShellFolder2_iface, *apidl, rgfInOut); apidl++; cidl--; } } /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */ *rgfInOut &= ~SFGAO_VALIDATE; TRACE ("-- result=0x%08x\n", *rgfInOut); return hr; }
int WINAPI wWinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPWSTR cmdline, int cmdshow) { parameters_struct parameters; HRESULT hres; MSG msg; IShellFolder *folder; INITCOMMONCONTROLSEX init_info; memset(¶meters,0,sizeof(parameters)); explorer_hInstance = hinstance; parse_command_line(cmdline,¶meters); hres = OleInitialize(NULL); if(FAILED(hres)) { WINE_ERR("Could not initialize COM\n"); ExitProcess(EXIT_FAILURE); } if(parameters.root[0] && !PathIsDirectoryW(parameters.root)) if(ShellExecuteW(NULL,NULL,parameters.root,NULL,NULL,SW_SHOWDEFAULT) > (HINSTANCE)32) ExitProcess(EXIT_SUCCESS); init_info.dwSize = sizeof(INITCOMMONCONTROLSEX); init_info.dwICC = ICC_USEREX_CLASSES | ICC_BAR_CLASSES | ICC_COOL_CLASSES; if(!InitCommonControlsEx(&init_info)) { WINE_ERR("Could not initialize Comctl\n"); ExitProcess(EXIT_FAILURE); } register_explorer_window_class(); folder = get_starting_shell_folder(¶meters); make_explorer_window(folder); IShellFolder_Release(folder); while(GetMessageW( &msg, NULL, 0, 0 ) != 0) { TranslateMessage(&msg); DispatchMessageW(&msg); } return 0; }
static ULONG WINAPI ContextMenu_Release(IContextMenu3 *iface) { ContextMenu *This = impl_from_IContextMenu3(iface); ULONG ref = InterlockedDecrement(&This->ref); TRACE("(%p)->(%u)\n", This, ref); if (!ref) { if(This->parent) IShellFolder_Release(This->parent); SHFree(This->pidl); _ILFreeaPidl(This->apidl, This->cidl); HeapFree(GetProcessHeap(), 0, This); } return ref; }
static void COMDLG32_UpdateCurrentDir(const FileOpenDlgInfos *fodInfos) { LPSHELLFOLDER psfDesktop; STRRET strret; HRESULT res; res = SHGetDesktopFolder(&psfDesktop); if (FAILED(res)) return; res = IShellFolder_GetDisplayNameOf(psfDesktop, fodInfos->ShellInfos.pidlAbsCurrent, SHGDN_FORPARSING, &strret); if (SUCCEEDED(res)) { WCHAR wszCurrentDir[MAX_PATH]; res = StrRetToBufW(&strret, fodInfos->ShellInfos.pidlAbsCurrent, wszCurrentDir, MAX_PATH); if (SUCCEEDED(res)) SetCurrentDirectoryW(wszCurrentDir); } IShellFolder_Release(psfDesktop); }
/************************************************************************** * ISvItemCm_fnRelease */ static ULONG WINAPI ISvItemCm_fnRelease(IContextMenu2 *iface) { ItemCmImpl *This = impl_from_IContextMenu2(iface); ULONG refCount = InterlockedDecrement(&This->ref); TRACE("(%p)->(count=%i)\n", This, refCount + 1); if (!refCount) { TRACE(" destroying IContextMenu(%p)\n",This); if(This->pSFParent) IShellFolder_Release(This->pSFParent); SHFree(This->pidl); /*make sure the pidl is freed*/ _ILFreeaPidl(This->apidl, This->cidl); HeapFree(GetProcessHeap(),0,This); } return refCount; }
static HRESULT ShellItem_get_shellfolder(ShellItem *This, IBindCtx *pbc, IShellFolder **ppsf) { IShellFolder *desktop; HRESULT ret; ret = SHGetDesktopFolder(&desktop); if (SUCCEEDED(ret)) { if (_ILIsDesktop(This->pidl)) { *ppsf = desktop; IShellFolder_AddRef(*ppsf); } else { ret = IShellFolder_BindToObject(desktop, This->pidl, pbc, &IID_IShellFolder, (void**)ppsf); } IShellFolder_Release(desktop); } return ret; }
static void destroy_menus(void) { if (!root_menu.menuhandle) return; DestroyMenu(root_menu.menuhandle); root_menu.menuhandle = NULL; while (!list_empty(&items)) { struct menu_item* item; item = LIST_ENTRY(list_head(&items), struct menu_item, entry); if (item->folder) IShellFolder_Release(item->folder); CoTaskMemFree(item->pidl); CoTaskMemFree(item->displayname); list_remove(&item->entry); HeapFree(GetProcessHeap(), 0, item); } }
static void test_GetItemObject(void) { IShellFolder *desktop; IShellView *view; IUnknown *unk; HRESULT hr; hr = SHGetDesktopFolder(&desktop); ok(hr == S_OK, "got (0x%08x)\n", hr); hr = IShellFolder_CreateViewObject(desktop, NULL, &IID_IShellView, (void**)&view); ok(hr == S_OK, "got (0x%08x)\n", hr); /* from documentation three interfaces are supported for SVGIO_BACKGROUND: IContextMenu, IDispatch, IPersistHistory */ hr = IShellView_GetItemObject(view, SVGIO_BACKGROUND, &IID_IContextMenu, (void**)&unk); ok(hr == S_OK, "got (0x%08x)\n", hr); IUnknown_Release(unk); unk = NULL; hr = IShellView_GetItemObject(view, SVGIO_BACKGROUND, &IID_IDispatch, (void**)&unk); todo_wine ok(hr == S_OK || broken(hr == E_NOTIMPL) /* NT4 */, "got (0x%08x)\n", hr); if (unk) IUnknown_Release(unk); unk = NULL; hr = IShellView_GetItemObject(view, SVGIO_BACKGROUND, &IID_IPersistHistory, (void**)&unk); todo_wine ok(hr == S_OK || broken(hr == E_NOTIMPL) /* W9x, NT4 */, "got (0x%08x)\n", hr); if (unk) IUnknown_Release(unk); /* example of unsupported interface, base for IPersistHistory */ hr = IShellView_GetItemObject(view, SVGIO_BACKGROUND, &IID_IPersist, (void**)&unk); ok(hr == E_NOINTERFACE || broken(hr == E_NOTIMPL) /* W2K */, "got (0x%08x)\n", hr); IShellView_Release(view); IShellFolder_Release(desktop); }
/************************************************************************** * IShellBrowserImpl_BrowseObject * * See Windows documentation on IShellBrowser::BrowseObject for more details * * This function will override user specified flags and will always * use SBSP_DEFBROWSER and SBSP_DEFMODE. */ static HRESULT WINAPI IShellBrowserImpl_BrowseObject(IShellBrowser *iface, LPCITEMIDLIST pidl, UINT wFlags) { HRESULT hRes; IShellFolder *psfTmp; IShellView *psvTmp; FileOpenDlgInfos *fodInfos; LPITEMIDLIST pidlTmp; HWND hwndView; HWND hDlgWnd; BOOL bViewHasFocus; RECT rectView; IShellBrowserImpl *This = impl_from_IShellBrowser(iface); TRACE("(%p)(pidl=%p,flags=0x%08x)\n", This, pidl, wFlags); COMDLG32_DumpSBSPFlags(wFlags); fodInfos = get_filedlg_infoptr(This->hwndOwner); /* Format the pidl according to its parameter's category */ if(wFlags & SBSP_RELATIVE) { /* SBSP_RELATIVE A relative pidl (relative from the current folder) */ if(FAILED(hRes = IShellFolder_BindToObject(fodInfos->Shell.FOIShellFolder, pidl, NULL, &IID_IShellFolder, (LPVOID *)&psfTmp))) { ERR("bind to object failed\n"); return hRes; } /* create an absolute pidl */ pidlTmp = COMDLG32_PIDL_ILCombine(fodInfos->ShellInfos.pidlAbsCurrent, pidl); } else if(wFlags & SBSP_PARENT) { /* Browse the parent folder (ignores the pidl) */ pidlTmp = GetParentPidl(fodInfos->ShellInfos.pidlAbsCurrent); psfTmp = GetShellFolderFromPidl(pidlTmp); } else /* SBSP_ABSOLUTE is 0x0000 */ { /* An absolute pidl (relative from the desktop) */ pidlTmp = COMDLG32_PIDL_ILClone(pidl); psfTmp = GetShellFolderFromPidl(pidlTmp); } if(!psfTmp) { ERR("could not browse to folder\n"); return E_FAIL; } /* If the pidl to browse to is equal to the actual pidl ... do nothing and pretend you did it*/ if(COMDLG32_PIDL_ILIsEqual(pidlTmp,fodInfos->ShellInfos.pidlAbsCurrent)) { IShellFolder_Release(psfTmp); COMDLG32_SHFree(pidlTmp); TRACE("keep current folder\n"); return NOERROR; } /* Release the current DataObject */ if (fodInfos->Shell.FOIDataObject) { IDataObject_Release(fodInfos->Shell.FOIDataObject); fodInfos->Shell.FOIDataObject = NULL; } /* Create the associated view */ TRACE("create view object\n"); if(FAILED(hRes = IShellFolder_CreateViewObject(psfTmp, fodInfos->ShellInfos.hwndOwner, &IID_IShellView, (LPVOID *)&psvTmp))) goto error; /* Check if listview has focus */ bViewHasFocus = IsChild(fodInfos->ShellInfos.hwndView,GetFocus()); /* Get the foldersettings from the old view */ if(fodInfos->Shell.FOIShellView) IShellView_GetCurrentInfo(fodInfos->Shell.FOIShellView, &fodInfos->ShellInfos.folderSettings); /* Release the old fodInfos->Shell.FOIShellView and update its value. We have to update this early since ShellView_CreateViewWindow of native shell32 calls OnStateChange and needs the correct view here.*/ if(fodInfos->Shell.FOIShellView) { IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView); IShellView_Release(fodInfos->Shell.FOIShellView); } fodInfos->Shell.FOIShellView = psvTmp; /* Release old FOIShellFolder and update its value */ if (fodInfos->Shell.FOIShellFolder) IShellFolder_Release(fodInfos->Shell.FOIShellFolder); fodInfos->Shell.FOIShellFolder = psfTmp; /* Release old pidlAbsCurrent and update its value */ COMDLG32_SHFree(fodInfos->ShellInfos.pidlAbsCurrent); fodInfos->ShellInfos.pidlAbsCurrent = pidlTmp; COMDLG32_UpdateCurrentDir(fodInfos); GetWindowRect(GetDlgItem(This->hwndOwner, IDC_SHELLSTATIC), &rectView); MapWindowPoints(0, This->hwndOwner, (LPPOINT)&rectView, 2); /* Create the window */ TRACE("create view window\n"); if(FAILED(hRes = IShellView_CreateViewWindow(psvTmp, NULL, &fodInfos->ShellInfos.folderSettings, fodInfos->Shell.FOIShellBrowser, &rectView, &hwndView))) goto error; fodInfos->ShellInfos.hwndView = hwndView; /* Set view window control id to 5002 */ SetWindowLongPtrW(hwndView, GWLP_ID, lst2); SendMessageW( hwndView, WM_SETFONT, SendMessageW( GetParent(hwndView), WM_GETFONT, 0, 0 ), FALSE ); /* Select the new folder in the Look In combo box of the Open file dialog */ FILEDLG95_LOOKIN_SelectItem(fodInfos->DlgInfos.hwndLookInCB,fodInfos->ShellInfos.pidlAbsCurrent); /* changes the tab order of the ListView to reflect the window's File Dialog */ hDlgWnd = GetDlgItem(GetParent(hwndView), IDC_LOOKIN); SetWindowPos(hwndView, hDlgWnd, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE); /* Since we destroyed the old view if it had focus set focus to the newly created view */ if (bViewHasFocus) SetFocus(fodInfos->ShellInfos.hwndView); return hRes; error: ERR("Failed with error 0x%08x\n", hRes); return hRes; }