Dialog Box Commands

Top  Previous  Next

Authors make adjustments to graphic interface of their applications, but there are some standard Windows dialog boxes that are used by all applications.

MMB introduces this standard dialog boxes, available through it's script language:

  Message Box
  Message Box Ex
  Open File dialog box
  Save File dialog box
  Browse for Folder dialog box
  Color Picker dialog box
  Font Picker dialog

 

Message("String","Variable")

Description

 

Displays Message box with OK button and exclamation mark.

Use first parameter to set message you want to display:

Hello from MMB

Second parameter can be used to show a value of any string or numerical variable. This is especially useful when debugging a program, to check current variable value:

UserFile$

Here's an example of a Message box:

Message

Code Examples

 

**Show Message box without variables:

Message("Hello from MMB", "")

**Show Message box with numerical variable as 2nd parameter:

year=2004

Message("Selected year: ", "year")

**Show Message box with string variable as 2nd parameter:

name$='Sam'

Message("Welcome, ","name$")

**Show Message box with 2 string variables as parameters:

greeting$='Hello,'

name$='Peter'

Message("greeting$","name$")

Additional Info

 

Message box is displayed on top and project's window can't be used until user closes message box.

 

MessageEx("Title","text, flag[, timeout]")

Description

 

Displays fully configurable Message box.

The first parameter defines the Message box title bar. The second parameter is a comma separated list of parameters defining the rest of Message box parameters like a number of buttons, displayed icon, default button, etc..

Description:

title:

title bar text

text:

text in message box

flag:

indicates the type of message box and the possible button combinations

timeout:

[optional parameter] Timeout in milliseconds. The message box will be automatically closed after timeout expiration

Return value after Message box confirmation/expiration is stored in CBK_MsgEx where..

Success => returns the ID of pressed button.

Timeout => returns -1 if the message box timed out.

message buttons return ID values

OK

1

CANCEL

2

ABORT

3

RETRY

4

IGNORE

5

YES

6

NO

7

TRY AGAIN

10 **

CONTINUE

11 **

** only on Windows 2000/XP and above.

The message Flag parameter can be a combination of these values:

button related flags

OK button

0

OK and Cancel

1

Abort, Retry, and Ignore

2

Yes, No, and Cancel

3

Yes and No

4

Retry and Cancel

5

Cancel, Try Again, Continue

6 **

** only on Windows 2000/XP and above.

icon related flags

No icon (default)

0

Stop sign

16

Question mark

32

Exclamation mark

48

'i' Icon consisting of an 'i' in a circle

64

default button related flags

First button is default button (default)

0

Second button is default button

256

Third button is default button

512

message box modality related flags

Application (default)

0

System modal (dialog has an icon in title bar)

4096

Task modal

8192

miscellaneous flags

nothing special (default)

0

MsgBox has top-most attribute set

262144

title and text are right justified

524288

How to use the above flags? Actually, it's pretty simple! Just select the flags you would like to see in the message box and count them up. So for example, OK/Cancel buttons + Stop sign + 2nd button as default will require flags 1 + 16 + 256 = 273 and this value should be used as the above mentioned Flag parameter.

Here you can see two examples of extended message box:

Messageex

Messageex2

 

Code Examples

 

** here is an example of message box with "Abort/Retry/Ignore" buttons (2) + Question mark (32) + 3rd button as default (512)

Title$ = 'Extended message box'

Text$ = 'This is Abort/Retry/Ignore message box.'

Flag= 2 + 32 + 512

Params$ = Text$+','+CHAR(Flag)

MessageEx("Title$","Params$")

** here is an example of message box with comma character inside text

Title$ = 'Extended message box'

Text$ = '"This is, message box"'

Params$ = Text$ + ',64'

MessageEx("Title$","Params$")

Additional Info

 

IMPORTANT REMARKS!

A message box appears centered on the application screen.

The size of message box may vary according to the text it contains.

The title could get truncated if too long and the SYSTEMMODAL flag is used.

