Using PowerBASIC Forms: Part 2

Learn how to create a Password menu using PowerBASIC Forms. In this QuickStart Tutorial you will learn how to create top-level Popup menu items and related dropdown menus with sub-items.

The PBForms visual designer for PBWin includes a Menu editor which makes the creation of menus very easy. The following example creates a couple of top-level Popup menu items and related dropdown menus with sub-items. What is the difference between a Menu Popup and a Menu Item? A Menu Popup is designed to "pop up" additional Menu Items in the form of a drop-down menu. The drop-down menu can contain Menu Items, Separators, and additional Menu Popup's.

Depending on the type of menu member being edited or created, PowerBASIC Forms will automatically enable or disable controls on the Menu Editor window to make it simple to choose the appropriate settings for each menu member.

1. Start PBForms and open up a New Dialog.

2. Press the "Menu Editor" button to display the PBForms Menu Editor Dialog box.

The Menu Editor

File Menu

3. In the "Caption" TextBox, type "&File" (without the quotes). The "&" character is used to create a Menu Accelerator. The Character after the ampersand (&) is displayed with an underline and allows the user to access the Menu Item by holding down the ALT key and then pressing the character after "&". In this case the Menu Accelerator will be ALT+F.

4. Press the "Next" button.

5. In the "Caption" TextBox type "&New" (without the quotes).

6. In the "Accelerator key" Textbox, press Ctrl+N to make this combination a keyboard shortcut to the command.

7. In the "Prompt" Textbox, type in "Creates a New File" (without the quotes). Notice that the "ID Name" and "ID Value" boxes were both updated automatically with unique names and values. It is best to let PBForms create these because it will always select unique names and values with the correct syntax. The Prompt text is displayed in a StatusBar control, which we will be adding to the dialog later.

8. Press the "Next" button.

9. In the "Caption" TextBox type in "&Open" (without the quotes)

10. In the "Accelerator key" Textbox, press Ctrl+O to make this combination a keyboard shortcut to the command.

11. In the "Prompt" TextBox type in "Opens a File" (without the quotes)

12. Press the "Next" button.

13. Select "Separator" radio button from the "Type" groupbox. This will insert a Menu Separator, which is A horizontal line used to visually separate groups of unrelated Menu Items.

14. Press the "Next" button.

15. In the "Caption" TextBox type in "E&xit" (without the quotes).

16. In the "Prompt" TextBox type in "Exit the Program" (without the quotes)

17. Press the Enter key or click the "Next" button.

Help Menu

18. Click the Left Arrow button on the "Menu Editor" dialog box. This will cause the next Menu Item or Menu Popup to be displayed at the top level directly to the right of the previous top level Menu Item or Popup.

19. Select the "Popup" radio button from the "Type" groupbox.

20. In the "Caption" Textbox, type in "&Help" (without the quotes).

21. Press the Enter key or click the "Next" button.

22. In the "Caption" TextBox type in "&About" (without the quotes)

23. In the "Prompt" TextBox type in "Displays the About Dialog Box" (without the quotes).

24. Click the "Close" button. This will close the Menu Editor and take you back to the PBForms Visual Designer.

Adding a Status Bar to the dialog

25. Double-click on the "Status Bar Control" button in the Floating Toolbox. If the Floating Toolbox is not visible, select "View | Toolbox" from the PBForms menu.

26. Make sure the newly created StatusBar is selected and press F4 to bring up the Properties dialog.

27. Delete the Caption text for the StatusBar and press OK to close the Properties dialog.

Test the menu

28. Now we are ready to test the menu. Select the "Test Dialog" button in the PBForms ToolBar or "View | Test Dialog" from the PBForms Menu. This will display the Dialog with the Menu you just have created. Try using the Menu Accelerator keys and also make sure the Prompt text displayed in the Status Bar Control when a Menu Item is highlighted is correct.

The Result

29. You are now ready to save the Dialog as a .BAS file, to be edited and compiled with PowerBASIC For Windows. Select "File | Save As" from the PBForms Menu, select a unique name and folder for the file and Save.

30. Done! PBForms has created command handlers for all menu item id's under %WM_COMMAND and a %WM_MENUSELECT callback handler which will display prompt strings of highlighted menu items in the status bar control. Open up the code in the IDE (PBEdit), replace the MSGBOX parts under the related id's with the code you want to be executed on selection of the menu items, Compile and Run.