Tuesday, April 10, 2012

Select Folder Dialog (C++ Builder)

問題:TOpenDialog 可用來選擇要開啟的檔案, 但如何選擇某一個資料夾。

回答:用 SelectDirectory()

bool __fastcall SelectDirectory(System::UnicodeString & Directory, 
     System::Set<Filectrl::TSelectDirOpt,0,2> Options, int HelpCtx);
#include "FileCtrl.hpp"
const SELDIRHELP = 1000;
void __fastcall Form1::Button1Click(TObject *Sender)
    String Dir = "C:\\Program Files";
    if (SelectDirectory(Dir, TSelectDirOpts() << sdAllowCreate << sdPerformCreate << sdPrompt,SELDIRHELP))
              Label1->Caption = Dir;

Unit: FileCtrl
Type: function


Brings up a dialog to allow the user to enter a directory name.

Call SelectDirectory to let the user enter a directory name.
Use the first syntax to call the Select Directory dialog box. The directory passed to the function with the Directory parameter appears as the currently selected directory when the dialog box appears. The name of the directory the user selects becomes the value of Directory when the function returns.
The HelpCtx parameter is the help context ID number.
Use the second syntax to display the Windows directory browser. The Caption parameter specifies a caption for the dialog. The Root parameter specifies the root directory from which to browse. The selected directory is returned as the Directory parameter. When using this syntax, SelectDirectory does not change the value of the current directory.
Warning:  You can't use the same variable for the Root parameter and the Directory parameter.
The Options parameter is a set of values. If Options is the empty set, the user can only select a directory that already exists. No edit box is provided for the user to enter a new directory name. If Options is not empty, the included values determine how the dialog responds when the user types a nonexistent directory name.
With either syntax, SelectDirectory returns true if the user selected a directory and chose OK, and false if the user chose Cancel or closed the dialog box without selecting a directory.

See Also

  • DirectoryExists
  • ForceDirectories

[Qt] 執行檔需要哪些 Dll?

 1. 使用 Qt  的 windeployqt.exe 工具 (在 C:\Qt\Qt5.14.1\5.14.1\msvc2017\bin\)。   a. 把執行檔 myProgram.exe 放在某個資料夾。   b. 在檔案總管這個資料夾按 Shift 和滑鼠右鍵,開啟 Po...