// MW-2005-05-15: Updated for new answer command restructuring int MCA_folder(MCExecPoint &ep, const char *p_title, const char *p_prompt, const char *p_initial, unsigned int p_options) { if (MCmajorosversion >= 0x0600 && MCModeMakeLocalWindows()) return MCA_file(ep, p_title, p_prompt, nil, p_initial, p_options | MCA_OPTION_FOLDER_DIALOG); // MW-2005-05-27: We'll use a static (I know bad me) to store the version // of the shell dll. static int s_shell_version = -1; static char *s_last_folder = NULL; char *t_native_filename; unsigned int t_native_filename_length; if (p_initial != NULL) { t_native_filename_length = strlen(p_initial); t_native_filename = (char *)_alloca(t_native_filename_length + 2); strcpy(t_native_filename, p_initial); MCU_path2native(t_native_filename); } else { t_native_filename = s_last_folder; t_native_filename_length = 0; } if (!MCModeMakeLocalWindows()) { MCRemoteFolderDialog(ep, p_title, p_prompt, t_native_filename); if (!ep.isempty()) { if (s_last_folder != NULL) delete s_last_folder; s_last_folder = ep.getsvalue().clone(); MCU_path2native(s_last_folder); } return 0; } if (s_shell_version == -1) s_shell_version = get_dll_version("shell32.dll"); bool sheet = (p_options & MCA_OPTION_SHEET) != 0; char *prompt = (char *)p_prompt; ep . clear(); BROWSEINFOA bi; memset(&bi, 0, sizeof(BROWSEINFO)); Window pw; pw = MCModeGetParentWindow(); if (pw != DNULL) bi.hwndOwner = (HWND)pw->handle.window; bi.pidlRoot = NULL; bi.lpszTitle = prompt; bi.ulFlags = BIF_RETURNONLYFSDIRS; if (s_shell_version >= 500) bi.ulFlags |= BIF_NEWDIALOGSTYLE; if (t_native_filename != NULL) { bi . lpfn = BrowseCallbackProc; bi . lParam = (LPARAM)t_native_filename; } else { bi.lpfn = NULL; bi.lParam = NULL; } LPITEMIDLIST lpiil; LPMALLOC lpm; char *tdir = NULL; SHGetMalloc(&lpm); DWORD t_error; lpiil = SHBrowseForFolderA(&bi); if (lpiil == NULL) { t_error = GetLastError(); } if (lpiil != NULL && SHGetPathFromIDListA(lpiil, ep.getbuffer(PATH_MAX))) { if (s_last_folder != NULL) delete s_last_folder; s_last_folder = strclone(ep . getbuffer(0)); MCU_path2std(ep.getbuffer(0)); ep.setstrlen(); } else { ep.clear(); MCresult->sets(MCcancelstring); } // SMR 1880 clear shift and button state waitonbutton(); lpm->Free(lpiil); lpm->Release(); return 0; }
static void test_get_set(void) { HRESULT r; IShellLinkA *sl; IShellLinkW *slW = NULL; char mypath[MAX_PATH]; char buffer[INFOTIPSIZE]; LPITEMIDLIST pidl, tmp_pidl; const char * str; int i; WORD w; r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLinkA, (LPVOID*)&sl); ok(r == S_OK, "no IID_IShellLinkA (0x%08x)\n", r); if (r != S_OK) return; /* Test Getting / Setting the description */ strcpy(buffer,"garbage"); r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer)); ok(r == S_OK, "GetDescription failed (0x%08x)\n", r); ok(*buffer=='\0', "GetDescription returned '%s'\n", buffer); str="Some description"; r = IShellLinkA_SetDescription(sl, str); ok(r == S_OK, "SetDescription failed (0x%08x)\n", r); strcpy(buffer,"garbage"); r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer)); ok(r == S_OK, "GetDescription failed (0x%08x)\n", r); ok(lstrcmp(buffer,str)==0, "GetDescription returned '%s'\n", buffer); /* Test Getting / Setting the work directory */ strcpy(buffer,"garbage"); r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer)); ok(r == S_OK, "GetWorkingDirectory failed (0x%08x)\n", r); ok(*buffer=='\0', "GetWorkingDirectory returned '%s'\n", buffer); str="c:\\nonexistent\\directory"; r = IShellLinkA_SetWorkingDirectory(sl, str); ok(r == S_OK, "SetWorkingDirectory failed (0x%08x)\n", r); strcpy(buffer,"garbage"); r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer)); ok(r == S_OK, "GetWorkingDirectory failed (0x%08x)\n", r); ok(lstrcmpi(buffer,str)==0, "GetWorkingDirectory returned '%s'\n", buffer); /* Test Getting / Setting the path */ strcpy(buffer,"garbage"); r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH); todo_wine ok(r == S_FALSE || broken(r == S_OK) /* NT4/W2K */, "GetPath failed (0x%08x)\n", r); ok(*buffer=='\0', "GetPath returned '%s'\n", buffer); CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLinkW, (LPVOID*)&slW); if (!slW) skip("SetPath with NULL parameter crashes on Win9x\n"); else { IShellLinkW_Release(slW); r = IShellLinkA_SetPath(sl, NULL); ok(r==E_INVALIDARG || broken(r==S_OK), /* Some Win95 and NT4 */ "SetPath failed (0x%08x)\n", r); } r = IShellLinkA_SetPath(sl, ""); ok(r==S_OK, "SetPath failed (0x%08x)\n", r); strcpy(buffer,"garbage"); r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH); todo_wine ok(r == S_FALSE, "GetPath failed (0x%08x)\n", r); ok(*buffer=='\0', "GetPath returned '%s'\n", buffer); /* Win98 returns S_FALSE, but WinXP returns S_OK */ str="c:\\nonexistent\\file"; r = IShellLinkA_SetPath(sl, str); ok(r==S_FALSE || r==S_OK, "SetPath failed (0x%08x)\n", r); strcpy(buffer,"garbage"); r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH); ok(r == S_OK, "GetPath failed (0x%08x)\n", r); ok(lstrcmpi(buffer,str)==0, "GetPath returned '%s'\n", buffer); /* Get some real path to play with */ GetWindowsDirectoryA( mypath, sizeof(mypath)-12 ); strcat(mypath, "\\regedit.exe"); /* Test the interaction of SetPath and SetIDList */ tmp_pidl=NULL; r = IShellLinkA_GetIDList(sl, &tmp_pidl); todo_wine ok(r == S_OK, "GetIDList failed (0x%08x)\n", r); if (r == S_OK) { BOOL ret; strcpy(buffer,"garbage"); ret = SHGetPathFromIDListA(tmp_pidl, buffer); todo_wine { ok(ret, "SHGetPathFromIDListA failed\n"); } if (ret) ok(lstrcmpi(buffer,str)==0, "GetIDList returned '%s'\n", buffer); pILFree(tmp_pidl); }