Our first event

If you closed the the application at the end of the last section then open it now. If you open the "Project" menu you should see, at the bottom of the menu items, the name of any project you have saved. Assuming this is the case, open our saved project (which I had called "Example1") now. Check that it all looks familiar.

We are now going to add some action to our design. Windows is an event-based system as are all GUI programs. The IDE makes programming events really easy. All you have to do is double-click on the control in the IDE. You can then add an event handler. What I am planning to do is to add a handler so that when the user (left) clicks the "About" button a dialog box (called a message box) will appear. There are two stages to this process:

I shall go slowly through each of these steps.

The IDE incorporates a message box designer. Let's find this. Go to the "Edit" menu and pull it down. Just below half way is a menu item entitled "Create Message Box". Select this now. What you get is a dialog. We could spend a lot of time studying the design of this dialog (for example, note that it doesn't have any element of the normal "System Menu" found when you create a default Form) but let's go on now to use the dialog. A message box has three user-defined elements:

I suggest the following entries, but by all means choose your own:

Now we shall utilise the designer to create this.

Follow these steps:

Clicking the "Create" button pastes the outline code into the multi-line edit at the bottom of the dialog. Then enter your lines of text inside the quotation marks. Click the "Copy" button and your code is ready to insert inside the event handler.

Close the designer window and double-click on the "About" button in the Form Designer. This opens the code editor with the pointer inside the relevant procedure. Paste in your message box code. Make any changes to the text (if you made a mistake or want to change your mind). Note that the "MsgBox" variable (or other name if you changed from the default in the designer) is commented out. Delete the comments; then try it out. The "F6" key gives you a temporary run. If you have followed these steps you should now have a message produced when you click the "About" button.

Before saving this work I suggest changing the form's Caption to "Example 2" and then saving the project as "Example2".

Next we shall explore the different kinds of controls on offer and discuss how we might use them.

If you choose to close the IDE at this point you will get a message from the application - again delivered through a message box. Whenever you have modified existing code and not saved the changes (in our case because we have saved them under a different name) this alert comes up to protect you from wasting your work. In our case, of course, we do not want to save the changes under our earlier project name and so we decline to act. (Note that the message box has more than one (button) option - study the WinAPI documentation or explore the message box designer options if you want to learn more at this stage.)