The title bar icon in case of SYSTEMMODAL cannot by changed :(

If you want to use comma character inside the "text" flag, you have to enclose entire text in an additional pair of double quotes..like this..

Text$ = '"This is, message box"'

And NO, there is no way to change/replace the button labels!

 

OpenFile("Filter","DefaulExt")

Description

 

Displays Open File dialog box. First parameter sets extension filter, default extension is specified as a second parameter.

IMPORTANT! OpenFile command does not open anything! It's just a dialog box, which fills the MMB path macros with selected path!

 

Extension filter - sets what file formats will be displayed in a dialog box. MMB supports multiple masks, selectable through "Files of type" combobox inside Open File dialog box. Filter is set in a string as the first command parameter. Elements and their parts are separated using | character.

Mask element is comprised of label and extension:

MPEG Files (*.mpg) | *.mpg

Blue part is extension element label, green part is extension itself. They're separated with | character. You'll write another extension element behind this one, separating it again using | character. So extension filter will now look like this:

MPEG Files (*.mpg) | *.mpg| AVI Files (*.avi)| *.avi

When you're done adding extension elements, | character is needed at the end of parameter to signal MMB about it:

MPEG Files (*.mpg) | *.mpg| AVI Files (*.avi)| *.avi |

There. Line above represents first command parameter. It is also common to specify "All files" as the last extension element, giving users ability to see all files (turn filtering off). Here's how such version of first command parameter looks like:

MPEG Files (*.mpg) | *.mpg| AVI Files (*.avi)| *.avi | All Files (*.*) | *.* |

It is also possible to specify multiple extensions in one element, giving users ability to choose among similar file extensions (.mpg & .mpeg, .htm & html, .jpg & .jpeg...) . Use ; as an extension delimiter:

Movie Files (*.mpg,*.avi) | *.mpg ;*.avi| All Files (*.*)| *.* |

Default extension element, the one that will be used for file filtering when Open File dialog box appears, is set using second command parameter.

It's one of element extensions specified as the first parameter, for e.g.

*.mpg

Using multiple extensions in one element affects default extension too, so you will also use ; as extension delimiter:

*.mpg ;*.avi

Put into OpenFile command, parameters look like this:

OpenFile(" Movie Files (*.mpg,*.avi) | *.mpg ;*.avi| All Files (*.*)| *.* | "," *.mpg ;*.avi ")

Here's example of Open File dialog box, showing all files:

OpenFile

 

Once user selects file and clicks Open button (or double-clicks selected file), MMB fills OpenFile$ string variable with full folder path and file name of selected file.

Three constants also contain dialog box result:

<File> - contains the same data as OpenFile$ variable

CBK_OpenFile - contains selected file name without folder path

CBK_OpenDir - contains folder path without name of selected file
 

Code Examples

 

**Show Open File dialog box with filters for MP3, WAV, MID and MOD

**files with WAV as default filter

OpenFile(" MP3 Files (*.mp3)|*.mp3|WAVE Files (*.wav)|*.wav|MIDI Files (*.mid)|*.mid|MOD Files (*.mod)|*.mod|","*.wav")

**Show Open File dialog box with one filter for MP3, WAV, MID and MOD

**files, labeled "Sound Files"

OpenFile(" Sound Files (*.mp3,*.wav,*.mid,*.mod) |*.mp3;*.wav;*.mid;*.mod|","*.mp3;*.wav;*.mid;*.mod")

**Show Open File dialog box with filters for EXE and All files

**with EXE as default filter

OpenFile(" Executable Files (*.exe)|*.exe|All Files (*.*)|*.*|","*.exe")

**Show Open File dialog box with filters for HTML and all files

**with HTML as default filter. Result is displayed in message boxes

OpenFile(" HTML Files (*.htm)|*.htm|All Files (*.*)|*.*|","*.htm")

Message("Selected file in OpenFile$ variable: ","OpenFile$")

file$=<File>

Message("Selected file in <File> constant: ","file$")

file$=CBK_OpenFile

Message("Selected file name: ","file$")

folder$=CBK_OpenDir

Message("Folder path of selected file: ","folder$")

**Show Open File dialog box at defined position (source application directory in this case) and with filter for TXT files.

Path$=<SrcDir>+'*.txt'

OpenFile("TXT Files (*.txt)|*.txt|All Files (*.*)|*.*||","Path$")

Additional Info

 

Dialog box is displayed on top and project's window can't be used until user closes dialog box.

 

SaveFile("Filter","DefualtExt")

Description

 

Displays Save File dialog box. First parameter sets extension filter, default extension is specified as a second parameter.

IMPORTANT! SaveFile command does not save anything! It's just a dialog box, which fills the MMB path macros with selected path!

Extension filter - sets what file formats will be displayed in a dialog box. MMB supports multiple masks, selectable through "Files of type" combobox inside Save File dialog box. Filter is set in a string as first command parameter. Elements and their parts are separated using | character.

Mask element is comprised of a label and extension:

TXT Files (*.txt) | *.txt

Blue part is extension element label, green part is extension itself. They're separated with | character. You'll write another extension element behind this one, separating it again using | character. So extension filter will now look like this:

TXT Files (*.txt) | *.txt| LOG Files (*.log)| *.log

When you're done adding extension elements, | character is needed at the end of parameter to signal MMB about it:

TXT Files (*.txt) | *.txt| LOG Files (*.log)| *.log |

Line above represents first command parameter. It is also common to specify "All files" as the last extension element, giving users ability to see all files (turn filtering off). Here's how such version of first command parameter looks like:

TXT Files (*.txt) | *.txt| LOG Files (*.log)| *.log | All Files (*.*) | *.* |

It is also possible to specify multiple extensions in one element, giving users ability to choose among similar file extensions (.mpg & .mpeg, .htm & html, .jpg & .jpeg...) . Use ; as extension delimiter:

Text Files (*.txt,*.log) | *.txt ;*.log| All Files (*.*)| *.* |

Default extension element, the one that will be used for file filtering when Save File dialog box is displayed, is set using second command parameter.

It's one of element extensions specified in first parameter, for e.g.

*.txt

Using multiple extensions in one element affects default extension too, so you will also use ; as an extension delimiter:

*.txt ;*.log

Put into SaveFile command, parameters look like this:

SaveFile(" Text Files (*.txt,*.log) | *.txt ;*.log| All Files (*.*)| *.* | "," *.txt ;*.log ")

Here's example of Save File dialog box, showing all files:

SaveFile

 

Once user selects or writes file name and clicks Save button (or double-clicks selected file), MMB will fill OpenFile$ string variable with full folder path and file name of selected file.

Three constants also contain dialog box result:

<File> - contains the same data as OpenFile$ variable

CBK_OpenFile - contains selected file name without folder path

CBK_OpenDir - contains folder path without name of selected file
 

Code Examples

 

**Show Save File dialog box with filters for TXT and LOG

**files with TXT as default filter

SaveFile(" TXT Files (*.txt)|*.txt|LOG Files (*.log)|*.log|", "*.txt")

**Show Save File dialog box with one filter for TXT and LOG

**files, labeled "Text Files"

SaveFile(" Text Files (*.txt,*.log)|*.txt;*.log|", "*.txt;*.log")

**Show Save File dialog box with filters for TXT and All files

**with TXT as default filter

SaveFile(" TXT Files (*.txt)|*.txt|All Files (*.*)|*.*|","*.txt")

**Show Save File dialog box with filters for TXT and All files

**with TXT as default filter. Result is displayed in message boxes

SaveFile(" TXT Files (*.txt)|*.txt|All Files (*.*)|*.*|","*.txt")

Message("Selected file in OpenFile$ variable: ","OpenFile$")

file$=<File>

Message("Selected file in <File> constant: ","file$")

file$=CBK_OpenFile

Message("Selected file name: ","file$")

folder$=CBK_OpenDir

Message("Folder path of selected file: ","folder$")

**Show Save File dialog box at defined position (source application directory in this case) and with filter for TXT files.

Path$=<SrcDir>+'*.txt'

SaveFile("TXT Files (*.txt)|*.txt|All Files (*.*)|*.*||","Path$")

Additional Info

 

Dialog box is displayed on top and project's window can't be used until user closes dialog box.

 

BrowseForFolder("Prompt","StartFolder")

Description

 

Displays Browse for Folder dialog box. First parameter sets dialog description, second parameter sets starting (root) folder.

Both parameters are optional.

Dialog description - defines prompt that will be displayed in Browse for Folder dialog box. Usual prompt is:

Select folder:

Starting folder - sets root folder and disables browsing for upper folders. Default starting folder is:

My Computer

Here's an example of Browse for Folder dialog box:

OpenFolder

 

Once user selects folder and clicks OK button, constant CBK_OpenDir will contain selected folder path.
 

Code Examples

 

**Show basic Browse for Folder dialog box:

BrowseForFolder("","" )

**Show Browse for Folder dialog box with custom prompt:

BrowseForFolder("Select Folder: ","" )

**Show Save File dialog box with filters for TXT and All files

**with TXT as default filter

SaveFile(" TXT Files (*.txt)|*.txt|All Files (*.*)|*.*|","*.txt")

**Show Browse for Folder dialog box with custom prompt

**and c:\ as starting folder

BrowseForFolder("Select Folder: ","c:\" )

**Show Browse for Folder dialog box with custom prompt

**and starting folder specified through string variables

prompt$='Select directory'

root$='c:\\'

BrowseForFolder("prompt$","root$" )

Additional Info

 

Dialog box is displayed on top and project's window can't be used until user closes dialog box.

 

ColorPicker()

Description

 

Displays Color Picker dialog box. Uses no input parameters.

 

ColorPicker

 

Once user selects color and clicks OK button, constant CBK_SelColor will contain selected color.

Color picking uses RGB ( Red, Green, Blue) system containing 3 components.

Each component can have one of 256 levels. Greater value of component increases color intensity. If you specify value 0, color component will not be used. Value 255 uses maximum color intensity.

Result of Color Picker is a comma-separated array of string values, each representing one RGB component (first: red, second: green, third: blue) in value range 0-255.

R,G,B

Result

128,5,64

 

 

R,G,B

Result

0,255,255

 

 

To retrieve color value, simply assign contents of CBK_SelColor to a string variable:

color$=CBK_SelColor

Returned color value looks like this:

119,230,95
 

Code Examples

 

**Show Color Picker dialog box:

ColorPicker( )

**Show Color Picker dialog box, retrieve and show selected color string:

ColorPicker( )

color$=CBK_SelColor

Message("Selected color is: ","color$")

Additional Info

 

Dialog box is displayed on top and project's window can't be used until user closes dialog box.

 

FontPicker()

Description

 

Displays Font Picker dialog box. Uses no input parameters.

 

FontPicker

 

Once user selects color and clicks OK button, constant CBK_SelFont is filled with selected font parameters. The parameters are stored in this format (just a simple string array):

FONTNAME|FONTSTYLE|FONTSIZE|FONTSCRIPT|FONTEFFECT|

The individual parameters can be obtained from this array with GetArrayItem array function.

For an example of FontPicker dialog and the SetObjectParam function check the supplied 497_test_project.mbd sample project.
 

Code Examples

 

**Show Font Picker dialog box:

FontPicker()

**Show Font Picker dialog box, retrieve and show selected font name and its parameters in a Message box:

FontPicker()

FontParams$=CBK_Font

If (FontParams$<>'') Then

**font name

item$[1]=GetArrayItem(FontParams$,|,1)

**font style

item$[2]=GetArrayItem(FontParams$,|,2)

**font size

item$[3]=GetArrayItem(FontParams$,|,3)

**font script

item$[4]=GetArrayItem(FontParams$,|,4)

**font effect

item$[5]=GetArrayItem(FontParams$,|,5)

msg$= 'FONTNAME = ' + item$[1] + CHR(13) + CHR(10) + 'FONTSTYLE = ' + item$[2] + CHR(13) + CHR(10) + 'FONTSIZE = ' + item$[3] + CHR(13) + CHR(10) + 'FONTSCRIPT = ' + item$[4] + CHR(13) + CHR(10) + 'FONTEFFECT = ' + item$[5] + CHR(13) + CHR(10)

Message("Font parameters:","msg$")

End

Additional Info

 

Dialog box is displayed on top and project's window can't be used until user closes dialog box.