ebmDevMag.com home
ebm Developer's Magazine
links

developer's mag
main page

article
part 1
part 2
part 3
part 4
part 5
part 6


6 - Example Code

To illustrate the concepts discussed here, this column's source code includes two dialogs suitable for general use. The first is a flexible message box:

int MessageBox("message","button1","button2","button3");

The function simply displays the text, and from one to three buttons for response. The return is the index of the button pressed (0 for button1, 1 for button2, 2 for button3). Leave off entries to create a display with fewer buttons. For instance, this will display a single OK button and text message:

MessageBox("Single Button Here!","OK");

The second dialog is a simple text entry box:

bool InputBox(const char *caption,char *text,int maxLen);

The dialog displays a caption, and a text edit control with the text data displayed. On return, the text string is written back and the function returns true (unless cancel is selected, in which case the return value is false, and the string is not changed). The value 'maxLen' is the maximum length of the text (including null byte), and limits writing to prevent overflowing the text buffer. This dialog illustrates parameter passing - the text string passed is filled from the object before closing. Notice also the keyboard button - this is a system icon used to make the display more user-friendly. Although you can call up the keyboard with the upward pen stroke, this is a simple touch to enhance usability.

The demo program (eg_8.zip, including source and SEB file) calls up each dialog form, and displays the results. It gives you a base to test variations for your own use, and lets you walk through the code to get an idea of how each dialog works. There's a fair amount of code in the constructors, showing how they format themselves to fit onscreen. Reviewing it should give you ideas on how to manage your own window formatting, to make more flexible displays.

Dialogs are necessary on all but the most trivial of programs. Working with them, knowing how to program them, and designing them are useful skills that not only impact your ebm programming projects, but enhance development on other platforms.

Previous Section


Copyright © 2001-2006 ebmDevMag.com - Legal Notice