/* * Main BrowseInfo callback to set the initial directory and populate the edit control */ INT CALLBACK BrowseInfoCallback(HWND hDlg, UINT message, LPARAM lParam, LPARAM pData) { char dir[MAX_PATH]; wchar_t* wpath; LPITEMIDLIST pidl; switch(message) { case BFFM_INITIALIZED: pOrgBrowseWndproc = (WNDPROC)SetWindowLongPtr(hDlg, GWLP_WNDPROC, (LONG_PTR)BrowseDlgCallback); // Windows hides the full path in the edit box by default, which is bull. // Get a handle to the edit control to fix that hBrowseEdit = FindWindowExA(hDlg, NULL, "Edit", NULL); SetWindowTextU(hBrowseEdit, szFolderPath); SetDialogFocus(hDlg, hBrowseEdit); // On Windows 7, MinGW only properly selects the specified folder when using a pidl wpath = utf8_to_wchar(szFolderPath); pidl = SHSimpleIDListFromPath(wpath); safe_free(wpath); // NB: see http://connect.microsoft.com/VisualStudio/feedback/details/518103/bffm-setselection-does-not-work-with-shbrowseforfolder-on-windows-7 // for details as to why we send BFFM_SETSELECTION twice. SendMessageW(hDlg, BFFM_SETSELECTION, (WPARAM)FALSE, (LPARAM)pidl); Sleep(100); PostMessageW(hDlg, BFFM_SETSELECTION, (WPARAM)FALSE, (LPARAM)pidl); break; case BFFM_SELCHANGED: // Update the status if (SHGetPathFromIDListU((LPITEMIDLIST)lParam, dir)) { SendMessageLU(hDlg, BFFM_SETSTATUSTEXT, 0, dir); SetWindowTextU(hBrowseEdit, dir); } break; } return 0; }
void CRecBinViewer::InstallShellNotify () { SHChangeNotifyEntry stPIDL; LPITEMIDLIST ppidl; int iPos = 0; TCHAR szPath[MAX_PATH]; WIN32_FIND_DATA findData; HANDLE hFindData = INVALID_HANDLE_VALUE; HRESULT hr = S_OK; CDriveArray ar; GetDrives (ar); for (unsigned int i = 0; i < ar.size (); i++) { if (ar[i].m_nType != DRIVE_FIXED) continue; SHQUERYRBINFO qrbi; ZeroMemory (&qrbi, sizeof (qrbi)); qrbi.cbSize = sizeof (qrbi); hr = SHQueryRecycleBin (ar[i].m_Path, &qrbi); if (SUCCEEDED (hr)) { ZeroMemory (&findData, sizeof (findData)); wsprintf (szPath, _T("%sRecycler"), static_cast<LPCWSTR>(ar[i].m_Path)); hFindData = FindFirstFile (szPath, &findData); if (INVALID_HANDLE_VALUE != hFindData) { ppidl = SHSimpleIDListFromPath (szPath); stPIDL.pidl = ppidl; m_pidlDrives[iPos] = ppidl; m_hNotifyDrives[iPos] = SHChangeNotifyRegister (m_hWnd, SHCNF_ACCEPT_INTERRUPTS | SHCNF_ACCEPT_NON_INTERRUPTS, SHCNE_RMDIR | SHCNE_RENAMEFOLDER | SHCNE_DELETE | SHCNE_RENAMEITEM, WM_SHELLNOTIFYRBINDIR, 1, &stPIDL); iPos ++; FindClose (hFindData); } else { ZeroMemory (&findData, sizeof (findData)); wsprintf (szPath, _T("%sRecycled"), static_cast<LPCWSTR>(ar[i].m_Path)); hFindData = FindFirstFile (szPath, &findData); if (INVALID_HANDLE_VALUE != hFindData) { ppidl = SHSimpleIDListFromPath (szPath); stPIDL.pidl = ppidl; m_pidlDrives[iPos] = ppidl; m_hNotifyDrives[iPos] = SHChangeNotifyRegister (m_hWnd, SHCNF_ACCEPT_INTERRUPTS | SHCNF_ACCEPT_NON_INTERRUPTS, SHCNE_RMDIR | SHCNE_RENAMEFOLDER | SHCNE_DELETE | SHCNE_RENAMEITEM, WM_SHELLNOTIFYRBINDIR, 1, &stPIDL); iPos ++; FindClose (hFindData); } } } } }
static VOID TestCommandLine( _In_ INT ExpectedRet, _In_ INT ExpectedCsidl, _In_ DWORD ExpectedFlags, _In_ PCWSTR ExpectedFileName, _In_ PCWSTR PidlPath) { EXPLORER_INFO Info; PVOID Ret; ULONG i; FillMemory(&Info, sizeof(Info), 0x55); Info.dwFlags = 0x00000000; Ret = SHExplorerParseCmdLine(&Info); if (ExpectedRet == -1) ok(Ret == Info.pidl, "Ret = %p, expected %p\n", Ret, Info.pidl); else ok(Ret == (PVOID)ExpectedRet, "Ret = %p, expected %p\n", Ret, (PVOID)ExpectedRet); if (ExpectedFileName == NULL) ok(Info.FileName == InvalidPointer, "FileName = %p\n", Info.FileName); else { ok(Info.FileName != NULL && Info.FileName != InvalidPointer, "FileName = %p\n", Info.FileName); if (Info.FileName != NULL && Info.FileName != InvalidPointer) { ok(!wcscmp(Info.FileName, ExpectedFileName), "FileName = %ls, expected %ls\n", Info.FileName, ExpectedFileName); LocalFree(Info.FileName); } } if (ExpectedCsidl == PIDL_IS_UNTOUCHED) ok(Info.pidl == InvalidPointer, "pidl = %p\n", Info.pidl); else if (ExpectedCsidl == PIDL_IS_NULL) ok(Info.pidl == NULL, "pidl = %p\n", Info.pidl); else { PIDLIST_ABSOLUTE ExpectedPidl; HRESULT hr; ok(Info.pidl != NULL, "pidl = %p\n", Info.pidl); if (Info.pidl != NULL && Info.pidl != InvalidPointer) { if (ExpectedCsidl == PIDL_IS_PATH) { ExpectedPidl = SHSimpleIDListFromPath(PidlPath); hr = ExpectedPidl == NULL ? E_FAIL : S_OK; ok(ExpectedPidl != NULL, "SHSimpleIDListFromPath failed\n"); } else { hr = SHGetFolderLocation(NULL, ExpectedCsidl, NULL, 0, &ExpectedPidl); ok(hr == S_OK, "SHGetFolderLocation returned %08lx\n", hr); } if (SUCCEEDED(hr)) { ok(ILIsEqual(Info.pidl, ExpectedPidl), "Unexpected pidl value\n"); ILFree(ExpectedPidl); } ILFree(Info.pidl); } } ok(Info.dwFlags == ExpectedFlags, "dwFlags = %08lx, expected %08lx\n", Info.dwFlags, ExpectedFlags); for (i = 0; i < sizeof(Info.Unknown) / sizeof(Info.Unknown[0]); i++) ok(Info.Unknown[i] == 0x55555555, "Unknown[%lu] = %08lx\n", i, Info.Unknown[i]); }
static VOID TestCommandLine( _In_ INT ExpectedRet, _In_ INT ExpectedCsidl, _In_ DWORD ExpectedFlags, _In_ PCWSTR ExpectedFileName, _In_ PCWSTR PidlPath, _Out_opt_ PUINT PWriteEnd) { EXPLORER_INFO Info; UINT Ret; ULONG i; PDWORD InfoWords = (PDWORD) &Info; FillMemory(&Info, sizeof(Info), 0x55); Info.dwFlags = 0x00000000; Ret = SHExplorerParseCmdLine(&Info); // Special case for empty cmdline: Ret is the PIDL for the selected folder. if (ExpectedRet == -1) ok((LPITEMIDLIST) Ret == Info.pidl, "Ret = %x, expected %p\n", Ret, Info.pidl); else ok(Ret == ExpectedRet, "Ret = %x, expected %p\n", Ret, (PVOID) ExpectedRet); if (ExpectedFileName == NULL) ok(Info.FileName == InvalidPointer, "FileName = %p\n", Info.FileName); else { ok(Info.FileName != NULL && Info.FileName != InvalidPointer, "FileName = %p\n", Info.FileName); if (Info.FileName != NULL && Info.FileName != InvalidPointer) { ok(!wcscmp(Info.FileName, ExpectedFileName), "FileName = %ls, expected %ls\n", Info.FileName, ExpectedFileName); LocalFree(Info.FileName); } } ok(Info.dwFlags == ExpectedFlags, "dwFlags = %08lx, expected %08lx\n", Info.dwFlags, ExpectedFlags); if (ExpectedCsidl == PIDL_IS_UNTOUCHED) ok(Info.pidl == InvalidPointer, "pidl = %p\n", Info.pidl); else if (ExpectedCsidl == PIDL_IS_NULL) ok(Info.pidl == NULL, "pidl = %p\n", Info.pidl); else { PIDLIST_ABSOLUTE ExpectedPidl; HRESULT hr; ok(Info.pidl != NULL, "pidl = %p\n", Info.pidl); if (Info.pidl != NULL && Info.pidl != InvalidPointer) { WCHAR pidlPathName[MAX_PATH] = L""; if (Info.pidl != NULL && Info.pidl != (LPITEMIDLIST) 0x55555555) { SHGetPathFromIDListW(Info.pidl, pidlPathName); } if (ExpectedCsidl == PIDL_PATH_EQUALS_PATH) { ok(wcsicmp(pidlPathName, PidlPath) == 0, "Path from pidl does not match; pidlPathName=%S\n", pidlPathName); } else if (ExpectedCsidl == PIDL_IS_EMPTY) { ok(wcslen(pidlPathName) == 0, "Unexpected non-empty path from pidl; pidlPathName=%S\n", pidlPathName); } else { if (ExpectedCsidl == PIDL_IS_PATH) { ExpectedPidl = SHSimpleIDListFromPath(PidlPath); hr = ExpectedPidl == NULL ? E_FAIL : S_OK; ok(ExpectedPidl != NULL, "SHSimpleIDListFromPath(%S) failed. pidlPathName=%S\n", PidlPath, pidlPathName); if (SUCCEEDED(hr)) { ok(ILIsEqual(Info.pidl, ExpectedPidl), "Unexpected pidl value %p; pidlPathName=%S PidlPath=%S\n", Info.pidl, pidlPathName, PidlPath); ILFree(ExpectedPidl); } } else { hr = SHGetFolderLocation(NULL, ExpectedCsidl, NULL, 0, &ExpectedPidl); ok(hr == S_OK, "SHGetFolderLocation returned %08lx\n", hr); if (SUCCEEDED(hr)) { BOOL eq = ILIsEqual(Info.pidl, ExpectedPidl); ILFree(ExpectedPidl); ok(eq, "Unexpected pidl value %p; pidlPathName=%S CSIDL=%d\n", Info.pidl, pidlPathName, ExpectedCsidl); } } } if (Info.pidl != NULL && Info.pidl != (LPITEMIDLIST) 0x55555555) ILFree(Info.pidl); } } for (i = 0; i < sizeof(Info) / sizeof(DWORD); i++) { switch (i*4) { case 0x00: // FileName case 0x04: // pidl case 0x08: // dwFlags case 0x20: // pidlRoot case 0x34: // guidInproc (1/4) case 0x38: // guidInproc (2/4) case 0x3C: // guidInproc (3/4) case 0x40: // guidInproc (4/4) break; default: ok(InfoWords[i] == 0x55555555, "Word 0x%02lx has been set to 0x%08lx\n", i * 4, InfoWords[i]); } } if (PWriteEnd) { PBYTE data = (PBYTE)&Info; *PWriteEnd = 0; for (i = sizeof(Info); i > 0; i--) { if (data[i - 1] != 0x55) { *PWriteEnd = i; break; } } } }