Older Version
Newer Version
StPendl
Dec 7, 2008
- "corrected the links to the Window styles to point to the Win32 description, since LB does not use MFC"
StPendl
Dec 7, 2008
- "corrected the links to the Window styles to point to the Win32 description, since LB does not use MFC"
Defining the Window
To understand how stylebits can modify a window, it's important to first understand what the traditional window looks like and how it behaves. Generally speaking, a window is distinguishable from the rest of the screen by its borders. The borders create a box.
Types of Windows
The Liberty BASIC Help File identifies these four types of windows created using native LB commands:
WINDOW - the most common and the most useful, used to hold controls, can include one or more menus, can trap TAB key to move focus from one control to another.
GRAPHICS - designed to display graphics and sprites, not intended to hold controls, can trap mouse clicks and character key presses.
DIALOG - similar to the traditional window, can contain controls, cannot contain menus, can trap ENTER key as a special button to direct action. When displayed as "modal," the dialog window remain in focus until closed. (The prompt, notice and confirm windows are special dialog modal windows.
TEXT - Limited to writing and editing text, always contain a menubar that contains a read-made File Menu and a ready-made Edit Menu. (The Mainwindow is a Text Window.
There are many native variations of these four windows. See the Helpfile for variations such as full screen (_fs), _nf (no sizing frame), no scroll bars (_nsb), no titlebar (_popup), among others.
Elements of a Window
For an explanation of the parts of a window, visit this tutorial.
As well as the borders of the window box, the typical window contains a blue title bar along its top. The windows constant for the border is WS_BORDER and for the title bar is WS_CAPTION. The window icon, the small picture located in the left portion of the title bar is referred to as WS_SYSMENU. Double-clicking this icon reveals the window menu (Restore, Move, Size, Minimize, Maximize, Close). In addition, there are three buttons located in the right portion of the title bar. They are
Using Window Styles Constants in Your Program
Window styling changes have long been available in Liberty BASIC using the API calls SendMessageLong. Liberty BASIC v4.x offers the programmer the opportunity to modify these styles using the native command STYLEBITS. Stylebits commands are used to access or change the style and attributes of a window and other controls. There are two categories of styles: standard and extended.
Extended attributes resulted from newer CreateWindwoEX functions so they are more useful in adding qualities rather than removing qualities. Both categories are represented as flags in 32 - bit integers. These styles must be applied to the window and / or controls before the gui is opened.
The stylebits of any particular window and the controls of that window may not be altered after the window is opened except, in some but not all cases, with API calls.
From the Liberty BASIC v4.01 Help File
stylebits #handle, addBits, removeBits, addExtendedBits, removeExtendedBits
STYLEBITS allows you to change the style of a Liberty BASIC window or control. It accepts a handle and four parameters. When the window is opened it checks to see if there are style bits for the window or for any controls. If there is a STYLEBITS command it applies the remove bits first, then applies the add bits. In this way the control is created from the get-go with the desired style. The STYLEBITS command must be issued before the command to open the window.
Most often you can recognize whether a stylebit is standard (dwStyle) or extended (dwExStyle) by its Window Constant. The stylebit WS_CAPTION can be passed as the first (addBits) or second (removeBits) parameter, while the stylebit WS_EX_TOPMOST is passed as either the third (addExtendedBits) or fourth (removeExtendedBits) parameter. Liberty BASIC recognizes window constants by placing an additional underscore immediately in front of the constant, e.g, _WS_CAPTION. Run this demo to see how window attributes can be both added and removed.
It is sometimes desirable to add two or more stylebit parameters. The window constants can be combined using the logical boolean OR conjunction. This next demo first opens a normal window, then opens a second window that
Stylebits, of both dwStyle and dwExStyle, can be assigned to other types of windows and most controls (buttons, textboxes, listboxes, statictext, etc.). Texteditors are not readily modifiable with Stylebits. The helpfile states that since the texteditor is not a native Windows control you will only be able to do things like tweak its border and perhaps a few other things.
A List of Stylebits
You can get a list of all dwStyles and dwExStyles available with the Stylebits command at the MSDN Library.