The ac_request function with the dialog_get_filename directive invokes a file selection dialog.

Call:

int iret = ac_request("dialog_get_filename",string Title, string Filter, string sStartFolder,string &FileNameAndPath);


Here: Title - window title, Filter - filter string for file selection, sStartFolder - initial path where to select a file.

The full path to the selected file is returned to the FileNameAndPath variable.

If iret is -1, it means that the user has abandoned the choice.


Example.

Select a program file with the .cpp extension. Search first in the root directory of drive C:. Optional - run this selected program file for execution.


string sFileNameAndPath;
string sStartFolder = "c:\\";
int iret = ac_request("dialog_get_filename", "Select a file to launch", "cpp", sStartFolder, sFileNameAndPath);
if (iret == -1)
{
    cout << "User declined file selection\n";
    return -1;
}
run_cpp("run_from_file", sFileNameAndPath);
cout << "File selected and executed";



You can create complex filters and filter groups based on file extensions.


Example.

Allow the user to select a file from three selection options.

option 1 - Excel with extensions xls, xslx, xslm;

option 2 - Archicad with extensions pln, pla, tpl;

option 3 - Text with extensions txt, sx.

Start directory - current;


string FileNameAndPath;
ac_request("dialog_get_filename", "Select file", "Excel,xls,xlsx,xlsm|Archicad,pln,pla,tpl|Text,txt,sx", "", FileNameAndPath);
coutvar << FileNameAndPath;