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(); }
const string ProjectConfigDialog::browseFolder(const string baseDir) { char buff[MAX_PATH + 1] = {0}; WCHAR curr[MAX_PATH + 1] = {0}; if (baseDir.length() > 0) { MultiByteToWideChar(CP_UTF8, 0, baseDir.c_str(), baseDir.length(), curr, MAX_PATH); } else { GetCurrentDirectory(MAX_PATH + 1, curr); } BROWSEINFOA bi = {0}; bi.hwndOwner = m_hwndDialog; bi.pszDisplayName = buff; bi.lpszTitle = "Select Project Directory"; bi.lParam = reinterpret_cast<LPARAM>(curr); bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NONEWFOLDERBUTTON | BIF_NEWDIALOGSTYLE; bi.lpfn = BrowseFolderCallback; PIDLIST_ABSOLUTE pid = SHBrowseForFolderA(&bi); if (pid) { SHGetPathFromIDListA(pid, buff); return string(buff); } else { return string(""); } }
char *FolderDlgInnerA(HWND hWnd, wchar_t *title, char *default_dir) { BROWSEINFOA info; char display_name[MAX_PATH]; FOLDER_DLG_INNER_DATA data; LPMALLOC pMalloc; char *ret = NULL; char *title_a; if (UniIsEmptyStr(title)) { title = NULL; } if (IsEmptyStr(default_dir)) { default_dir = NULL; } Zero(&data, sizeof(data)); data.default_dir = CopyStrToUni(default_dir); Zero(display_name, sizeof(display_name)); Zero(&info, sizeof(info)); info.hwndOwner = hWnd; info.pidlRoot = NULL; info.pszDisplayName = display_name; title_a = CopyUniToStr(title); info.lpszTitle = title_a; info.ulFlags = BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS | BIF_VALIDATE | BIF_SHAREABLE; info.lpfn = FolderDlgInnerCallbackA; info.lParam = (LPARAM)&data; if (SUCCEEDED(SHGetMalloc(&pMalloc))) { LPITEMIDLIST pidl; pidl = SHBrowseForFolderA(&info); if (pidl) { char tmp[MAX_PATH]; if (SHGetPathFromIDListA(pidl, tmp)) { ret = CopyStr(tmp); } pMalloc->Free(pidl); } pMalloc->Release(); } Free(data.default_dir); Free(title_a); return ret; }
/** * 폴더 가져오기 */ BOOL GetFolder(CString* strSelectedFolder, const char* lpszTitle, const HWND hwndOwner, const char* strRootFolder, const char* strStartFolder) { char pszDisplayName[ MAX_PATH ]; LPITEMIDLIST lpID; BROWSEINFOA bi; bi.hwndOwner = hwndOwner; if (strRootFolder == NULL) { bi.pidlRoot = NULL; } else { LPITEMIDLIST pIdl = NULL; IShellFolder* pDesktopFolder; char szPath[ MAX_PATH ]; OLECHAR olePath[ MAX_PATH ]; ULONG chEaten; ULONG dwAttributes; strcpy(szPath, (LPCTSTR)strRootFolder); if (SUCCEEDED (SHGetDesktopFolder (&pDesktopFolder))) { MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, szPath, -1, olePath, MAX_PATH); pDesktopFolder->ParseDisplayName (NULL, NULL, olePath, &chEaten, &pIdl, &dwAttributes); pDesktopFolder->Release (); } bi.pidlRoot = pIdl; } bi.pszDisplayName = pszDisplayName; bi.lpszTitle = lpszTitle; bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT; bi.lpfn = BrowseCallbackProc; if (strStartFolder == NULL) { bi.lParam = FALSE; } else { strTmpPath.Format ("%s", strStartFolder); bi.lParam = TRUE; } bi.iImage = NULL; lpID = SHBrowseForFolderA(&bi); if (lpID != NULL) { BOOL b = SHGetPathFromIDList (lpID, pszDisplayName); if (b == TRUE) { strSelectedFolder->Format ("%s",pszDisplayName); return TRUE; } } else { strSelectedFolder->Empty (); } return FALSE; }
BBString *bbSystemRequestDir( BBString *text,BBString *dir ){ BBString *str=&bbEmptyString; if( _usew ){ LPMALLOC shm; ITEMIDLIST *idlist; BROWSEINFOW bi={0}; wchar_t buf[MAX_PATH],*p; GetFullPathNameW( bbTmpWString(dir),MAX_PATH,buf,&p ); bi.hwndOwner=GetActiveWindow(); bi.lpszTitle=bbTmpWString( text ); bi.ulFlags=BIF_RETURNONLYFSDIRS|BIF_NEWDIALOGSTYLE; bi.lpfn=BrowseForFolderCallbackW; bi.lParam=(LPARAM)buf; beginPanel(); idlist=SHBrowseForFolderW(&bi); endPanel(); if( idlist ){ SHGetPathFromIDListW( idlist,buf ); str=bbStringFromWString( buf ); //SHFree( idlist ); //?!? } } else { LPMALLOC shm; ITEMIDLIST *idlist; BROWSEINFOA bi={0}; char buf[MAX_PATH],*p; GetFullPathNameA( bbTmpCString(dir),MAX_PATH,buf,&p ); bi.hwndOwner=GetActiveWindow(); bi.lpszTitle=bbTmpCString( text ); bi.ulFlags=BIF_RETURNONLYFSDIRS|BIF_NEWDIALOGSTYLE; bi.lpfn=BrowseForFolderCallbackA; bi.lParam=(LPARAM)buf; beginPanel(); idlist=SHBrowseForFolderA(&bi); endPanel(); if( idlist ){ SHGetPathFromIDListA( idlist,buf ); str=bbStringFromCString( buf ); //SHFree( idlist ); //?!? } } return str; }
void __fastcall TOptionsForm::ToolButton1Click(TObject *Sender) { UnicodeString dir; if (!DirectoryExists(AcfParams.Save_Dir)) dir = ExtractFilePath(Application->ExeName); else dir = AcfParams.Save_Dir; _browseinfoA lpbi; LPMALLOC ppMalloc; char *buffer; PItemIDList ItemIDList; memset(&lpbi, 0 ,sizeof(_browseinfoA)); if ((SHGetMalloc(&ppMalloc) == S_OK) && (ppMalloc != NULL)) { buffer = (char *) ppMalloc->Alloc(1024); try { OleInitialize(NULL); lpbi.hwndOwner = Application->Handle; lpbi.pidlRoot = NULL; lpbi.pszDisplayName = buffer; lpbi.lpszTitle = "Выберите директорию для сохранения данных"; lpbi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI | BIF_EDITBOX; lpbi.lpfn = &BrowseCallbackProc; lpbi.lParam = (long) AcfParams.Save_Dir.t_str(); try { ItemIDList = SHBrowseForFolderA(&lpbi); } catch (...) { } if (ItemIDList != NULL) { SHGetPathFromIDListA(ItemIDList, buffer); ppMalloc->Free(ItemIDList); Label56->Caption = buffer; } } __finally { ppMalloc->Free(buffer); } }
struct _ITEMIDLIST *SHBrowseForFolderUTF8(struct _browseinfoA *bi) { if (bi && (WDL_HasUTF8(bi->pszDisplayName) || WDL_HasUTF8(bi->lpszTitle)) AND_IS_NOT_WIN9X) { MBTOWIDE(wfn,bi->pszDisplayName); if (wfn_ok) { MBTOWIDE(wtxt,bi->lpszTitle); if (wtxt_ok) { BROWSEINFOW biw ={ bi->hwndOwner,bi->pidlRoot,wfn,wtxt,bi->ulFlags,bi->lpfn,(LPARAM)bi->lParam,bi->iImage }; LPITEMIDLIST idlist = SHBrowseForFolderW(&biw); MBTOWIDE_FREE(wfn); MBTOWIDE_FREE(wtxt); return (struct _ITEMIDLIST *) idlist; } MBTOWIDE_FREE(wtxt); } MBTOWIDE_FREE(wfn); } return (struct _ITEMIDLIST *)SHBrowseForFolderA(bi); }
static LPITEMIDLIST WINAPI SHBrowseForFolderUA(PBROWSEINFO lpbi) { // BROWSEINFOA and BROWSEINFOW don't contain any actual string data, // so the structs can be copied. BROWSEINFOA abi; memcpy(&abi, lpbi, sizeof(abi)); // Convert constant strings from UTF-8 to ANSI. char *lpszaTitle = NULL; if (lpbi->lpszTitle) { lpszaTitle = w32u_UTF8toANSI(lpbi->lpszTitle); abi.lpszTitle = lpszaTitle; } // Allocate the return buffer. char *pszaDisplayName = NULL; if (lpbi->pszDisplayName) { // This is assumed to be MAX_PATH characters. pszaDisplayName = (char*)malloc(MAX_PATH * sizeof(char)); abi.pszDisplayName = pszaDisplayName; } // Get the directory list entry. LPITEMIDLIST pidl = SHBrowseForFolderA(&abi); // Convert the non-constant strings from ANSI to UTF-8. if (abi.pszDisplayName) { w32u_ANSItoUTF8_copy(lpbi->pszDisplayName, abi.pszDisplayName, MAX_PATH); } // Free the strings. free(lpszaTitle); free(pszaDisplayName); return pidl; }
string CmFile::BrowseFolder() { static char Buffer[MAX_PATH]; BROWSEINFOA bi;//Initial bi bi.hwndOwner = NULL; bi.pidlRoot = NULL; bi.pszDisplayName = Buffer; // Dialog can't be shown if it's NULL bi.lpszTitle = "BrowseFolder"; bi.ulFlags = 0; bi.lpfn = NULL; bi.iImage = NULL; LPITEMIDLIST pIDList = SHBrowseForFolderA(&bi); // Show dialog if(pIDList) { SHGetPathFromIDListA(pIDList, Buffer); if (Buffer[strlen(Buffer) - 1] == '\\') Buffer[strlen(Buffer) - 1] = 0; return string(Buffer); } return string(); }
// 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; }
/* * Tests if clicking the "Make New Folder" button in a SHBrowseForFolder * dialog box creates a new folder. (Bug 17986). * * Here follows a description of what happens on W2K,Vista, W2K8, W7: * When the "Make New Folder" button is clicked a new folder is created and * inserted into the tree. The folder is given a default name that depends on * the locale (e.g. "New Folder"). The folder name is selected and the dialog * waits for the user to type in a new name. The folder is renamed when the user * types in a name and presses enter. * * Note that XP and W2K3 do not select the folder name or wait for the user * to type in a new folder name. This behavior is considered broken as most * users would like to give the folder a name after creating it. The fact that * it originally waited for the user to type in a new folder name(W2K), and then * again was changed back wait for the new folder name(Vista, W2K8, W7), * indicates that MS also believes that it was broken in XP and W2K3. */ static void test_click_make_new_folder_button(void) { HRESULT resCoInit, hr; BROWSEINFOA bi; LPITEMIDLIST pidl = NULL; LPITEMIDLIST test_folder_pidl; IShellFolder *test_folder_object; char test_folder_path[MAX_PATH]; WCHAR test_folder_pathW[MAX_PATH]; CHAR new_folder_path[MAX_PATH]; CHAR new_folder_pidl_path[MAX_PATH]; char selected_folder[MAX_PATH]; const CHAR title[] = "test_click_make_new_folder_button"; int number_of_folders = -1; SHFILEOPSTRUCTA shfileop; if (does_folder_or_file_exist(title)) { skip("The test folder already exists.\n"); return; } /* Must initialize COM if using the NEWDIAlOGSTYLE according to MSDN. */ resCoInit = CoInitialize(NULL); if(!(resCoInit == S_OK || resCoInit == S_FALSE)) { skip("COM could not be initialized %u\n", GetLastError()); return; } /* Leave room for concatenating title, two backslashes, and an extra NULL. */ if (!GetCurrentDirectoryA(MAX_PATH-strlen(title)-3, test_folder_path)) { skip("GetCurrentDirectoryA failed %u\n", GetLastError()); } strncat(test_folder_path, "\\", 1); strncat(test_folder_path, title, MAX_PATH-1); strncat(test_folder_path, "\\", 1); /* Avoid conflicts by creating a test folder. */ if (!CreateDirectoryA(title, NULL)) { skip("CreateDirectoryA failed %u\n", GetLastError()); return; } /* Initialize browse info struct for SHBrowseForFolder */ bi.hwndOwner = NULL; bi.pszDisplayName = selected_folder; bi.lpszTitle = title; bi.ulFlags = BIF_NEWDIALOGSTYLE; bi.lpfn = create_new_folder_callback; /* Use test folder as the root folder for dialog box */ MultiByteToWideChar(CP_UTF8, 0, test_folder_path, -1, test_folder_pathW, MAX_PATH); hr = SHGetDesktopFolder(&test_folder_object); ok (SUCCEEDED(hr), "SHGetDesktopFolder failed with hr 0x%08x\n", hr); if (FAILED(hr)) { skip("SHGetDesktopFolder failed - skipping\n"); return; } test_folder_object->lpVtbl->ParseDisplayName(test_folder_object, NULL, NULL, test_folder_pathW, 0UL, &test_folder_pidl, 0UL); bi.pidlRoot = test_folder_pidl; /* Display dialog box and let callback click the buttons */ pidl = SHBrowseForFolderA(&bi); number_of_folders = get_number_of_folders(test_folder_path); ok(number_of_folders == 1 || broken(number_of_folders == 0) /* W95, W98 */, "Clicking \"Make New Folder\" button did not result in a new folder.\n"); /* There should be a new folder foo inside the test folder */ strcpy(new_folder_path, test_folder_path); strcat(new_folder_path, new_folder_name); ok(does_folder_or_file_exist(new_folder_path) || broken(!does_folder_or_file_exist(new_folder_path)) /* W95, W98, XP, W2K3 */, "The new folder did not get the name %s\n", new_folder_name); /* Dialog should return a pidl pointing to the new folder */ ok(SHGetPathFromIDListA(pidl, new_folder_pidl_path), "SHGetPathFromIDList failed for new folder.\n"); ok(strcmp(new_folder_path, new_folder_pidl_path) == 0 || broken(strcmp(new_folder_path, new_folder_pidl_path) != 0) /* earlier than Vista */, "SHBrowseForFolder did not return the pidl for the new folder. " "Expected '%s' got '%s'\n", new_folder_path, new_folder_pidl_path); /* Remove test folder and any subfolders created in this test */ shfileop.hwnd = NULL; shfileop.wFunc = FO_DELETE; /* Path must be double NULL terminated */ test_folder_path[strlen(test_folder_path)+1] = '\0'; shfileop.pFrom = test_folder_path; shfileop.pTo = NULL; shfileop.fFlags = FOF_NOCONFIRMATION|FOF_NOERRORUI|FOF_SILENT; SHFileOperationA(&shfileop); if (pidl) CoTaskMemFree(pidl); if (test_folder_pidl) CoTaskMemFree(test_folder_pidl); test_folder_object->lpVtbl->Release(test_folder_object); CoUninitialize(); }
/* ======================================= WinMain 程序入口 ======================================= */ int WINAPI WinMain ( __CR_IN__ HINSTANCE curt_app, __CR_IN__ HINSTANCE prev_app, __CR_IN__ LPSTR cmd_line, __CR_IN__ int cmd_show ) { uint_t argc; ansi_t** argv; CR_NOUSE(curt_app); CR_NOUSE(prev_app); CR_NOUSE(cmd_show); /* 只允许一个例程 */ ximp_stop_running(); if (misc_is_running(EXE_XNAME)) return (QST_ERROR); /* 建立 CrHack 系统 */ if (!set_app_type(CR_APP_GUI)) return (QST_ERROR); /* 获取命令行参数, 不包括进程文件名 */ argv = misc_get_param(cmd_line, &argc); sINIu* ini; ansi_t* str; bool_t old = TRUE; /* 加载配置文件 */ str = file_load_as_strA(QST_PATH_CONFIG WIN_ICONF); if (str != NULL) { ini = ini_parseU(str); mem_free(str); if (ini != NULL) { old = ini_key_intxU("sdir::old_style", TRUE, ini); ini_closeU(ini); } } /* 参数解析 [起始目录] */ g_root = NULL; if (argc > 0) { /* 验证目录是否存在 */ if (misc_dir_exist(argv[0])) g_root = argv[0]; } /* 未指定目录则使用上次结果 */ if (g_root == NULL) g_root = file_load_as_strA(QST_SELECT_DIR); if (!old) { BROWSEINFOA bi; LPITEMIDLIST pidl; ansi_t path[MAX_PATH]; /* 使用新风格的目录打开窗口 */ CoInitialize(NULL); bi.hwndOwner = NULL; bi.pidlRoot = NULL; bi.pszDisplayName = path; bi.lpszTitle = ""; bi.ulFlags = BIF_RETURNONLYFSDIRS; if (g_root == NULL) bi.lpfn = NULL; else bi.lpfn = BrowseCallbackProc; bi.lParam = 0; bi.iImage = 0; pidl = SHBrowseForFolderA(&bi); if (pidl != NULL && SHGetPathFromIDListA(pidl, path)) ximp_dir_write(path); CoUninitialize(); return (QST_OKAY); } /* 标准 VCL 过程开始 */ try { Application->Initialize(); Application->Title = WIN_TITLE; Application->CreateForm(__classid(TfrmMain), &frmMain); Application->Run(); } catch (Exception &exception) { Application->ShowException(&exception); } catch (...) { try { throw Exception(""); } catch (Exception &exception) { Application->ShowException(&exception); } } return (QST_OKAY); }