Characteristics PowerBASIC is a native-code BASIC compiler whose reported merits are simplicity of use and speed compared to other languages. Although the compiled code is fast enough for most purposes, the compilers also support inline
assembler which can be used for hand optimization of critical routines. The Windows compilers (PBWin & PBCC) support almost all of the
x86 instruction set, including
FPU,
SIMD, and
MMX, the main exceptions being a few which are useful mostly to systems programmers. One can insert any unsupported instructions by inserting their
opcodes with the "db", "dw", and "dd" statements. Lines of assembler code can be freely interspersed with lines of BASIC code, although one must always consider the potential interactions between the two types of code.
Hello world Hello world is used to give a very small example of the
syntax used by a programming language and is often the smallest possible program for any given programming language. Here is an example of a PBCC hello world program. By default PBCC creates a console window at runtime for displaying output. The use of Waitkey$ in this example prevents the console window from automatically closing until the operator sees the displayed text. Function PBMain Print "Hello, World!" Waitkey$ End Function Here is the PBWin version, which displays a Windows "dialog" message box. Function PBMain MsgBox "Hello, World!" End Function
Structured control statements These structured control statements eliminate many instances that would require the use of GOTO and labels: • iterate - skips ahead to the next iteration of the loop containing it (iterate do, iterate loop, iterate for), like the
continue statement in most languages • exit - sends execution to just after the loop (exit for, exit do, exit loop), conditional (exit if, exit select), or block (exit function, exit sub) containing it, like the
break statement in most languages
Object-oriented programming PBWin and PBCC support
object-oriented programming in the form of
COM classes, however the compilers do not force you to use OOP, it is merely an option. In-process and out-of-process COM Servers can also be built using these compilers.
Graphics Both the Console Compiler and Windows Compiler can create graphic windows. The GRAPHICs statements are higher-level than Windows'
Graphics Device Interface (GDI) library functions.
Elements of the GRAPHIC statements GRAPHIC WINDOWS are dedicated dialogs each containing a single control which fills the dialog's client area. GRAPHIC controls are
child windows which support the same GRAPHIC drawing functionality as GRAPHIC windows. GRAPHIC BITMAPS are also defined, again supporting the GRAPHIC drawing functionality, but as purely memory objects, like
Windows bitmaps or
DIB sections. Keyboard and mouse handling statements are included among the GRAPHIC statements. Character output to a GRAPHIC target uses fonts specified via the FONT NEW statement.
Creating a GRAPHIC WINDOW application A GRAPHIC WINDOW is the equivalent of a Windows
dialog box containing a static control on which drawing operations can be done. A single BASIC statement will create a GRAPHIC WINDOW and specify its size, position and title. It is not essential to specify a
WNDPROC for the GRAPHIC WINDOW. A short source code example for a complete GRAPHIC WINDOW application follows: • Compile Exe ' using either PBCC6 or PBWIN10 compiler • Dim All Function PBMain Local GW As Dword ' start a GRAPHIC WINDOW Graphic Window New "graphic window", 100, 100, 200, 200 to GW ' show a coloured disc Graphic Ellipse (10, 10)-(190, 190), %rgb_Red, %rgb_SeaGreen, 0 ' wait for a keypress Graphic Waitkey$ End Function
Comparison of PB GRAPHIC statements with the GDI API Using PB GRAPHIC statements, a GRAPHIC (WINDOW, BITMAP, or control) is first selected as the current GRAPHIC target, then operations are done on it without requiring it to be identified again. Contrast this with the GDI API approach, where the
Device Context handle is required for every drawing operation. It is not necessary when using the PB GRAPHIC statements to define a brush or pen as a separate entity, nor is it necessary to redraw the GRAPHIC target (when in view) in response to
Windows messages such as WM_PAINT and WM_ERASEBKGND. GRAPHIC targets are persistent. When GRAPHIC targets are attached, a REDRAW option can be specified which buffers the results of drawing operations until they are specifically requested. Using this technique reduces flicker in a similar way to the technique of drawing on memory
DCs when using the GDI API. Pixel operations are possible using the GRAPHIC GET|SET PIXEL statements, in a manner similar to GetPixel/SetPixel of the GDI API. GRAPHIC GET BITS allows the entire bitmap to be loaded into a dynamic string. This can be manipulated either as a string or by mapping an array onto it. It can be placed back into the GRAPHIC target by GRAPHIC SET BITS.
Complementarity of GRAPHIC statements and the Windows GDI API The GRAPHIC statements contain all the commonly used GDI API functions, but if you need one that is not included it is possible to obtain the
hDC of any GRAPHIC target and thereby use GDI API functions on it. ==User community==