1.18.1.1 Built-in Dialog Boxes


Input Box

Input boxes are used to solicit textual information from program users. The global function InputBox is used to open an input box.

// enter string
string strName = InputBox("Please enter your name", "");
printf("Name is %s.\n", strName);

// enter numeric
double dVal = InputBox(0, "Please enter a value");
printf("Value is %g.\n", dVal);

Message Box

Message boxes are used to convey information, or to prompt a user with a limited number of choices. The information presented is considered important enough to require the user's attention before they are allowed to continue.

The first example shows a simple OK message box to inform the user that their file has downloaded successfully.

string strTitle = "File Download";
string strMsg = "Your file downloaded successfully.";
MessageBox(GetWindow(), strMsg, strTitle, MB_OK);

The next example shows an OK-Cancel message box with an exclamation icon to warn the user that they will not be able to undo an action. This gives the user a choice to proceed or to cancel their action.

string strTitle = "Delete Data";
string strMsg = "You will not be able to undo this change.";
int nMB = MB_OKCANCEL|MB_ICONEXCLAMATION;
if( IDOK == MessageBox(GetWindow(), strMsg, strTitle, nMB) )
    out_str("Data has been deleted");

The next example shows a Yes-No message box with a question mark icon. This is being used to ask the user if they want to continue with their action.

string strTitle = "Close Windows";
string strMsg = "Are you sure you want to close all windows?";
int nMB = MB_YESNO|MB_ICONQUESTION;
if( IDYES == MessageBox(GetWindow(), strMsg, strTitle, nMB) )
    out_str("All windows have been closed.");

The next example shows a private reminder message dialog. An Ini file is used to initialize the dialog. Each section in the ini file is used for a single message.

/* Example Dialog.ini file in UFF.
[MyMessage]
;Title = My Reminder
Msg = This is my message.
;Btns = 4 for Yes No buttons
Btns = 4
*/
void PrivateReminderMessage_ex1()
{
   string iniFileName = GetOriginPath(ORIGIN_PATH_USER) + "Dialog.ini";
   int nRet = PrivateReminderMessage("MyMessage", iniFileName);
   printf("User chose %d\n", nRet);
}

Progress Box

A progress box is a small dialog box that indicates the software is busy processing data. This dialog box contains a progress bar for showing the fraction of the completed processing. The progress dialog box is usually used in iterative loops.

int iMax = 10, iMin = 0;
progressBox prgbBox("This is a ProgressBox example:");
prgbBox.SetRange(iMin, iMax);

for (int ii=iMin; ii<=iMax; ii++)
{
    if(prgbBox.Set(ii))
        printf("Hi, it is now at %d.\n", ii);
    else 
    {
        out_str("User abort!"); // Click Cancel button to abort
        break;
    }
    LT_execute("sec -p 0.5");
}

File Dialogs

Origin C provides functions for all the common file and path dialogs. This includes dialogs that prompt the user to open a single file, open multiple files, save a file, and choose a folder. The following sections show you how to use these dialogs in your own applications.

File Open Dialog

StringArray saFiletypes(3);
saFiletypes[0]="[Project (*.OPJ)] *.OPJ";
saFiletypes[1]="[Old version (*.ORG)] *.ORG";
saFiletypes[2]="[Worksheets (*.OGW)] *.OGW";

string strPath = GetOpenBox( saFiletypes, GetAppPath(false) ); 
out_str(strPath);

Multiple Files Open Dialog

StringArray saFilePaths;
StringArray saFileTypes(3);    
saFileTypes[0]="[Project (*.OPJ)] *.OPJ";
saFileTypes[1]="[Old version (*.ORG)] *.ORG";
saFileTypes[2]="[Worksheets (*.OGW)] *.OGW";

// Press Ctrl or Shirt key to choose multiple files
int iNumSelFiles = GetMultiOpenBox(saFilePaths, saFileTypes, GetAppPath(false));

File SaveAs Dialog

string strDefaultFilename = "Origin";
FDLogUseGroup nFDLogUseGroup = FDLOG_ASCII; // ASCII file group 

string strPath = GetSaveAsBox(nFDLogUseGroup,GetAppPath(false),strDefaultFilename);
out_str( strPath );

Path Browser Dialog

string strPath = BrowseGetPath(GetAppPath() + "OriginC\\", "This is an example");
out_str(strPath);