Learning to Program in PowerBasic for GWBASIC Programmers

Here is a list of things I have put together that can help you learn how to program in PowerBasic, especially if you have never done any Windows programming. In particular, it is oriented toward someone who has done a lot of programming in GWBasic or QuickBasic and who now wants to move to Windows. This is the information that I wish I had when I first started using PowerBasic for Windows. It is oriented mostly toward PowerBasic for Windows, although much of it is in common with the Console Compiler too.

Gary Peek

Some general comments

Important Resources

Programming Style (SDK versus DDT)

Throughout PowerBasic source code and in the PowerBasic forums you will find references to SDK and DDT. Both programming styles work just fine, however, DDT makes getting started with PowerBasic easier.

1. SDK (Software Development Kit) style programming (in any language) means separating the source code file from the layout of the windows, dialog boxes, and other "resources" used by the program, like icons, bitmaps, etc. These resources are placed in a "resource file" which gets compiled separately. (Note: The "Resource Compiler" has its own Help File). Utility programs from Microsoft are available as part of the PowerBasic development software to create most of these resources.

2. DDT (Dynamic Dialog Tools) is a feature that PowerBasic includes that allows you to specify and create windows (dialog boxes) directly in the source code. Many of the example programs you will find in the PowerBasic forums will be DDT style programs, because it is quick to write an example program as a single file which the reader can copy, paste, and compile in PowerBasic.

3. Third party software is available for generating both SDK and DDT style code and resources, with most of it being very helpful and affordable.

Files included with PowerBasic

The following files, which are included with PowerBasic, deserve a bit of explanation. The latest versions are available on the PowerBasic web site.

WIN32API.INC is the equates, types, and declarations for calling the Windows API from your PowerBASIC programs.

Helpful hint: Whenever you see an equate used as an option, (something that begins with the % sign), search for it in WIN32API.INC and find out all of the other options available for that API.

COMDLG32.INC is the Windows API Common Dialog declarations. Common Dialog boxes are things like a Printer dialog box that you get right before printing, or the FileOpen dialog box which lets you select from a list of files. You will want to look up the available options to the Common Dialogs too.

COMMCTRL.INC is the declarations for Common Controls, like scroll bars, progress bars, up-down controls, etc. A list of the Common Controls and details about them is in the Win32 Help File.

Things you will see in PowerBasic source code

Once you have compiled and run a number of example programs in PowerBasic, you will begin to notice some things about them that do not seem to be explained anywhere. Some of this is because it really isn't explained anywhere, and some of it is explained in some of the resources listed above, but you have not yet seen it because you have been busy trying out example code.

Data types and naming variables-

Some programmers name variables according to a convention known as Hungarian notation. This type of naming indicates what data type the variable is just by looking at its name. For example lpszName would be a long pointer (lp) to a string (s) of the ASCIIZ type (z). This type of notation is helpful when trying to understand how someone's code works, however if not explained, this type of naming seems strange and unnecessary.

Since Windows programming involves the use of many "Handles", one of the most used naming conventions is naming variables that store handles with an "h" as the first character. For example, hWnd as a handle to a window, hDlg as the handle to a dialog box, etc.

In the PowerBasic on-line help file, examples are often given that show the result of a command using a variable ending with & character. This character is not really needed, but is there in the example to remind you that the command returns a long integer.

For example, s$ = LEFT$(string_expression, n&) means that the LEFT$ function returns a string ($) and requires a numeric value (&) as one of the arguments.


Near the beginning of code and resource files you will often find equates that are named things like %ID_THIS or %IDM_THAT. Since each control in a window or dialog box needs a unique identifier (number) most people use these equates to identify the control. The prefixes to these equates are sometimes used to further identify the equate, for example, IDM for an ID for a menu. Note that IDOK, IDCANCEL, IDRETRY, IDYES, IDNO, IDCLOSE, IDHELP and others are predefined in WIN32API.INC.

Note: The first equate should normally be %WM_USER, which is a constant that Windows specifies as the first in a group of numbers to be used to define private messages (or your controls). Subsequent equates should be %WM_USER + (plus some number assigned by you.)


In WIN32API.INC they are defined as: %TRUE = 1 %FALSE = 0 %NULL = 0 You will want to look up the ISTRUE, ISFALSE, and NOT operators in the PowerBasic on-line help file to see why using these equates is not very obvious and straightforward.

Code shortcuts and non-intuative construction-

If you have never programmed in the "C" programming language or are new to Windows programming, some of the conditional statements you see in PowerBasic will seem strange. One of the favorite things that programmers experienced in this type of programming like to do is to write shortcuts.

One of the most confusing shortcuts is calling a function which returns a True or False result within a conditional statement, which obscures its meaning to less experienced programmers. The following is a typical example.

"If the result (returned value) of the function is anything but zero then condition is True."

IF FunctionName() THEN
 ... do something

This construction is possible because an IF statement is True if the condition is anything but zero.

The following is the equivalent code but much more obvious, however, you will see this type of code much less often because the variable "result" must be defined.

result = FunctionName()
IF result <> 0 THEN
 ... do something

log file