⁨csanchez⁩ avatar
Carlos

Window9 documentation

FreeBASIC Window9 documentation

public ⁨1⁩ ⁨file⁩ 2025-03-29 00:22:15 UTC

pastefile1

Raw
Window9 Library Documentation

Introduction:
This library is designed to facilitate programming in the FreeBasic language for Windows and Linux systems, providing an alternative to writing directly against pure APIs. Note that not all features are cross-platform; please refer to the descriptions for each feature regarding platform compatibility.

Format Notes:
- Examples using '?' or 'Print' should be compiled as console applications (or run in a terminal on Linux).
- Function parameters are listed with required ones first, followed by optional ones which have default values assigned.
- Some content may be adapted or supplemented from the official FreeBasic documentation for completeness.
- The USTRING type is an alias for STRING in the ASCII library version and for extWstring (dynamic UNICODE string) in the UNICODE version. Examples use STRING; replace with USTRING for UNICODE builds.

Developer Information:
Main Developers:
- Stanislav Budinov (Russia): Author of over 500 functions and this reference guide.
- D.J. Peters (Germany): Introduced professional function design, code quality improvements, bug fixes, and added necessary functions.

Contributors:
- Chris Brown (Zamaster): Added AesDecoder, AesEncoder functions.
- MOD (Germany): Added SHA1create, SHA1CreateFile, SHA512create, SHA512CreateFile, MD5createHash, MD5createFileHash functions.
- Antarman (Russia): Provided the initial foundation and idea with simple functions and an event handler.
- I3I2UI / I0 (Germany): Added SetXProgressBarColor function, testing, tips.
- DEPOzit (Russia): Testing, tips.
- ShadEx (Russia): Optimization of some functions, testing, tips.
- RNBW (United Kingdom): Translation of the current help file version to English.
- FXG861 (Canada), Steini63: Translation of the old help file version to English.
Thanks to all library users.

MODULES OVERVIEW:
2D_DRAW - Functions for drawing 2D primitives (circles, squares, text, images, etc.)
2D_DrawA - Advanced 2D drawing functions with transparency support.
3D (OpenGL) - Functions for creating OpenGL contexts within gadgets.
ClipBoard - Functions for working with the clipboard (text, images, files).
Color - Functions for working with window and gadget colors.
Cipher - Functions for encryption and hashing (AES, Base64, CRC32, MD5, SHA1, SHA512).
Config - Functions for managing configuration data in an INI-like format.
Data Containers - Hashtable, List, Map, Queue, Stack implementations.
Desktop - Functions for working with the desktop (size, color depth, etc.).
Dialog - Dialog boxes (Font, Color, File Save/Open, InputBox, MessageBox, Folder Selection).
Event - Event handling constants and functions (mouse, keyboard, window, gadget, menu events).
File - Functions for basic file operations (create, open, read, write, close).
FileSystem - Functions for managing files and directories (copy, delete, move, examine, etc.).
Font - Functions for loading and managing fonts.
Gadget - UI controls (Buttons, TextFields, Lists, Trees, etc.) and related functions.
Help File - Functions for interacting with CHM help files.
Image - Functions for loading, saving, resizing, and manipulating images (HBITMAP).
ImageA - Functions for loading, saving, resizing, and manipulating GDI+/PixBuf images (supporting transparency).
Internet - Functions for basic Internet operations (HTTP GET, FTP).
Macro - Utility macros (IncludeBinary, SleepW9, UBoundIncBin).
Memory - Functions for memory manipulation (FastCopy, PeekS).
Menu - Functions for creating and managing standard and pop-up menus.
Mouse - Functions for getting mouse cursor position and state.
Movie - Functions for working with video and audio playback (DirectShow based).
Packer - Functions for compressing and decompressing files and memory (ZLIB based).
Preference - Older functions for managing settings files (alternative to Config).
Printer - Functions for printing text, images, and window contents.
Process - Functions related to running programs, managing processes, and command line arguments.
String - Utility functions for string manipulation (ClearString, InsertString, ReplaceString).
Sys Tray - Functions for managing system tray icons.
Toolbar - Functions for creating and managing toolbars.
UTF_ASCII_ENCODING - Functions for converting between ASCII, UTF-8, and Unicode (UTF-16/UTF-32).
Window - Functions for creating, managing, and manipulating windows.

--- SECTION: 2D_DRAW ---

Examples of drawing with transparency:
Example 1:
#Include "window9.bi"
Dim As Integer event
Dim as HWND hwnd
hwnd=OpenWindow("Hello",10,10,320,250) : CenterWindow(hwnd)
Updateinfoxserver() // need for Linux
WindowStartDraw(hwnd,0,0,320,250) // Start drawing
CircleDraw(100,101,100,,255)
CircleDraw(200,101,100,,&hff0000,,,100)
BoxDraw(100,15,100,170,&hffffff,&hffffff,,,100)
FillRectDraw(260,30,&hff0000)
FillRectDraw(5,5,&h00ff00)
StopDraw // finish drawing
Do
event=WindowEvent()
If Event=EventClose Then End
Loop

Example 2:
#Include "window9.bi"
Dim As Integer event
Dim As HWND hwnd
Dim As HBITMAP bmp
hwnd=OpenWindow("Hello",10,10,370,200) : CenterWindow(hwnd)
Var font=LoadFont("Isabella-Decor",72)
bmp=Create_Image(500,200)
ImageStartDraw(bmp) // Start drawing
FillRectDraw(10,10,&hf0f0f0)
FontDraw(font)
TextDraw(22,10,"Hello",-1,&hff00ff)
TextDraw(17,10,"Hello",-1,&hff0000,100)
StopDraw // finish drawing
ImageGadget(1,0,0,500,200,bmp)
Do
event=WindowEvent()
If Event=EventClose Then End
Loop

***
FUNCTION: BoxDraw
Syntax: Function BoxDraw(ByVal x As Long,ByVal y As Long,ByVal w As Long,ByVal h As Long,ByVal ColorPen As Long=0,ByVal ColorBk As Long=0,ByVal widthPen As Long=0,ByVal StylePen As Long=PS_SOLID, ByVal AlPHAPARAM As Long=255) As Integer
Description: Used to draw rectangles.
Options:
x - X-axis location
y - Y-axis location
w - Width of the rectangle
h - Height of the rectangle
ColorPen - Color of the rectangle border
ColorBk - Fill color of the rectangle (if -1, then transparent)
widthPen - Width of the border pen
StylePen - Border style: PS_SOLID, PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT, PS_NULL, PS_INSIDEFRAME (Windows only)
AlPHAPARAM - Degree of transparency (0 to 255)
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var hwnd=OpenWindow("",100,100,300,300)
UpdateInfoXserver()
WindowStartDraw(hwnd)
BoxDraw(40,40,200,200,255,255)
BoxDraw(65,65,150,150,50000,50000)
StopDraw
Do : Loop until WaitEvent= EventClose
Result: Visual output of two rectangles.

***
FUNCTION: CircleDraw
Syntax: Function CircleDraw(ByVal x As Long,ByVal y As Long,ByVal radius As Long,ByVal ColorPen As Long=0,ByVal ColorBk As Long=0,ByVal widthPen As Long=0,ByVal StylePen As Long=PS_SOLID, ByVal AlPHAPARAM As Long=255) As Integer
Description: Used to draw a circle.
Options:
x - X-axis location of the center
y - Y-axis location of the center
radius - Radius of the circle
ColorPen - Color of the circle border
ColorBk - Fill color of the circle (if -1, then transparent)
widthPen - Width of the circle border pen
StylePen - Border style: PS_SOLID, PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT, PS_NULL, PS_INSIDEFRAME (Windows only)
AlPHAPARAM - Degree of transparency (0 to 255)
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var hwnd=OpenWindow("",100,100,250,250)
UpdateInfoXserver()
WindowStartDraw(hwnd)
BoxDraw(0,0,250,250,&hffffff,&hffffff)
CircleDraw(80,140,50,&hFF0000 , &hFF0000 , , , 100)
CircleDraw(160,140,50,&hFF00 , &hFF00 , , , 100)
CircleDraw(120,80,50,&hFF , &hFF , , , 100)
StopDraw
Do : Loop until WaitEvent= EventClose
Result: Visual output of three overlapping transparent circles.

***
SUB: FillRectDraw
Syntax: sub FillRectDraw(ByVal x As Long, ByVal y As Long, ByVal Color As Long)
Description: Fills enclosed areas with the selected color starting from point (x,y). Extends to shape bounds. May be slow on Linux. Use BoxDraw for rectangular areas.
Options:
x - X-coordinate for fill starting point
y - Y-coordinate for fill starting point
Color - Fill Color
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var hwnd=OpenWindow("",100,100,300,300)
UpdateinfoXserver()
WindowStartDraw(hwnd)
FillRectDraw(0,1,&hf0f0f0) // Background
LineDraw(60,180,140,50,10,&hff0000,&hff0000)
LineDraw(140,50,220,180,10,&hff0000,&hff0000)
LineDraw(220,180,60,180,10,&hff0000,&hff0000)
FillRectDraw(150,150,50000) // Fill the triangle
StopDraw
Do : Loop until WaitEvent= EventClose
Result: Visual output of a filled triangle.

***
SUB: FocusDraw
Syntax: sub FocusDraw(ByVal x As Long, ByVal y As Long, ByVal w As Long, ByVal h As Long ,ByVal iColor as Long = 0)
Description: Used to draw a focus rectangle.
Options:
x - X-Axis Location
y - Y-Axis Location
w - Focus width
h - Focus Height
iColor - Focus color (Linux only)
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var hwnd=OpenWindow("",100,100,300,300)
UpdateInfoXserver()
WindowStartDraw(hwnd)
fillrectdraw(40,40,&hffffff) // Draw background for text
TextDraw(100,100,"Hello",&hffffff)
FocusDraw(95,95,45,25) // Draw focus around "Hello"
StopDraw
Do : Loop until WaitEvent= EventClose
Result: Visual output showing text with a focus rectangle around it.

***
SUB: FontDraw
Syntax: Sub FontDraw(ByVal FontID As HFONT)
Description: Sets the font for subsequent text drawing operations.
Options:
FontID - Handle of the font (obtained from LoadFont, FontRequester, etc.)
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var hwnd=OpenWindow("",100,100,300,300)
UpdateInfoXserver()
WindowStartDraw(hwnd,100,100,100,30)
#Ifdef __FB_WIN32__
// On Windows, set the background color of the canvas to be the same
// as that of the window. You don't need to do this on linux.
BoxDraw(0,0,100,30,&hf0f0f0,&hf0f0f0)
#EndIf
FontDraw(LoadFont("arial",22))
TextDraw(0,0,"Hello",-1,255)
StopDraw
Do : Loop until WaitEvent= EventClose
Result: Visual output showing text drawn with the specified font.

***
FUNCTION: GetPix
Syntax: Function GetPix(ByVal x As Long,ByVal y As Long) As Long
Description: Gets the color of a pixel at the specified coordinates in the current drawing area.
Options:
X - X-Axis Location
Y - Y-Axis Location
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var hwnd=OpenWindow("",100,100,300,300)
UpdateInfoXserver()
WindowStartDraw(hwnd)
fillrectdraw(10,10,&h0) // Background
RoundDraw(65,65,150,100,255,50000,20) // Draw an ellipse
TextDraw(120,100,Str(GetPix(120,100)),-1) // Display color at (120,100)
StopDraw
Do : Loop until WaitEvent= EventClose
Result: Visual output showing an ellipse and the color value of a pixel within it.

***
FUNCTION: GradientFillDraw
Syntax: Function GradientFillDraw(ByVal x As Long, ByVal y As Long,ByVal w As Long, ByVal h As Long,ByVal Rbegin As Long,ByVal Gbegin As Long,ByVal Bbegin As Long,ByVal REnd As Long,ByVal GEnd As Long,ByVal BEnd As Long, ByVal GOR_VERT As bool=0)As Integer
Description: Draws a rectangle filled with a gradient. Color values range from 0 to 65535.
Options:
x, y, w, h - Initial coordinates and dimensions of the gradient rectangle
Rbegin, Gbegin, Bbegin - Start color components (Red, Green, Blue) (0-65535)
REnd, GEnd, BEnd - End color components (Red, Green, Blue) (0-65535)
GOR_VERT - Gradient direction: 0 = Horizontal (default), 1 = Vertical
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var hwnd=OpenWindow("",100,100,440,160):CenterWindow(hwnd)
UpdateInfoXserver()
WindowStartDraw(hwnd,,,,,1)
GradientFillDraw(10,10,200,100,&hE7CA,&h4A16,&h63C2,&h489E,&h4727,&hB183,0) // Horizontal
GradientFillDraw(215,10,200,100,&h0,&hC02E,&hE074,&h0,&hFADD,&h3703,1) // Vertical
StopDraw
Do : Loop until WaitEvent= EventClose
Result: Visual output showing two rectangles filled with gradients.

***
SUB: IconDraw
Syntax: Sub IconDraw(ByVal x As Long, ByVal y As Long, ByVal Hicon As HICON)
Description: Draws a loaded icon. Use ImageDraw on Linux.
Options:
x - X-Axis Location
y - Y-Axis Location
Hicon - Icon handle (from Load_Icon, ExtractIcon, LoadImage API, etc.)
Platform: Windows
Example:
#Include "window9.bi"
#Include "win/shellapi.bi"
Var hwnd=OpenWindow("",100,100,300,300)
Dim As HICON icon1,icon2
icon1=ExtractIcon(0,GetSystemDir & "\SetupAPI.dll",22)
icon2=LoadIcon(0,IDI_WINLOGO)
WindowStartDraw(hwnd)
fillrectdraw(40,40,&hffffff) // Background
IconDraw(50,100,icon1)
IconDraw(100,100,icon2)
StopDraw
Do : Loop until WaitEvent= EventClose
Result: Visual output showing two icons drawn on the window.

***
SUB: ImageDraw
Syntax: Sub ImageDraw(ByVal hBmp As HBITMAP,ByVal x As Long, ByVal y As Long, ByVal alphaparam As Long=255)
Description: Draws (overlays) an image (bitmap).
Options:
hBmp - Handle of the bitmap to draw
x, y - Top-left coordinates for drawing the image
alphaparam - Degree of transparency (0 to 255)
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var hwnd=OpenWindow("",100,100,300,300)
UpdateInfoXServer()
WindowStartDraw(hwnd,100,100,100,100,1) // Limit drawing area
ImageDraw(Load_image("E:\WINDOWS\system32\oobe\images\merlin.gif"),0,0) // Assuming path exists
StopDraw
Do : Loop until WaitEvent = EventClose
Result: Visual output showing the loaded image drawn on the window.

***
FUNCTION: ImageStartDraw
Syntax: Function ImageStartDraw(ByVal hBmp As HBITMAP) As HDC
Description: Starts drawing operations on a specific image (bitmap). Must be paired with StopDraw. Returns the device context (HDC) for the image.
Options:
hBmp - Handle of the bitmap (from Load_image, Create_Image, etc.)
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var hbitmap=Create_Image(320,240) // Create an image
ImageStartDraw(hbitmap) // Start drawing on the image
CircleDraw(150,100,50,255,255) // draw a circle
StopDraw // Stop drawing on the image
CenterWindow(OpenWindow("Draw",100,100,320,240)) // create a window
ImageGadget(1,0,0,320,240,hbitmap) // display the image in a gadget
Do : Loop until WaitEvent=EventClose
Result: Visual output showing a window with an image gadget displaying a circle.

***
FUNCTION: LineDraw
Syntax: Function LineDraw(ByVal x As Long,ByVal y As Long,ByVal x1 As Long,ByVal y1 As Long,ByVal width As Long=0,ByVal color As Long=0,ByVal style As Long=PS_SOLID) As Integer
Description: Used to draw a line.
Options:
x - Start X-coordinate
y - Start Y-coordinate
x1 - End X-coordinate
y1 - End Y-coordinate
width - Line width
color - Line color
style - Line style: PS_SOLID, PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT, PS_NULL, PS_INSIDEFRAME (Windows only)
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var hwnd=OpenWindow("",100,100,300,300)
UpdateInfoXserver()
WindowStartDraw(hwnd) // Start drawing
boxdraw(0,0,300,300,0,0) // Background
LineDraw(65,65,200,200,10,&hff0000) // Draw a line
StopDraw // Stop drawing
Do : Loop until WaitEvent= EventClose
Result: Visual output showing a red diagonal line.

***
FUNCTION: PieDraw
Syntax: Function PieDraw(ByVal x As Long,ByVal y As Long,ByVal w As Long,ByVal h As Long,ByVal x1 As Long,ByVal y1 As Long,ByVal x2 As Long,ByVal y2 As Long,ByVal ColorPen As Long=0,ByVal ColorBk As Long=0,ByVal widthPen As Long=0,ByVal StylePen As Long=PS_SOLID) As Integer
Description: Draws a pie-shaped wedge bounded by an ellipse and two radial lines. On Linux, w and h are forced to be equal (using the larger value).
Options:
x, y - Top-left corner of the bounding rectangle
w, h - Width and height of the bounding rectangle
x1, y1 - Endpoint of the first radial line
x2, y2 - Endpoint of the second radial line
ColorPen - Border color
ColorBk - Fill color (if -1, transparent)
widthPen - Border pen width
StylePen - Border style: PS_SOLID, PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT, PS_NULL, PS_INSIDEFRAME (Windows only)
Platform: Windows, Linux
Example: (Animated Pie)
#Include "window9.bi"
Dim Shared As integer event,M,f
Dim Shared As HWND hwnd
function draw_anim() As Integer
WindowStartDraw(hwnd,0,0,200,200)
FillRectDraw(10,10,&hf0f0f0)
PieDraw(10,10,120,120,150,20+M,160,130-M,255,&hff0000,2)
CircleDraw(95,35+M\20,10,&h00ffFF,&h00ff,4)
StopDraw
If f=0 Then M+=3 Else M-=3 EndIf
If M=54 Then f=1 EndIf
If M=0 Then f=0 EndIf
Return TRUE
End Function
hwnd=OpenWindow("",100,100,160,180)
SetTimer(hwnd,1,10,Cast(Any Ptr,@draw_anim))
Do : Loop Until WaitEvent= EventClose
Result: Visual output showing an animated pie wedge.

***
SUB: PixDraw
Syntax: Sub PixDraw(ByVal x As Long,ByVal y As Long,ByVal Color As Long)
Description: Used to draw a single pixel (point).
Options:
x - X-coordinate of the point
y - Y-coordinate of the point
Color - Color of the point
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var hwnd=OpenWindow("",100,100,300,300)
UpdateinfoXserver()
Dim a As Integer
WindowStartDraw(hwnd,0,100,300,1) // Start drawing in a limited area
BoxDraw(0,0,300,1,&hf0f0f0) // Background
For a=1 To 300 Step 3
PixDraw(a,0,255) // draw a dotted line
Next
StopDraw // Stop drawing
Do : Loop until WaitEvent= EventClose
Result: Visual output showing a dotted horizontal line.

***
FUNCTION: PolygonDraw
Syntax: Function PolygonDraw(ByVal pPoint As POINT ptr,ByVal nCount As Long, byval FillColor as Long, ByVal BorderColor As Long=0,ByVal BorderWidth As Long=0,ByVal BorderStyle As Long=PS_SOLID) As Integer
Description: Draws a polygon, automatically connecting the start and end vertices.
Options:
pPoint - Pointer to an array of POINT (or GDKPoint on Linux) structures defining vertices.
nCount - Number of vertices in the array.
FillColor - Polygon fill color.
BorderColor - Polygon border color.
BorderWidth - Border pen width.
BorderStyle - Border style: PS_SOLID, PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT, PS_NULL, PS_INSIDEFRAME (Windows only).
Platform: Windows, Linux
Example:
#Include "window9.bi"
#Ifdef __FB_WIN32__
Type FBPOINT As Point
#Else
Type FBPOINT As GDKPoint
#EndIf
Var hwnd=OpenWindow("",100,100,190,300)
Dim pPoint(4) As FBPOINT = _
{( 85, 50), (150,100), (150,150), ( 20,150), ( 20,100)}
UpdateInfoXserver()
WindowStartDraw(hwnd)
FillRectDraw(0,1,&hf0f0f0) // Background
PolygonDraw(@pPoint(0),5,&hD24EF3)
FillRectDraw(90,130,&hD24EF3) // Fill part of the polygon (example specific)
StopDraw
Do : Loop until WaitEvent= EventClose
Result: Visual output showing a filled polygon.

***
FUNCTION: PolylineDraw
Syntax: Function PolylineDraw(ByVal pPoint As POINT Ptr,ByVal nCount As Long, ByVal ColorPen As Long=0, ByVal widthPen As Long=0, ByVal StylePen As Long=PS_SOLID) As Integer
Description: Draws a series of connected line segments (polyline). Does not automatically close the shape.
Options:
pPoint - Pointer to an array of POINT (or GDKPoint on Linux) structures defining vertices.
nCount - Number of vertices in the array.
ColorPen - Line color.
widthPen - Line width.
StylePen - Line style: PS_SOLID, PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT, PS_NULL, PS_INSIDEFRAME (Windows only).
Platform: Windows, Linux
Example:
#Include "window9.bi"
#Ifdef __FB_WIN32__
Type FBPOINT As Point
#Else
Type FBPOINT As GDKPoint
#EndIf
Var hwnd=OpenWindow("",100,100,190,300)
Dim pPoint(5) As FBPOINT
pPoint(0).x=85 : pPoint(0).y=100
pPoint(1).x=150 : pPoint(1).y=150
pPoint(2).x=150 : pPoint(2).y=200
pPoint(3).x=20 : pPoint(3).y=200
pPoint(4).x=20 : pPoint(4).y=150
pPoint(5).x=85 : pPoint(5).y=100 // Explicitly closing the shape
UpdateInfoXServer()
WindowStartDraw(hwnd) // Start drawing
FillRectDraw(0,1,&hf0f0f0) // Background
PolylineDraw(@pPoint(0),6,&hD24EF3)
FillRectDraw(90,130,&hD24EF3) // Fill part (example specific)
StopDraw // Stop drawing
Do : Loop until WaitEvent= EventClose
Result: Visual output showing a polyline shape.

***
FUNCTION: RoundBoxDraw
Syntax: Function RoundBoxDraw(ByVal x As Long,ByVal y As Long,ByVal w As Long,ByVal h As Long,ByVal ColorPen As Long=0,ByVal ColorBk As Long=0,ByVal widthPen As Long=0,ByVal StylePen As Long=PS_SOLID,ByVal ellipsewidth As Long=0,ByVal ellipseheight As Long=0, ByVal alphaparam As Long=255) As Integer
Description: Draws rectangles with rounded corners.
Options:
x, y - Top-left corner location
w, h - Width and height of the rectangle
ColorPen - Border color
ColorBk - Fill color (if -1, transparent)
widthPen - Border pen width
StylePen - Border style: PS_SOLID, PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT, PS_NULL, PS_INSIDEFRAME (Windows only)
ellipsewidth - Width of the ellipse used for rounding corners
ellipseheight - Height of the ellipse used for rounding corners
alphaparam - Degree of transparency (0 to 255)
Platform: Windows
Example:
#Include "window9.bi"
Var hwnd=OpenWindow("",100,100,300,300)
WindowStartDraw(hwnd) // Start drawing
RoundBoxDraw(65,65,150,150,50000,50000,,,1000,50) // Draw rounded rectangle
StopDraw // Stop drawing
Do : Loop until WaitEvent= EventClose
Result: Visual output showing a rectangle with rounded corners.

***
FUNCTION: RoundDraw
Syntax: Function RoundDraw(ByVal X As Long,ByVal Y As Long,ByVal W As Long,ByVal H As Long,ByVal ColorPen As Long=0,ByVal ColorBk As Long=0,ByVal WidthPen As Long=0,ByVal StylePen As Long=PS_SOLID, ByVal Alphaparam As Long=255) As Integer
Description: Used to draw ellipses and circles.
Options:
X, Y - Top-left corner of the bounding box
W, H - Width and height of the bounding box
ColorPen - Border color
ColorBk - Fill color (if -1, transparent)
WidthPen - Border pen width
StylePen - Border style: PS_SOLID, PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT, PS_NULL, PS_INSIDEFRAME (Windows only)
Alphaparam - Degree of transparency (0 to 255)
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var hwnd=OpenWindow("",100,100,300,300)
UpdateInfoXServer()
WindowStartDraw(hwnd) // Start drawing
BoxDraw(0,0,300,300) // background color
RoundDraw(65,65,150,100,255,&hff0000,20) // draw an ellipse
StopDraw // Stop drawing
Do : Loop until WaitEvent= EventClose
Result: Visual output showing an ellipse.

***
FUNCTION: StopDraw
Syntax: Function StopDraw() As Integer
Description: Finishes drawing operations started with WindowStartDraw or ImageStartDraw and frees related resources.
Options: None
Platform: Windows, Linux
Example: (See ImageStartDraw example)

***
FUNCTION: TextDraw
Syntax: Function TextDraw(ByVal x As Long, ByVal y As Long, ByRef text As string, ByVal ColorBK As Long=0, ByVal ColorText As Long=0, ByVal AlPHAPARAM As Long=255) As Integer
Description: Used to draw text. Text positioning might differ slightly between Windows and Linux.
Options:
x, y - Top-left coordinates for the text
text - The string to draw
ColorBK - Background color (if -1, transparent)
ColorText - Text color
AlPHAPARAM - Text transparency level (0 to 255)
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var hwnd=OpenWindow("",100,100,300,300)
UpdateInfoXserver()
WindowStartDraw(hwnd)
fillrectdraw(40,40,&hffffff) // Background for text
TextDraw(10,10,"Hello",&hffffff) // Draw text with white background
StopDraw
Do : Loop until WaitEvent= EventClose
Result: Visual output showing text drawn on the window.

***
FUNCTION: WindowStartDraw
Syntax: Function WindowStartDraw(ByVal hWin As HWND,ByVal x As Long=0,ByVal y As Long=0,ByVal w As Long=0, ByVal h As Long=0,ByVal Alpha_FLAG As Long=0, ByVal Alpha_VALUE As ULong=0) As HDC
Description: Starts drawing operations on a specific window. Must be paired with StopDraw. Returns the device context (HDC) for the window.
Options:
hWin - Handle of the window to draw on
x, y, w, h - Optional coordinates and dimensions to constrain the drawing area (default is the entire window)
Alpha_FLAG - (Windows only) If 1, enables drawing with a transparent background using Alpha_VALUE as the transparent color. Default is 0 (not transparent).
Alpha_VALUE - (Windows only) The color to be treated as transparent if Alpha_FLAG is 1. Default is 0 (black).
Platform: Windows, Linux
Example: (See BoxDraw example)

--- SECTION: 2D_DrawA ---
Description: 2D_DrawA functions allow drawing higher quality, anti-aliased images with transparency support. These images can be saved in formats like PNG, TIFF, ICO while preserving transparency. Uses GDI+ on Windows and Cairo on Linux.

***
SUB: ArcDrawA
Syntax: Sub ArcDrawA(ByVal x As single,ByVal y As single,ByVal width_ As single,ByVal height_ As single,ByVal startAngle As Single,ByVal sweepAngle As Single,ByVal ColorPen As integer=&hff000000,ByVal brushPen as Any Ptr=0,ByVal widthPen As Single=1)
Description: Draws an arc (a segment of an ellipse).
Options:
x, y, width_, height_ - Location and size of the bounding ellipse.
startAngle - Starting angle in degrees (0 is at 3 o'clock, counter-clockwise).
sweepAngle - Angle extent in degrees (counter-clockwise from startAngle).
ColorPen - Color of the arc line (ARGB format, e.g., &hFFAARRGGBB).
brushPen - Brush for drawing the arc line (from CreateBrushA). Overrides ColorPen if not 0.
widthPen - Width of the arc line.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Any Ptr Gpbitmap=Create_ImageA(250,270)
Dim As Hbitmap bmp
Dim As HWND hw
ImageStartDrawA(Gpbitmap)
ModeDrawA(ANTIALIAS_GOOD)
ArcDrawA(75,50,100,100,40,280,&hFFA000AA,,20) // Draw a thick purple arc
StopDrawA
hw=OpenWindow("GDI+",100,100,250,270)
CenterWindow(hw)
bmp=CreateHBitmapFromGpBitmap(GpBitmap,&hf0f0F0)
imagegadget(1, 0,0,300,300, bmp)
Do:Loop Until WaitEvent()= eventclose
Free_ImageA(Gpbitmap):Free_Image(bmp)
Result: Visual output of an arc.

***
SUB: BezierDrawA
Syntax: Sub BezierDrawA(ByVal x0 As single,ByVal y0 As single,ByVal x1 As single,ByVal y1 As single,ByVal x2 As single,ByVal y2 As single,ByVal x3 As single,ByVal y3 As single,ByVal ColorPen As integer=&hff000000,ByVal brushPen as Any Ptr=0,ByVal widthPen As Single=1)
Description: Draws a Bezier curve using four control points.
Options:
x0, y0 - Start point coordinates.
x1, y1 - First control point coordinates.
x2, y2 - Second control point coordinates.
x3, y3 - End point coordinates.
ColorPen - Color of the Bezier curve line (ARGB).
brushPen - Brush for drawing the Bezier curve (from CreateBrushA). Overrides ColorPen if not 0.
widthPen - Width of the Bezier curve line.
Platform: Windows, Linux
Example 1:
#Include "window9.bi"
Dim As Any Ptr Gpbitmap=Create_ImageA(260,270)
Dim As Hbitmap bmp
Dim As HWND hw
Dim As Any ptr brush
brush=CreateBrushA(1,1,120,90,&h80000000,&hF0FFF0f0) // Gradient brush
ImageStartDrawA(Gpbitmap,1,&hffff0000) // Red background fill
ModeDrawA(ANTIALIAS_GOOD)
BezierDrawA(127,60,-56,60,254,210,74,200,&hFF0FFFF0,,10) // Yellow Bezier
BezierDrawA(127,60,300,60,0,210,180,200,,brush,10) // Bezier with gradient brush
StopDrawA
hw=OpenWindow("GDI+",100,100,260,270)
CenterWindow(hw)
bmp=CreateHBitmapFromGpBitmap(GpBitmap,&hf0f0F0)
imagegadget(1, 0,0,300,300, bmp)
Do:Loop Until WaitEvent()= eventclose
FreeBrushA(brush):Free_ImageA(Gpbitmap):Free_Image(bmp)
Result: Visual output of two Bezier curves.

***
SUB: BoxDrawA
Syntax: Sub BoxDrawA(ByVal x As single,ByVal y As single,ByVal width As single,ByVal height As single,ByVal ColorPen As integer=&hff000000,ByVal flagcolorBK As Integer=1,ByVal ColorBk As integer=&hff000000,byval brushPen as Any Ptr=0,byval brushBk as Any Ptr=0,ByVal widthPen As Single=1)
Description: Draws rectangles with enhanced options (brushes, anti-aliasing).
Options:
x, y, width, height - Location and dimensions.
ColorPen - Color of the rectangle border (ARGB).
flagcolorBK - Fill mode: 0=No Fill, 1=Fill with ColorBk, 2=Fill with brushBk.
ColorBk - Fill color of the rectangle (ARGB). Used if flagcolorBK is 1.
brushPen - Brush for the border (from CreateBrushA). Overrides ColorPen if not 0.
brushBk - Brush for the fill (from CreateBrushA). Used if flagcolorBK is 2.
widthPen - Width of the rectangle border.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Any Ptr Gpbitmap=Create_ImageA(250,270)
Dim As Hbitmap bmp
Dim As HWND hw
Dim As Any ptr brush,brush1
brush=CreateBrushA(1,1,120,90,&hFF000ff0,&hFFFFF0f0) // Gradient brush 1
brush1=CreateBrushA(1,1,120,120,&hFFF000F0,&hFF00f0F0) // Gradient brush 2
ImageStartDrawA(Gpbitmap)
BoxDrawA(10,10,100,100,&hFF0000FF,0) // Blue border, no fill
BoxDrawA(125,10,100,100,&hFFFF0000,,&HFF0000FF,,,5) // Red border (5px), blue fill
BoxDrawA(10,125,100,100,&hFF00FF00,0,,brush,,10) // No fill, border uses brush1 (10px)
BoxDrawA(125,125,100,100,,2,,brush,brush1,10) // Border uses brush1, fill uses brush2 (10px border)
StopDrawA
hw=OpenWindow("GDI+",100,100,250,270)
CenterWindow(hw)
bmp=CreateHBitmapFromGpBitmap(GpBitmap,&hf0f0F0)
ImageGadget(1, 0,0,300,300, bmp)
Do:Loop Until WaitEvent()= eventclose
FreeBrushA(brush):FreeBrushA(brush1)
Free_ImageA(Gpbitmap):Free_Image(bmp)
Result: Visual output of four rectangles with different styles.

***
SUB: CircleDrawA
Syntax: Sub CircleDrawA(ByVal x As single,ByVal y As single,ByVal Radius As single,ByVal ColorPen As integer=&hff000000,ByVal flagcolorBK As Integer=1,ByVal ColorBk As integer=&hff000000,ByVal brushPen as Any Ptr=0,byval brushBk as Any Ptr=0,ByVal widthPen As Single=1)
Description: Draws circles with enhanced options.
Options:
x, y - Location of the center of the circle.
Radius - Radius of the circle.
ColorPen - Color of the circle border (ARGB).
flagcolorBK - Fill mode: 0=No Fill, 1=Fill with ColorBk, 2=Fill with brushBk.
ColorBk - Circle fill color (ARGB). Used if flagcolorBK is 1.
brushPen - Brush for the border (from CreateBrushA). Overrides ColorPen if not 0.
brushBk - Brush for the fill (from CreateBrushA). Used if flagcolorBK is 2.
widthPen - Width of the circle border.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Any Ptr Gpbitmap=Create_ImageA(250,270)
Dim As Hbitmap bmp
Dim As HWND hw
ImageStartDrawA(Gpbitmap)
ModeDrawA(ANTIALIAS_GOOD)
CircleDrawA(80,140,50,0,,&h800000FF) // Transparent blue circle (alpha = 80)
CircleDrawA(160,140,50,0,,&H80FF0000) // Transparent red circle
CircleDrawA(120,80,50,0,,&H8000FF00) // Transparent green circle
StopDrawA
hw=OpenWindow("GDI+",100,100,250,270)
CenterWindow(hw)
bmp=CreateHBitmapFromGpBitmap(GpBitmap,&hf0f0F0)
ImageGadget(1, 0,0,300,300, bmp)
Do:Loop Until WaitEvent()= eventclose
Free_ImageA(Gpbitmap):Free_Image(bmp)
Result: Visual output of three overlapping transparent circles.

***
FUNCTION: CreateBrushA
Syntax: Function CreateBrushA(ByVal x0 As Single=0,ByVal y0 As Single=0,ByVal x1 As Single=0,ByVal y1 As Single=0, ByVal color1 As Integer=&hFF00FF00, ByVal color2 As Integer=&hFF0000FF,ByVal GpImage As Any ptr=0,ByVal WrapMode As Integer=3 ) As Any Ptr
Description: Creates a brush for GDI+/Cairo drawing. Can be a gradient brush or a texture brush (from an image). Returns a brush handle.
Options:
x0, y0 - Start coordinates for gradient (used if GpImage = 0).
x1, y1 - End coordinates for gradient (used if GpImage = 0).
color1, color2 - Start and end colors for gradient (ARGB, used if GpImage = 0).
GpImage - Bitmap handle (GDI+/PixBuf) for texture brush. If non-zero, gradient parameters are ignored.
WrapMode - Tiling mode for texture brush: WrapModeTile (0), WrapModeTileFlipX (1), WrapModeTileFlipY (2), WrapModeTileFlipXY (3, default), WrapModeClamp (4).
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Any Ptr Gpbitmap=Create_ImageA(300,170),GpCopy
Dim As Hbitmap bmp
Dim As HWND hw
Dim As Any ptr brush,brush1
brush=CreateBrushA(1,1,120,90,&hFF0F0ff0,&hFF00Ff0F) // Gradient brush
ImageStartDrawA(Gpbitmap)
ModeDrawA(ANTIALIAS_GOOD)
RoundDrawA(125,50,50,50,&hFF00FF00,0,,brush,,10) // Ellipse border with gradient
GpCopy=grab_ImageA(Gpbitmap,125,50,50,50) // Grab part of the image
brush1=CreateBrushA(,,,,,,GpCopy) // Texture brush from grabbed part (default WrapModeTileFlipXY)
RoundDrawA(25,25,100,100,&h00000000,2,,,brush1) // Fill ellipse with texture brush 1
FreeBrushA(brush1)
brush1=CreateBrushA(,,,,,,GpCopy,2) // Texture brush with WrapModeTileFlipY
RoundDrawA(175,25,100,100,&h00000000,2,,,brush1) // Fill ellipse with texture brush 2
StopDrawA
hw=OpenWindow("GDI+",100,100,310,170)
CenterWindow(hw)
bmp=CreateHBitmapFromGpBitmap(GpBitmap,&hf0f0F0)
ImageGadget(1, 0,0,300,300, bmp)
Do:Loop Until WaitEvent()= eventclose
FreeBrushA(brush):FreeBrushA(brush1)
Free_ImageA(Gpbitmap):Free_ImageA(GpCopy)
Result: Visual output demonstrating gradient and texture brushes.

***
FUNCTION: CreateFontDrawA
Syntax: Function CreateFontDrawA(ByVal name As String="Arial",ByVal size As Integer=10,ByVal style As Integer=0,ByVal unit As Integer=6) As Any Ptr
Description: Creates a font handle for use with TextDrawA.
Options:
name - Font name (e.g., "Arial", "Times New Roman").
size - Font size.
style - Font style: FontStyleRegular (0), FontStyleBold (1), FontStyleItalic (2), FontStyleBoldItalic (3), FontStyleUnderline (4, Win only), FontStyleStrikeout (8, Win only). Combine with OR.
unit - Unit for the size parameter: UnitWorld (0, Win only), UnitDisplay (1, avoid), UnitPixel (2), UnitPoint (3), UnitInch (4), UnitDocument (5), UnitMillimeter (6, default).
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Any Ptr Gpbitmap=Create_ImageA(300,270)
Dim As Hbitmap bmp
Dim As HWND hw
Dim As Any ptr font=CreateFontDrawA("Courier",36,3) // Bold Italic
ImageStartDrawA(Gpbitmap)
TextDrawA("ABC",0,10,font,&h80FF0000,,ANTIALIAS_GOOD) // Draw transparent red text
StopDrawA
hw=OpenWindow("GDI+",100,100,320,270)
CenterWindow(hw)
bmp=CreateHBitmapFromGpBitmap(GpBitmap,&hf0f0F0)
ImageGadget(1, 0,0,300,300, bmp)
Do:Loop Until WaitEvent()= eventclose
Free_ImageA(Gpbitmap):Free_Image(bmp)
FreeFontDrawA(font)
Result: Visual output showing text drawn with the created font.

***
SUB: CurveDrawA
Syntax: Sub CurveDrawA(ByVal Points As Any ptr,ByVal countPoints As Integer,ByVal RoundPoints As Single=0.5,ByVal ColorPen As integer=&hff000000,ByVal flagcolorBK As Integer=1,ByVal ColorBk As integer=&hff000000,ByVal brushPen as Any Ptr=0,byval brushBk as Any Ptr=0,ByVal widthPen As Single=1,ByVal Closed As Integer=0,ByVal fillmode As Integer=0)
Description: Draws a cardinal spline through a series of points.
Options:
Points - Pointer to an array of PointF structures.
countPoints - Number of points in the array.
RoundPoints - Tension factor for the curve (0.0 to 1.0). Default 0.5.
ColorPen - Color of the curve line (ARGB).
flagcolorBK - Fill mode: 0=No Fill, 1=Fill with ColorBk, 2=Fill with brushBk.
ColorBk - Fill color (ARGB). Used if flagcolorBK is 1.
brushPen - Brush for the curve line (from CreateBrushA). Overrides ColorPen if not 0.
brushBk - Brush for the fill (from CreateBrushA). Used if flagcolorBK is 2.
widthPen - Width of the curve line.
Closed - 0 = Open curve, 1 = Closed curve (connects last and first points).
fillmode - Fill mode for closed curves (Windows only): FillModeAlternate (0), FillModeWinding (1).
Platform: Windows (Linux support might be limited, especially fillmode)
Example:
#Include "window9.bi"
Dim As Any Ptr Gpbitmap=Create_ImageA(750,270)
Dim As Hbitmap bmp
Dim As HWND hw
Dim As PointF Points(4)
Dim As Single dAngle
For u As single=0.5 To 1.5 Step 1.0 // Draw two curves: one closed, one open
for i As Integer=0 to 4
dAngle = (i * 0.8 - 0.5) * 3.1415926535
points(i).x=(200 *(u + 0.48 * Cos(dAngle)))
points(i).y=(200 *(0.50 + 0.48 * Sin(dAngle)))
Next
ImageStartDrawA(Gpbitmap)
ModeDrawA(4) // AntiAlias Best
CurveDrawA(@Points(0),5,0.5,&hff0000ff,1,&hFF0000FF,,,,Int(u),0) // Draw curve
StopDrawA
Next
hw=OpenWindow("GDI+",100,100,420,230)
CenterWindow(hw)
bmp=CreateHBitmapFromGpBitmap(GpBitmap,&hf0f0F0)
WindowBackgroundImage(hw,Bmp) // Set as window background
Do:Loop Until WaitEvent()= eventclose
Free_ImageA(Gpbitmap):Free_Image(bmp)
Result: Visual output showing cardinal splines.

***
SUB: FillRectDrawA
Syntax: Sub FillRectDrawA(byval x As Integer, byval y As Integer, byval color As integer)
Description: Fills enclosed areas with the selected color starting from point (x,y). Extends to shape borders. Function is slow; consider custom algorithms for performance-critical fill operations. Color is ARGB.
Options:
x - X coordinate for fill starting point.
y - Y coordinate for fill starting point.
color - Fill color (ARGB).
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Any Ptr Gpbitmap=Create_ImageA(190,170)
Dim As Hbitmap bmp
Dim As HWND hw
ImageStartDrawA(Gpbitmap)
LineDrawA(50,50,100,100,,&HFFFF0000) // Draw triangle border
LineDrawA(100,100,150,50,,&HFFFF0000)
LineDrawA(50,50,150,50,,&HFFFF0000)
FillRectDrawA(80,60,&hff0000ff) // Fill inside triangle (blue)
FillRectDrawA(10,10,&hFF00FF00) // Fill outside (green)
StopDrawA
hw=OpenWindow("GDI+",100,100,200,180)
CenterWindow(hw)
bmp=CreateHBitmapFromGpBitmap(GpBitmap,&hf0f0F0)
ImageGadget(1, 0,0,300,300, bmp)
Do:Loop Until WaitEvent()= eventclose
Free_ImageA(Gpbitmap):Free_Image(bmp)
Result: Visual output showing a filled triangle.

***
SUB: FreeBrushA
Syntax: Sub FreeBrushA(ByVal Brush As Any Ptr)
Description: Releases resources used by a brush created with CreateBrushA.
Options:
Brush - Handle of the brush to free.
Platform: Windows, Linux
Example: (See CreateBrushA or BoxDrawA examples)

***
SUB: FreeFontDrawA
Syntax: Sub FreeFontDrawA(ByVal GpFont As Any Ptr)
Description: Releases resources used by a font created with CreateFontDrawA.
Options:
GpFont - Handle of the font to free.
Platform: Windows, Linux
Example: (See CreateFontDrawA example)

***
FUNCTION: GetPixA
Syntax: Function GetPixA(ByVal X As single,ByVal Y As Single) As Integer
Description: Gets the ARGB color value of a pixel from a GDI+/PixBuf bitmap at the specified coordinates.
Options:
X, Y - Pixel coordinates.
Platform: Windows, Linux
Example: (See SetPixA example)

***
SUB: ImageDrawA
Syntax: Sub ImageDrawA(ByVal GpImage As Any Ptr,ByVal x As single, ByVal y As single,ByVal w As Single=0, ByVal h As Single=0)
Description: Draws an image (GDI+/PixBuf bitmap) onto the current drawing surface, optionally resizing it. Preserves transparency.
Options:
GpImage - Handle of the image to draw.
x, y - Top-left coordinates for drawing the image.
w, h - Desired width and height. If 0, the original image dimensions are used.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Any Ptr Gpbitmap=Create_ImageA(250,270)
Dim As Hbitmap bmp
Dim As HWND hw
ImageStartDrawA(Gpbitmap)
ModedrawA(ANTIALIAS_GOOD)
LineDrawA(185,30,100,100,7,&Hf807f000) // Draw some lines first
LineDrawA(105,30,200,100,7,&Hf807f000)
ImageDrawA(Gpbitmap,10,10,100,100) // Draw the image itself, resized
ImageDrawA(Gpbitmap,100,100,100,100) // Draw it again, resized, offset
StopDrawA
hw=OpenWindow("GDI+",100,100,250,270)
CenterWindow(hw)
bmp=CreateHBitmapFromGpBitmap(GpBitmap,&hf0f0F0)
imagegadget(1, 0,0,300,300, bmp)
Do:Loop Until WaitEvent()= eventclose
Free_ImageA(Gpbitmap):Free_Image(bmp)
Result: Visual output showing lines and resized copies of the image drawn onto itself.

***
FUNCTION: ImageStartDrawA
Syntax: Function ImageStartDrawA(ByRef bitmapGP As Any Ptr,ByVal ColorFlag As Integer=0,ByVal Color As Integer=&hFFFFFFFF) As Any Ptr
Description: Starts drawing operations on a specific GDI+/PixBuf bitmap. Must be paired with StopDrawA. Returns a pointer to the graphics context (GDI+ Graphics on Windows, Cairo context on Linux).
Options:
bitmapGP - Handle of the GDI+/PixBuf bitmap to draw on (from Create_ImageA, Load_ImageA, etc.).
ColorFlag - If 1, the bitmap surface will be filled with the specified Color before drawing starts.
Color - The ARGB fill color to use if ColorFlag is 1.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Any Ptr Gpbitmap=Create_ImageA(200,200)
Dim As Hbitmap bmp
Dim As HWND hw
#define Rndcolor BGR(Int(Rnd*255),Int(Rnd*255),Int(Rnd*255))Or &hA0000000 // Random semi-transparent color
ImageStartDrawA(Gpbitmap)
ModeDrawA(ANTIALIAS_GOOD)
For a As Integer=1 To 40
CircleDrawA(Rnd*200,Rnd*200,30,Rndcolor,,Rndcolor,,,3) // Draw random circles
Next
StopDrawA
hw=OpenWindow("GDI+",100,100,200,200)
CenterWindow(hw)
bmp=CreateHBitmapFromGpBitmap(GpBitmap,&hf0f0f0)
ImageGadget(1, 0,0,300,300, bmp)
Do:Loop Until WaitEvent()= eventclose
Free_ImageA(Gpbitmap):Free_Image(bmp)
Result: Visual output showing a collection of randomly placed transparent circles.

***
SUB: LineDrawA
Syntax: Sub LineDrawA(ByVal x As single,ByVal y As single,ByVal x1 As single,ByVal y1 As single,ByVal width As Single=1,ByVal color As Integer=&hff000000,byval brushPen as Any Ptr=0)
Description: Draws an anti-aliased line.
Options:
x, y - Start coordinates.
x1, y1 - End coordinates.
width - Line width.
color - Line color (ARGB). Ignored if brushPen is used.
brushPen - Brush for drawing the line (from CreateBrushA).
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Any Ptr Gpbitmap=Create_ImageA(160,160)
Dim As Hbitmap bmp
Dim As HWND hw
Dim As Any ptr brush
brush=CreateBrushA(1,1,140,10,&h8000f0f0,&h80FF00f0) // Semi-transparent gradient brush
ImageStartDrawA(Gpbitmap)
ModeDrawA(ANTIALIAS_GOOD)
LineDrawA(10,10,150,150,10,&HFF0000FF) // Solid blue line
LineDrawA(10,150,150,10,10,,brush) // Line drawn with gradient brush
StopDrawA
hw=OpenWindow("GDI+",100,100,180,200)
CenterWindow(hw)
bmp=CreateHBitmapFromGpBitmap(GpBitmap,&hf0F0fF) // Note: Background color typo? Should be &hf0f0f0?
ImageGadget(1, 0,0,200,200, bmp)
Do:Loop Until WaitEvent()= eventclose
FreeBrushA(brush)
Free_ImageA(Gpbitmap):Free_Image(bmp)
Result: Visual output of two diagonal lines, one solid, one gradient.

***
SUB: ModeDrawA
Syntax: Sub ModeDrawA(ByVal mode As Integer)
Description: Sets the anti-aliasing mode for subsequent drawing operations.
Options:
mode - Anti-aliasing mode: ANTIALIAS_NONE, ANTIALIAS_FAST, ANTIALIAS_GOOD, ANTIALIAS_BEST.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Any Ptr Gpbitmap=Create_ImageA(250,270)
Dim As Hbitmap bmp
Dim As HWND hw
ImageStartDrawA(Gpbitmap)
ModeDrawA(ANTIALIAS_BEST)
lineDrawA(15,30,100,100,7) // Line with best anti-aliasing
ModeDrawA(ANTIALIAS_NONE)
LineDrawA(185,30,100,100,7) // Line with no anti-aliasing
StopDrawA
hw=OpenWindow("GDI+",100,100,250,270)
CenterWindow(hw)
bmp=CreateHBitmapFromGpBitmap(GpBitmap,&hf0f0F0)
ImageGadget(1, 0,0,300,300, bmp)
Do:Loop Until WaitEvent()= eventclose
Free_ImageA(Gpbitmap):Free_Image(bmp)
Result: Visual output comparing an anti-aliased line with a non-anti-aliased line.

***
SUB: PieDrawA
Syntax: Sub PieDrawA(ByVal x As single,ByVal y As single,ByVal width As single,ByVal height As single,ByVal startAngle As Single,ByVal sweepAngle As Single,ByVal ColorPen As integer=&hff000000,ByVal flagcolorBK As Integer=1,ByVal ColorBk As integer=&hff000000,ByVal brushPen as Any Ptr=0,byval brushBk as Any Ptr=0,ByVal widthPen As Single=1)
Description: Draws a filled pie-shaped wedge.
Options:
x, y, width, height - Location and size of the bounding ellipse.
startAngle - Starting angle in degrees (0 is at 3 o'clock, counter-clockwise).
sweepAngle - Angle extent in degrees (counter-clockwise from startAngle).
ColorPen - Color of the pie border (ARGB).
flagcolorBK - Fill mode: 0=No Fill, 1=Fill with ColorBk, 2=Fill with brushBk.
ColorBk - Fill color (ARGB). Used if flagcolorBK is 1.
brushPen - Brush for the border (from CreateBrushA). Overrides ColorPen if not 0.
brushBk - Brush for the fill (from CreateBrushA). Used if flagcolorBK is 2.
widthPen - Width of the pie border.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Any Ptr Gpbitmap=Create_ImageA(250,270)
Dim As Hbitmap bmp
Dim As HWND hw
ImageStartDrawA(Gpbitmap)
ModeDrawA(ANTIALIAS_GOOD)
PieDrawA(75,50,100,100,40,280,&hFFA000AA,1,&hFFA000AA) // Draw a solid purple pie wedge
StopDrawA
hw=OpenWindow("GDI+",100,100,250,270)
CenterWindow(hw)
bmp=CreateHBitmapFromGpBitmap(GpBitmap,&hf0f0F0)
ImageGadget(1, 0,0,300,300, bmp)
Do:Loop Until WaitEvent()= eventclose
Free_ImageA(Gpbitmap):Free_Image(bmp)
Result: Visual output of a pie wedge.

***
SUB: PolygonDrawA
Syntax: Sub PolygonDrawA(ByVal Points As Any ptr,ByVal countPoints As Integer,ByVal ColorPen As integer=&hff000000,ByVal flagcolorBK As Integer=1,ByVal ColorBk As integer=&hff000000,ByVal brushPen as Any Ptr=0,byval brushBk as Any Ptr=0,ByVal widthPen As Single=1,ByVal fillmode As Integer=0)
Description: Draws a filled polygon, automatically connecting the start and end vertices.
Options:
Points - Pointer to an array of PointF structures defining vertices.
countPoints - Number of vertices in the array.
ColorPen - Polygon border color (ARGB).
flagcolorBK - Fill mode: 0=No Fill, 1=Fill with ColorBk, 2=Fill with brushBk.
ColorBk - Polygon fill color (ARGB). Used if flagcolorBK is 1.
brushPen - Brush for the border (from CreateBrushA). Overrides ColorPen if not 0.
brushBk - Brush for the fill (from CreateBrushA). Used if flagcolorBK is 2.
widthPen - Width of the polygon border.
fillmode - Fill mode for complex polygons (Windows only, ignored on Linux): FillModeAlternate (0), FillModeWinding (1).
Platform: Windows, Linux
Example: (Demonstrates fill modes)
#Include "window9.bi"
Dim As Any Ptr Gpbitmap=Create_ImageA(500,270)
Dim As Hbitmap bmp
Dim As HWND hw
#ifdef __FB_WIN32__
Dim As PointF Points(4)
#else
Dim As GDKPoint Points(4) // Use GDKPoint for Linux compatibility if needed
#endif
Dim As Single dAngle
For u As single=0.5 To 1.5 Step 1.0 // Draw two overlapping star shapes
for i As Integer=0 to 4
dAngle = (i * 0.8 - 0.5) * 3.1415926535
points(i).x=(200 *(u + 0.48 * Cos(dAngle)))
points(i).y=(200 *(0.50 + 0.48 * Sin(dAngle)))
Next
ImageStartDrawA(Gpbitmap)
PolygonDrawA(@Points(0),5,0,1,&hFF00FF00,,,20,Int(u)) // Draw polygon with fillMode Alternate/Winding
StopDrawA
Next
hw=OpenWindow("GDI+",100,100,420,230)
CenterWindow(hw)
bmp=CreateHBitmapFromGpBitmap(GpBitmap,&hf0f0F0)
ImageGadget(1, 0,0,420,230, bmp)
Do:Loop Until WaitEvent()= eventclose
Free_ImageA(Gpbitmap):Free_Image(bmp)
Result: Visual output showing complex polygons filled using different modes.

***
SUB: RoundDrawA
Syntax: Sub RoundDrawA(ByVal X As single,ByVal Y As single,ByVal W As single,ByVal H As single,ByVal ColorPen As integer=&hff000000,ByVal flagcolorBK As Integer=1,ByVal ColorBk As integer=&hff000000,ByVal brushPen as Any Ptr=0,byval brushBk as Any Ptr=0,ByVal widthPen As Single=1)
Description: Draws ellipses with enhanced options.
Options:
X, Y, W, H - Location and dimensions of the bounding box.
ColorPen - Ellipse border color (ARGB).
flagcolorBK - Fill mode: 0=No Fill, 1=Fill with ColorBk, 2=Fill with brushBk.
ColorBk - Ellipse fill color (ARGB). Used if flagcolorBK is 1.
brushPen - Brush for the border (from CreateBrushA). Overrides ColorPen if not 0.
brushBk - Brush for the fill (from CreateBrushA). Used if flagcolorBK is 2.
widthPen - Width of the ellipse border.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Any Ptr Gpbitmap=Create_ImageA(250,270)
Dim As Hbitmap bmp
Dim As HWND hw
Dim As Any ptr brush,brush1
brush=CreateBrushA(1,1,120,90,&hFF000ff0,&hFFFFF0f0) // Gradient brush 1
brush1=CreateBrushA(1,1,120,120,&hFFF000F0,&hFF00f0F0) // Gradient brush 2
ImageStartDrawA(Gpbitmap)
ModeDrawA(ANTIALIAS_GOOD)
RoundDrawA(10,10,100,80,&hFF0000FF,0) // Blue border, no fill
RoundDrawA(125,10,80,100,&hFFFF0000,,&HFF0000FF,,,5) // Red border (5px), blue fill
RoundDrawA(10,105,100,120,&hFF00FF00,0,,brush,,10) // No fill, border uses brush1 (10px)
RoundDrawA(125,125,100,100,,2,,brush,brush1,10) // Border uses brush1, fill uses brush2 (10px border)
StopDrawA
hw=OpenWindow("GDI+",100,100,250,270)
CenterWindow(hw)
bmp=CreateHBitmapFromGpBitmap(GpBitmap,&hf0f0F0)
ImageGadget(1, 0,0,300,300, bmp)
Do:Loop Until WaitEvent()= eventclose
FreeBrushA(brush):FreeBrushA(brush1)
Free_ImageA(Gpbitmap):Free_Image(bmp)
Result: Visual output of four ellipses with different styles.

***
SUB: SetPixA
Syntax: Sub SetPixA(ByVal X As single,ByVal Y As Single,ByVal Color As integer=&hff000000)
Description: Sets the ARGB color of a single pixel in a GDI+/PixBuf bitmap.
Options:
X, Y - Pixel coordinates.
Color - ARGB color value.
Platform: Windows, Linux
Example: (Create transparent bitmap from opaque one)
#Include "window9.bi"
Var HBitmap=Create_Image(300,300) // create a regular bitmap
ImageStartDraw(HBitmap) // start drawing
TextDraw(30,50,"FreeBasic The Best",,&hff) // Draw opaque text
StopDraw // stop drawing
Var MainGpBitmap=Create_ImageA(300,300) // create a transparent bitmap
Var GpBitmap=CreateGpBitmapFromHBitmap(HBitmap) // create GDI+ bitmap from Hbitmap
ImageStartDrawA(MainGpBitmap) // start drawing with GDI+
ImageDrawA(GpBitmap,0,0) // draw our opaque bitmap onto the transparent one
For y As Integer=0 To 299 // Iterate through pixels (adjust loop bounds)
For x As Integer=0 To 299
If GetPixA(x,y)=&hff000000 Then // If pixel is opaque black
SetPixA(x,y,&h00000000) // Make it fully transparent
EndIf
Next
Next
StopDrawA // stop drawing
Save_image(HBitmap,"1.png") // save the original opaque bitmap
Save_imageA(MainGpBitmap,"2.png") // save the new transparent bitmap
Free_ImageA(GpBitmap):Free_Image(hbitmap):Free_ImageA(MainGpBitmap)
Result: Creates two PNG files, one opaque, one with transparency where black pixels were.

***
SUB: StopDrawA
Syntax: Sub StopDrawA()
Description: Finishes drawing operations started with ImageStartDrawA or WindowStartDrawA and frees related GDI+/Cairo resources.
Options: None
Platform: Windows, Linux
Example: (See ImageStartDrawA example)

***
SUB: TextDrawA
Syntax: Sub TextDrawA(ByRef text As String,ByVal x As Integer, ByVal y As Integer, ByVal GpFont As Any Ptr=0, ByVal color As Integer=&hFFFFFFFF,ByVal brush As Any Ptr=0,ByVal mode As Integer=0)
Description: Draws anti-aliased text. Positioning might differ slightly between Windows (GDI+) and Linux (Pango Cairo).
Options:
text - The string to draw.
x, y - Top-left coordinates for the text.
GpFont - Font handle (from CreateFontDrawA). Default is Arial 12 (Win) / Sans 12 (Lin).
color - Text color (ARGB). Ignored if brush is used.
brush - Brush for filling the text (from CreateBrushA).
mode - Text rendering hint (Windows only): TextRenderingHintSystemDefault (0), TextRenderingHintSingleBitPerPixelGridFit (1), TextRenderingHintSingleBitPerPixel (2), TextRenderingHintAntiAliasGridFit (3), TextRenderingHintAntiAlias (4), TextRenderingHintClearTypeGridFit (5). Ignored on Linux (always anti-aliased).
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Any Ptr Gpbitmap=Create_ImageA(250,270)
Dim As Hbitmap bmp
Dim As HWND hw
ImageStartDrawA(Gpbitmap)
ModeDrawA(ANTIALIAS_GOOD)
TextDrawA("FreeBasic",10,100,,&h8000FF00,,4) // Draw semi-transparent green text
CircleDrawA(125,125,50,&h700000FF,,&h700000FF) // Draw overlapping circle
StopDrawA
hw=OpenWindow("GDI+",100,100,250,270)
CenterWindow(hw)
bmp=CreateHBitmapFromGpBitmap(GpBitmap,&hf0f0F0)
ImageGadget(1, 0,0,300,300, bmp)
Do:Loop Until WaitEvent()= eventclose
Free_ImageA(Gpbitmap):Free_Image(bmp)
Result: Visual output showing anti-aliased text potentially overlapping a circle.

***
FUNCTION: WindowStartDrawA
Syntax: Function WindowStartDrawA(ByVal hWin As HWND,ByVal x As Integer=0,ByVal y As Integer=0,ByVal w As Integer=0, ByVal h As Integer=0,ByVal ColorFlag As Integer=0,ByVal Color As Integer=&hFFFFFFFF) As Any Ptr
Description: Starts GDI+/Cairo drawing operations directly on a window. Must be paired with StopDrawA. Returns a pointer to the graphics context.
Options:
hWin - Handle of the window to draw on.
x, y, w, h - Optional coordinates and dimensions to constrain the drawing area (default is the entire window).
ColorFlag - If 1, the drawing area will be filled with the specified Color before drawing starts.
Color - The ARGB fill color to use if ColorFlag is 1.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As HWND hwnd
hwnd = OpenWindow("",100,100,200,200)
Do
WindowStartDrawA(hwnd) // Start drawing on window
For i As Integer = 0 To 1000
SetPixA(Rnd*200,Rnd*200,&hFF000000) // Draw random black pixels
Next
BoxDrawA(20,20,140,120,&h8fFFFF00,,&h8fFFFF00) // Draw a semi-transparent yellow box
StopDrawA // Stop drawing
Sleep(1) // Prevent high CPU usage
Loop Until WindowEvent = eventclose
Result: Visual output showing random pixels and a box drawn directly on the window.

--- SECTION: 3D (OpenGL) ---

***
FUNCTION: OpenGLGadget
Syntax: function OpenGLGadget(ByVal gadget As Long, ByVal x As Long, ByVal y As Long, ByVal w As Long, ByVal h As Long, ByVal cBits As Long = 32, byval dBits as Long = 24, byval sBits as Long = 0, byval aBits as Long = 0) As HWND
Description: Creates a gadget area for OpenGL rendering.
Options:
gadget - Gadget ID number.
x, y, w, h - Location and size of the gadget.
cBits - Number of bitplanes in the color buffer (default 32).
dBits - Size of the depth buffer (default 24).
sBits - Size of the stencil buffer (default 0).
aBits - Size of the accumulation buffer (default 0).
Platform: Windows, Linux
Example 1: (Simple Triangle)
#Include "window9.bi"
#include "GL/gl.bi" // Need to include OpenGL headers
Sub SceneDraw()
glClearColor(0.7,0.7,0.6,1)
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
glTranslatef( 50,50,0 ) // Note: This likely requires glMatrixMode/glLoadIdentity setup first
glBegin( GL_TRIANGLES )
glColor3ub( 255,0,0 ) : glVertex2i( 0, 50 )
glColor3ub( 0,255,0 ) : glVertex2i( 100, 50 )
glColor3ub( 0,0,255 ) : glVertex2i( 50, 0 )
glEnd()
glLoadIdentity() // Reset transformations
OpenGLGadgetSwapBuffers(1)
End Sub
var win = OpenWindow("OpenGL Gadget",100,100,230,250)
OpenGLGadget(1,5,5,200,200,,0) // Create gadget with color buffer only
Do
var event = WindowEvent()
If event = eventclose Then Exit Do
SceneDraw()
sleep(1)
Loop
Result: Visual output of a colored triangle in an OpenGL gadget.

Example 2: (Rotating Shapes)
#Include "window9.bi"
#include "GL/gl.bi"
function SceneDraw() As Integer
Static rtri as single, rquad as Single
glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glTranslatef (-1.5, 0.0, -6.0)
glRotatef (rtri, 0, 1, 0)
glBegin (GL_TRIANGLES)
glColor3f (1.0, 0.0, 0.0) : glVertex3f ( 0.0, 1.0, 0.0)
glColor3f (0.0, 1.0, 0.0) : glVertex3f (-1.0,-1.0, 0.0)
glColor3f (0.0, 0.0, 1.0) : glVertex3f ( 1.0,-1.0, 0.0)
glEnd()
glLoadIdentity()
glTranslatef(1.5, 0.0, -6.0)
glColor3f (0.5, 0.5, 1.0)
glRotatef (rquad, 1, 0, 0)
glBegin (GL_QUADS)
glVertex3f (-1.0, 1.0, 0.0)
glVertex3f ( 1.0, 1.0, 0.0)
glVertex3f ( 1.0,-1.0, 0.0)
glVertex3f (-1.0,-1.0, 0.0)
glEnd()
glFlush() // Typically not needed with SwapBuffers
rtri += 1
rquad += 1
OpenGLGadgetSwapBuffers(1)
Return TRUE
End Function
var win = OpenWindow("OpenGL Gadget",100,100,230,250)
OpenGLGadget(1,5,5,200,200,,32) // Gadget with depth buffer
SetTimer(win , 1, 20, Cast(Any Ptr,@SceneDraw)) // Use address of function
Do
var event = WaitEvent()
If event = eventclose Then Exit Do
Loop
Result: Visual output of a rotating triangle and square.

***
SUB: OpenGLGadgetMakeCurrent
Syntax: Sub OpenGLGadgetMakeCurrent(ByVal gadget As Long)
Description: Makes the specified OpenGL gadget the current rendering target for OpenGL commands.
Options:
gadget - Gadget ID number.
Platform: Windows, Linux
Example: (Switching between two OpenGL gadgets)
#Include "window9.bi"
#include "GL/gl.bi"
Enum gadgets
opengl = 1
opengl2
Butchange
End enum
Dim Shared change As Integer
sub SceneDraw()
var w = GadgetWidth(change)
var h = GadGetHeight(change)
glClearColor(0,0,0,0)
glClear(GL_COLOR_BUFFER_BIT)
glBegin(GL_POINTS)
for i as integer = 1 to 5000
glColor3f(rnd,rnd,rnd)
glVertex2i(rnd*w,rnd*h)
next
glEnd()
OpenGLGadgetSwapBuffers(Change)
end sub
var win = OpenWindow("OpenGL Gadget",100,100,510,250)
#Ifdef __FB_WIN32__
ButtonGadget(Butchange,420,80,70,70,"Change Gadget" , BS_MULTILINE)
#Else
ButtonGadget(Butchange,420,80,70,70,!"Change\nGadget")
#EndIf
OpenGLGadget(opengl,5,5,200,200,,0) // 0 = no depth buffer
OpenGLGadget(opengl2,210,5,200,200,,0) // 0 = no depth buffer
change=opengl
OpenGLGadgetMakeCurrent(change) // Set initial target
Do
var event = WindowEvent()
Select Case event
Case eventclose
Exit Do
Case eventgadget
If EventNumber = Butchange Then // Use enum value
Change = ((change-1) Xor 1)+1 // Toggle between 1 and 2
OpenGLGadgetMakeCurrent(change) // Switch target
EndIf
End Select
SceneDraw()
sleep(1)
Loop
Result: Visual output showing two OpenGL gadgets, with drawing alternating between them on button click.

***
SUB: OpenGLGadgetSwapBuffers
Syntax: Sub OpenGLGadgetSwapBuffers(ByVal gadget As Long)
Description: Swaps the front and back buffers of the specified OpenGL gadget, making the rendered image visible (for double-buffered contexts).
Options:
gadget - Gadget ID number.
Platform: Windows, Linux
Example: (See OpenGLGadget and OpenGLGadgetMakeCurrent examples)

--- SECTION: ClipBoard ---
Description: Functions for interacting with the system clipboard.

***
FUNCTION: ClearClipBoard
Syntax: Function ClearClipBoard() As Integer
Description: Clears the contents of the clipboard. Returns non-zero on success.
Options: None
Platform: Windows, Linux
Example:
#Include "window9.bi"
SetClipBoardText("Hello")
Print GetClipBoardText() // Console output
sleep(1000)
ClearClipBoard()
Print GetClipBoardText() // Console output (should be empty)
Sleep(1000)
Result:
Hello
(empty line)

***
FUNCTION: GetClipboardFile
Syntax: Function GetClipBoardFile() As String
Description: Returns file path(s) copied to the clipboard (e.g., from Windows Explorer).
ASCII Version: Multiple files separated by Chr(0), string ends with Chr(0) & Chr(0).
UNICODE Version: Multiple files separated by "|", string ends with "||".
Options: None
Platform: Windows
Example: (User needs to copy a file to clipboard manually first)
#Include "window9.bi"
// Manually copy a file (e.g., D:\1.bas) to the clipboard before running
Print GetClipBoardFile() // Console output
Sleep(2000)
Result: (Depends on copied file) e.g., D:\1.bas

***
FUNCTION: GetClipBoardImage
Syntax: Function GetClipBoardImage() As HBITMAP
Description: Gets an image (bitmap) from the clipboard. Returns the HBITMAP handle or 0 if no image is present or on error.
Options: None
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Integer event
Dim As Hwnd hwnd
hwnd=OpenWindow("",10,10,100,100) : CenterWindow(hwnd)
ImageGadget(1,0,0,100,100)
Var hbmp=Load_image("1.png") // Assuming 1.png exists
SetClipboardImage(hbmp)
Var clipboardBmp = GetClipboardImage()
If clipboardBmp Then SetImageGadget(1, clipboardBmp)
Free_Image(hbmp) // Free original
Do
event=WaitEvent()
If Event=EventClose Then Exit Do
Loop
// Note: Bitmap retrieved from clipboard might need separate freeing if not used by gadget directly.
Result: Shows the image from 1.png in an image gadget after copying/pasting via clipboard functions.

***
FUNCTION: GetClipBoardText
Syntax: Function GetClipBoardText() As String
Description: Gets text content from the clipboard.
Options: None
Platform: Windows, Linux
Example:
#Include "window9.bi"
SetClipBoardText("Hello")
#ifdef UNICODE
Print Trim(GetClipBoardText(),WChr(0)) // Trim potential null terminator
#else
Print Trim(GetClipBoardText(),Chr(0))
#EndIf
Sleep(1000)
Result: Hello

***
FUNCTION: SetClipboardFile
Syntax: Function SetClipboardFile(byRef sFile As String) As Integer
Description: Sends file path(s) to the clipboard, formatted for file operations (e.g., paste in Explorer).
ASCII Version: Separate multiple files with Chr(0), end string with Chr(0) & Chr(0).
UNICODE Version: Separate multiple files with "|", end string with "||".
Returns non-zero on success.
Options:
sFile - The file path string, formatted as described above.
Platform: Windows
Example:
#Include "window9.bi"
#ifdef UNICODE
SetClipBoardFile("D:\1.bas||") // Example for Unicode
#else
SetClipBoardFile("D:\1.bas" & Chr(0) & Chr(0)) // Example for ASCII
#EndIf
Print GetClipBoardFile() // Verify by getting it back (optional)
Sleep(2000)
Result: D:\1.bas (Console output if GetClipBoardFile is called)

***
SUB: SetClipBoardImage
Syntax: Sub SetClipBoardImage(ByVal hbmp As HBITMAP)
Description: Sends an image (bitmap) to the clipboard.
Options:
hbmp - Handle of the bitmap to copy.
Platform: Windows, Linux
Example: (See GetClipBoardImage example)

***
SUB: SetClipBoardText
Syntax: Sub SetClipBoardText(ByRef Text As String)
Description: Sends text to the clipboard.
Options:
Text - The string to place on the clipboard.
Platform: Windows, Linux
Example: (See GetClipBoardText example)

--- SECTION: Color ---
Description: Functions for working with colors.

***
FUNCTION: BGR (Built-in FreeBasic Function)
Syntax: function BGR(r as UByte , g as Ubyte , b as Ubyte) as Long
Description: Creates a 32-bit color value from Red, Green, and Blue components (0-255). Standard FreeBasic function, included for completeness.
Options:
r, g, b - Red, Green, Blue color components (0-255).
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Hwnd hwnd
Dim As Long event
hwnd=OpenWindow("1",30,30,500,500)
Do
event=WaitEvent()
If event=EventClose Then End
If event=eventlbDOWN Then WindowColor(hwnd,BGR(255,0,0)) // Set window to Red
If event=eventrbDOWN Then WindowColor(hwnd,BGR(0,255,0)) // Set window to Green
Loop
Result: Window changes color on mouse clicks.

***
FUNCTION: ColorRequester
Syntax: Function ColorRequester(ByVal rgbCurrentUSER As Integer=0, ByVal flag As Integer=2, ByVal hwnd As HWND=0) As COLORREF
Description: Opens a standard system dialog box for selecting a color. Returns the selected color value (COLORREF).
Options:
rgbCurrentUSER - Initial color selected in the dialog (used if flag includes CC_RGBINIT).
flag - Dialog box initialization flags (Windows only, except CC_RGBINIT): CC_ANYCOLOR, CC_ENABLEHOOK, CC_ENABLETEMPLATE, CC_ENABLETEMPLATEHANDLE, CC_FULLOPEN, CC_PREVENTFULLOPEN, CC_RGBINIT, CC_SHOWHELP, CC_SOLIDCOLOR.
hwnd - Parent window handle for the dialog.
Platform: Windows, Linux (Linux supports only basic functionality)
Example:
#Include "window9.bi"
Dim As long event
Dim As hwnd hwnd=OpenWindow("1",30,30,500,500)
WindowColor(hwnd, ColorRequester() ) // Set window color using requester
Do
event=WaitEvent()
If event=EventClose Then End
Loop
Result: Opens a color selection dialog; the window background changes to the selected color.

***
FUNCTION: GetGadgetColor
Syntax: Function GetGadgetColor(byval gadget as Long ,ByVal flag as Long ) As Integer
Description: Gets the background or text color of a supported gadget. Support varies by gadget type and platform/GTK version.
Supported Gadgets: ButtonGadget (Linux text only), TextGadget, StringGadget, EditorGadget, CheckBoxGadget (Linux text only), ComboBoxGadget (Win only), ListBoxGadget, ListViewGadget, GadgetToolTip (Win only), OptionGadget (Linux text only), TrackBarGadget (Win/Linux GTK3), SpinGadget (Win/Linux GTK3), GroupGadget (Linux text only), ScrollBarGadget (Win only), ProgressBarGadget (Win/Linux GTK2), ExplorerListGadget (Win only).
Options:
gadget - Gadget ID number.
flag - Specifies which color to get: 1 = Background Color, 2 = Text Color.
Platform: Windows, Linux (support varies)
Example:
#Include "window9.bi"
OpenWindow("",10,10,240,150)
EditorGadget(1,20,20,100,40,"Editor")
SetGadgetColor(1,50000,0,1) // Set background color
ButtonGadget(2,10,70,150,30,"Get Color Editor")
TextGadget(3,150,20,45,17,"",SS_CENTER)
SetGadgetColor(3,255,16777215,3) // Set background/text for display gadget
Do
var event=WaitEvent()
If event=EventGadget Then
Select case EventNumber
Case 2
SetGadgetText(3,Str(GetGadgetColor(1,1))) // Get background color of editor
End Select
ElseIf event=Eventclose Then
End
EndIf
Loop
Result: Displays the background color value of the editor gadget when the button is clicked.

***
FUNCTION: SelectedFontColor
Syntax: Function SelectedFontColor() As Integer
Description: Gets the color selected in the most recent call to FontRequester.
Options: None
Platform: Windows
Example: (See FontRequester example)

***
SUB: SetGadgetColor
Syntax: Sub SetGadgetColor(byval gadget As Long, ByVal colorBG as Long, ByVal colorText as Long, ByVal flag as Long)
Description: Sets the background or text color of a supported gadget. Support varies by gadget type and platform/GTK version. See GetGadgetColor for supported list and notes.
Options:
gadget - Gadget ID number.
colorBG - Background color value.
colorText - Text color value.
flag - Specifies which color(s) to set: 1 = Background Color, 2 = Text Color, 3 = Both Background and Text Color.
Platform: Windows, Linux (support varies)
Example 1: (Trackbar and Text Gadget)
#Include "window9.bi"
OpenWindow("",10,10,300,150)
ButtonGadget(1,20,20,60,25,"End")
TrackBarGadget(2,20,70,100,30,0,10)
SetGadgetColor(2,50000,0,1) // Set trackbar background
TextGadget(3,200,20,50,50)
SetGadgetFont(3,LoadFont("Arial",34))
SetGadgetColor(3,0,16777215,3) // Set text gadget background (black) and text (white)
Do
var event=WaitEvent()
If event=EventGadget Then
Select case EventNumber
Case 2
SetGadgetText(3,Str(GetTrackBarPos(2)))
Case 1
end
End Select
EndIf
Loop
Result: Shows a trackbar with a custom background and a text gadget with custom colors.

Example 2: (ComboBox - Windows only for color)
#Include "window9.bi"
CenterWindow(OpenWindow("",10,10,260,100))
ComboBoxGadget(1,10,10,100,80)
AddComboBoxItem(1,"Hello0",-1)
AddComboBoxItem(1,"Hello1",-1)
AddComboBoxItem(1,"Hello2",-1)
ComboBoxGadget(2,120,10,100,80)
AddComboBoxItem(2,"Hello0",-1)
AddComboBoxItem(2,"Hello1",-1)
AddComboBoxItem(2,"Hello2",-1)
SetGadgetColor(1,255,16777215,3) // Combo 1: Blue BG, White Text
SetGadgetColor(2,50000,0,1) // Combo 2: Custom BG
Do
var event=WaitEvent()
If event=eventclose Then End
Loop
Result: Shows two ComboBox gadgets with custom colors (Windows only).

***
SUB: WindowColor
Syntax: Sub WindowColor(ByVal hWin As HWND, ByVal iColor As ulong)
Description: Sets the background color of the specified window.
Options:
hWin - Handle of the window.
iColor - Color value (use BGR or ColorRequester).
Platform: Windows, Linux
Example: (See BGR example)

--- SECTION: Cipher ---
Description: Functions for encryption and hashing. Based on code by D.J.Peters and MOD.

***
FUNCTION: AESDecoder
Syntax: function AESDecoder(byref Text as string, byref Key as string) as String
Description: Decrypts a string previously encrypted with AESEncoder using the provided key (AES algorithm).
Options:
Text - The encrypted string.
Key - The decryption key (password).
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As String st="Hello"
st=AESEncoder(st,"dvbjhrvh")
Print st // Encrypted output
st = AESDecoder(st,"dvbjhrvh")
Print st // Original text
Sleep(2000)
Result: (Console output shows encrypted and then decrypted string)

***
FUNCTION: AESEncoder
Syntax: function AESEncoder(byref Text as string, byref Key as string) as String
Description: Encrypts a string using the AES algorithm with the provided key.
Options:
Text - The plain text string to encrypt.
Key - The encryption key (password).
Platform: Windows, Linux
Example: (See AESDecoder example)

***
FUNCTION: Decode64
Syntax: Function Decode64(ByRef strb64 as const String) As String
Description: Decodes a Base64 encoded string back to its original form.
Options:
strb64 - The Base64 encoded string.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As String st="Hello"
st=Encode64(st)
Print st // Base64 output
st=Decode64(st)
Print st // Original text
Sleep(2000)
Result:
SGVsbG8=
Hello

***
FUNCTION: Encode64
Syntax: Function Encode64(ByRef text As String) As String
Description: Encodes a string using the Base64 algorithm.
Options:
text - The string to encode.
Platform: Windows, Linux
Example: (See Decode64 example)

***
FUNCTION: FastCRC32
Syntax: Function FastCRC32(Byval pBuffer As any Ptr, Byval BufferSize As uInteger) As ulong
Description: Calculates the CRC32 checksum of a memory buffer.
Options:
pBuffer - Pointer to the memory buffer.
BufferSize - Size of the buffer in bytes.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As String st="Hello"
Print st, " CRC=";Hex(FastCRC32(StrPtr(st),Len(st)))
st=Encode64(st) // Modify string
Print st
st=Decode64(st) // Restore string
Print st," CRC=";Hex(FastCRC32(StrPtr(st),Len(st))) // CRC should match original
Sleep(2000)
Result:
Hello CRC=F7D18982
SGVsbG8=
Hello CRC=F7D18982

***
FUNCTION: MD5createFileHash
Syntax: Function MD5createFileHash(ByRef file As String) As String
Description: Creates an MD5 hash (128-bit) string representation for the contents of a file.
Options:
file - Full path to the file.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Print MD5createFileHash("C:\Windows\notepad.exe") // Example path
Sleep(2000)
Result: (MD5 hash of notepad.exe, will vary) e.g., A4F6DF0E33E644E802C8798ED94D80EA

***
FUNCTION: MD5createHash
Syntax: Function MD5createHash(ByRef text As String) As String
Description: Creates an MD5 hash (128-bit) string representation for a given text string.
Options:
text - The string to hash.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Print MD5createHash("Hello")
Sleep(2000)
Result: 8B1A9953C4611296A827ABF8C47804D7

***
FUNCTION: SHA1create
Syntax: Function SHA1create(ByRef text As String) As String
Description: Creates an SHA-1 hash string representation for a given text string.
Options:
text - The string to hash.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Print SHA1create ("Hello")
Sleep(2000)
Result: F7FF9E8B7BB2E09B70935A5D785E0CC5D9D0ABF0

***
FUNCTION: SHA1createFile
Syntax: Function SHA1createFile(ByRef file As String) As String
Description: Creates an SHA-1 hash string representation for the contents of a file.
Options:
file - Full path to the file.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Print SHA1createFile ("1.png") // Assuming 1.png exists
Sleep(2000)
Result: (SHA-1 hash of 1.png)

***
FUNCTION: SHA512create
Syntax: Function SHA512create(ByRef text As String) As String
Description: Creates an SHA-512 hash string representation for a given text string.
Options:
text - The string to hash.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Print SHA512create ("Hello")
Sleep(2000)
Result: 3615F80C9D293ED7402687F94B22D58E529B8CC7916F8FAC7FDDF7FBD5AF4CF777D3D795A7A00A16BF7E7F3FB9561EE9BAAE480DA9FE7A18769E71886B03F315

***
FUNCTION: SHA512createFile
Syntax: Function SHA512createFile(ByRef file As String) As String
Description: Creates an SHA-512 hash string representation for the contents of a file.
Options:
file - Full path to the file.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Print SHA512createFile ("1.png") // Assuming 1.png exists
Sleep(2000)
Result: (SHA-512 hash of 1.png)

--- SECTION: Config ---
Description: Provides a way to store and retrieve data similar to INI files. Data is stored in memory and can be loaded from/saved to a file (UTF-8 encoded without BOM). Uses Group/Key pairs. Avoid using internal strings "~!+!~" and "~! !~".

***
SUB: ConfigClear
Syntax: Sub ConfigClear(p As Any Ptr)
Description: Clears all data from the specified configuration store.
Options:
p - Handle to the configuration store (from ConfigCreate).
Platform: Windows, Linux
Example:
#include "window9.bi"
Dim As Any Ptr p = ConfigCreate()
SetConfigValue(p , "Group1" , "Key1" , "data1")
SetConfigValue(p , "Group1" , "Key2" , "data2")
ConfigClear(p)
Print GetConfigValue(p , "Group1" , "Key1") // Should be empty
Print GetConfigValue(p , "Group1" , "Key2") // Should be empty
ConfigDelete(p)
Result: (Two empty lines)

***
FUNCTION: ConfigCreate
Syntax: Function ConfigCreate() As Any Ptr
Description: Creates a new, empty configuration store in memory and returns its handle.
Options: None
Platform: Windows, Linux
Example:
#include "window9.bi"
Dim As Any Ptr p = ConfigCreate()
SetConfigValue(p , "Group1" , "Key1" , "data1")
SetConfigValue(p , "Group1" , "Key2" , "data2")
SetConfigValue(p , "Group2" , "Key1" , "data3")
SetConfigValue(p , "Group2" , "Key2" , "data4")
Print GetConfigValue(p , "Group1" , "Key1")
Print GetConfigValue(p , "Group1" , "Key2")
Print GetConfigValue(p , "Group2" , "Key1")
Print GetConfigValue(p , "Group2" , "Key2")
ConfigSave(p , "test.ini") // Save to file
ConfigDelete(p) // Free memory
Result:
data1
data2
data3
data4

***
SUB: ConfigDelete
Syntax: Sub ConfigDelete(p As Any Ptr)
Description: Deletes the specified configuration store and frees associated memory.
Options:
p - Handle to the configuration store (from ConfigCreate).
Platform: Windows, Linux
Example:
#include "window9.bi"
Dim As Any Ptr p = ConfigCreate()
SetConfigValue(p , "Group1" , "Key1" , "data1")
Print GetConfigValue(p , "Group1" , "Key1")
ConfigDelete(p)
// Accessing 'p' after this point leads to errors.
Result: data1

***
SUB: ConfigDeleteValue
Syntax: Sub ConfigDeleteValue(p As Any Ptr , sGroup As USTRING , sKey As USTRING)
Description: Removes a specific key-value pair from the configuration store.
Options:
p - Handle to the configuration store.
sGroup - The group name containing the key.
sKey - The key of the value to remove.
Platform: Windows, Linux
Example:
#include "window9.bi"
Dim As Any Ptr p = ConfigCreate()
SetConfigValue(p , "Group1" , "Key1" , "data1")
SetConfigValue(p , "Group1" , "Key2" , "data2")
Print GetConfigValue(p , "Group1" , "Key1")
Print GetConfigValue(p , "Group1" , "Key2")
ConfigDeleteValue(p , "Group1" , "Key1")
Print "After delete value"
Print GetConfigValue(p , "Group1" , "Key1") // Should be empty
Print GetConfigValue(p , "Group1" , "Key2")
ConfigDelete(p)
Result:
data1
data2
After delete value

data2

***
SUB: ConfigLoad
Syntax: Sub ConfigLoad(p As Any Ptr , sPath As USTRING)
Description: Loads configuration data from a file (UTF-8 without BOM, INI-like format) into the specified configuration store. Clears existing data in the store before loading.
Options:
p - Handle to the configuration store.
sPath - Path to the configuration file to load.
Platform: Windows, Linux
Example: (Assumes test.ini was created by the ConfigCreate example)
#include "window9.bi"
Dim As Any Ptr p = ConfigCreate() // Create an empty store
ConfigLoad(p , "test.ini") // Load from file
Print GetConfigValue(p , "Group1" , "Key1")
Print GetConfigValue(p , "Group1" , "Key2")
Print GetConfigValue(p , "Group2" , "Key1")
Print GetConfigValue(p , "Group2" , "Key2")
ConfigDelete(p)
Result:
data1
data2
data3
data4

***
SUB: ConfigSave
Syntax: Sub ConfigSave(p As Any Ptr , sPath As USTRING)
Description: Saves the current contents of the configuration store to a file in INI-like format (UTF-8 without BOM).
Options:
p - Handle to the configuration store.
sPath - Path to the file where the configuration should be saved.
Platform: Windows, Linux
Example: (See ConfigCreate example)

***
FUNCTION: GetConfigValue
Syntax: Function GetConfigValue(p As Any Ptr , sGroup As USTRING , sKey As USTRING) As USTRING
Description: Retrieves the string value associated with a specific group and key from the configuration store. Returns an empty string if the group or key is not found.
Options:
p - Handle to the configuration store.
sGroup - The group name.
sKey - The key name.
Platform: Windows, Linux
Example: (See ConfigCreate example)

***
SUB: SetConfigValue
Syntax: Sub SetConfigValue(p As Any Ptr , sGroup As USTRING , sKey As USTRING , sValue As USTRING)
Description: Adds a new key-value pair or modifies an existing one within the specified group in the configuration store.
Options:
p - Handle to the configuration store.
sGroup - The group name.
sKey - The key name.
sValue - The string value to store (USTRING type).
Platform: Windows, Linux
Example: (See ConfigCreate example)

--- SECTION: Data Containers - Hash Table ---
Description: An associative container (hash table) storing key-value pairs. Keys are strings (case-sensitive), values can be pointers or strings. Data is not ordered. Generally faster than Map but unsorted.

***
FUNCTION: CreateHashTable
Syntax: Function CreateHashTable() As Any Ptr
Description: Creates a new hash table and returns its handle. Use SetValueStr/GetValueStr functions for string data, SetValue/GetValue for pointer/integer data. Remember to use the correct flag (1 for strings, 0 for non-strings) in FreeHashTable, FreeKeyHashTable, DeleteHashTable to manage memory correctly. Avoid mixing string and non-string data types in the same table.
Options: None
Platform: Windows, Linux
Example: (Using strings)
#include "window9.bi"
dim p as any ptr = CreateHashTable()
For i As Long = 0 To 10
dim as string skey = "Key" & i
dim as USTRING us = str(rnd)
SetValueStrHashTable(p , skey , us)
Next
For i As Long = 0 To 10
dim as string skey = "Key" & i
Print GetValueStrHashTable(p , skey )
Next
DeleteHashTable(p , 1) // Use flag 1 for string data
Result: (Prints 11 random float strings)

***
SUB: DeleteHashTable
Syntax: Sub DeleteHashTable(p As Any Ptr , bFlagFreeMemoryStrings As Long = 0)
Description: Deletes the hash table and frees associated memory.
Options:
p - Hash table handle.
bFlagFreeMemoryStrings - Set to 1 if the table stored string data (using SetValueStrHashTable) to free the string memory; otherwise, set to 0 (default).
Platform: Windows, Linux
Example: (See CreateHashTable example)

***
SUB: FreeHashTable
Syntax: Sub FreeHashTable(p As Any Ptr , bFlagFreeMemoryStrings As Long = 0)
Description: Clears all entries from the hash table, freeing associated memory based on the flag.
Options:
p - Hash table handle.
bFlagFreeMemoryStrings - Set to 1 for string data, 0 otherwise.
Platform: Windows, Linux
Example:
#include "window9.bi"
dim p as any ptr = CreateHashTable()
For i As Long = 0 To 10
SetValueStrHashTable(p , "string" & i , str(i))
Next
Print GetSizeHashTable(p)
FreeHashTable(p , 1) // Free string data
Print GetSizeHashTable(p)
DeleteHashTable(p , 1) // Still need to delete the table itself
Result:
11
0

***
SUB: FreeKeyHashTable
Syntax: Sub FreeKeyHashTable(p As Any Ptr , sKey As String , bFlagFreeMemoryStrings As Long = 0)
Description: Removes a single key-value pair from the hash table.
Options:
p - Hash table handle.
sKey - The key of the entry to remove.
bFlagFreeMemoryStrings - Set to 1 for string data, 0 otherwise.
Platform: Windows, Linux
Example:
#include "window9.bi"
dim p as any ptr = CreateHashTable()
For i As Long = 0 To 2
SetValueStrHashTable(p , "string" & i , str(i))
Next
For i As Long = 0 To 2
Print GetValueStrHashTable(p , "string" & i)
Next
FreeKeyHashTable(p , "string1" , 1) // Remove key "string1"
Print "Values after deleting"
For i As Long = 0 To 2
Print GetValueStrHashTable(p , "string" & i) // "string1" should be missing
Next
DeleteHashTable(p , 1)
Result:
0
1
2
Values after deleting
0
2

***
FUNCTION: GetValueHashTable
Syntax: Function GetValueHashTable(p As Any Ptr , sKey As String) As Any Ptr
Description: Retrieves the data pointer associated with the given key. Returns NULL if the key is not found. Use for non-string data.
Options:
p - Hash table handle.
sKey - The key to look up.
Platform: Windows, Linux
Example: (Storing integers as pointers)
#include "window9.bi"
dim p as any ptr = CreateHashTable()
For i As Long = 1 To 3
SetValueHashTable(p , "string" & i , cast(any ptr , cint(i)))
Next
For i As Long = 1 To 3
Print cint(GetValueHashTable(p , "string" & i))
Next
DeleteHashTable(p) // Flag 0 for non-string data
Result:
1
2
3

***
FUNCTION: GetValueStrHashTable
Syntax: Function GetValueStrHashTable(p As Any Ptr , sKey As String) As USTRING
Description: Retrieves the string value associated with the given key. Returns an empty string if the key is not found. Use for string data.
Options:
p - Hash table handle.
sKey - The key to look up.
Platform: Windows, Linux
Example: (See CreateHashTable example)

***
FUNCTION: GetSizeHashTable
Syntax: Function GetSizeHashTable(p As Any Ptr) As Long
Description: Returns the number of key-value pairs currently stored in the hash table.
Options:
p - Hash table handle.
Platform: Windows, Linux
Example: (See FreeHashTable example)

***
SUB: SetValueHashTable
Syntax: Sub SetValueHashTable(p As Any Ptr , sKey As String , anyValue As Any Ptr)
Description: Adds or modifies a key-value pair where the value is a pointer. Does not manage the memory pointed to by anyValue. Integers can be stored using CAST. Avoid using with SetValueStrHashTable in the same table.
Options:
p - Hash table handle.
sKey - The key (case-sensitive string).
anyValue - Pointer to the data to associate with the key.
Platform: Windows, Linux
Example:
#include "window9.bi"
dim p as any ptr = CreateHashTable()
For i As Long = 1 To 3
SetValueHashTable(p , "string" & i , cast(any ptr , cint(i)))
Next
For i As Long = 1 To 3
Print cint(GetValueHashTable(p , "string" & i))
Next
SetValueHashTable(p , "string2" , cast(any ptr , cint(100))) // Modify existing key
Print "Output after changes"
For i As Long = 1 To 3
Print cint(GetValueHashTable(p , "string" & i))
Next
DeleteHashTable(p)
Result:
1
2
3
Output after changes
1
100
3

***
SUB: SetValueStrHashTable
Syntax: Sub SetValueStrHashTable(p As Any Ptr , sKey As String , anyValue As USTRING)
Description: Adds or modifies a key-value pair where the value is a string. The library manages the memory for the stored string. Avoid using with SetValueHashTable in the same table.
Options:
p - Hash table handle.
sKey - The key (case-sensitive string).
anyValue - The USTRING value to associate with the key.
Platform: Windows, Linux
Example:
#include "window9.bi"
dim p as any ptr = CreateHashTable()
For i As Long = 1 To 3
SetValueStrHashTable(p , "string" & i , str(i))
Next
For i As Long = 1 To 3
Print GetValueStrHashTable(p , "string" & i)
Next
SetValueStrHashTable(p , "string2" , str(100)) // Modify existing key
Print "Output after changes"
For i As Long = 1 To 3
Print GetValueStrHashTable(p , "string" & i)
Next
DeleteHashTable(p , 1) // Use flag 1 for strings
Result:
1
2
3
Output after changes
1
100
3

--- SECTION: Data Containers - Linked List ---
Description: A doubly linked list implementation for storing elements (pointers or strings) in an indexed sequence.

***
SUB: AddList
Syntax: Sub AddList(p As Any Ptr , anyValue As Any Ptr)
Description: Adds a new element (storing a pointer) to the end of the list. Does not manage the memory pointed to by anyValue. Integers can be stored using CAST. Avoid using with AddStrList in the same list.
Options:
p - List handle (from CreateList).
anyValue - Pointer to the data to add.
Platform: Windows, Linux
Example 1: (Storing pointers to array elements)
#include "window9.bi"
dim shared as Long iDim(1) = {1,2}
Dim As Any Ptr p = CreateList()
AddList(p , @iDim(0))
AddList(p , @iDim(1))
Print *cast(long Ptr , getValueList(p , 0))
Print *cast(long Ptr , getValueList(p , 1))
DeleteList(p) // Flag 0 for non-string data
Result:
1
2
Example 2: (Storing integers directly)
#include "window9.bi"
Dim As Any Ptr p = CreateList()
AddList(p , cast(any ptr , cast(integer , 1)))
AddList(p , cast(any ptr , cast(integer , 2)))
Print cast(integer , getValueList(p , 0))
Print cast(integer , getValueList(p , 1))
DeleteList(p) // Flag 0 for non-string data
Result:
1
2

***
SUB: AddStrList
Syntax: Sub AddStrList(p As Any Ptr , anyValue As USTRING)
Description: Adds a new element (storing a string) to the end of the list. The library manages the string memory. Avoid using with AddList in the same list.
Options:
p - List handle (from CreateList).
anyValue - The USTRING value to add.
Platform: Windows, Linux
Example:
#include "window9.bi"
Dim As Any Ptr p = CreateList()
AddStrList(p , "String 1")
AddStrList(p , "String 2")
Print getValueStrList(p , 0)
Print getValueStrList(p , 1)
DeleteList(p , 1) // Use flag 1 for strings
Result:
String 1
String 2

***
FUNCTION: CreateList
Syntax: Function CreateList() As Any Ptr
Description: Creates a new, empty linked list and returns its handle. Use AddStr/GetValueStr/InsertItemStr/SetValueStr for string data and Add/GetValue/InsertItem/SetValue for non-string data. Remember to use the correct flag (1 for strings, 0 for non-strings) in DeleteItemList, FreeList, DeleteList. Avoid mixing data types.
Options: None
Platform: Windows, Linux
Example: (See AddList and AddStrList examples)

***
SUB: DeleteItemList
Syntax: Sub DeleteItemList(p As Any Ptr , iIndex As Long , bFlagFreeMemoryStrings As Long = 0)
Description: Removes the element at the specified zero-based index from the list.
Options:
p - List handle.
iIndex - Index of the element to remove.
bFlagFreeMemoryStrings - Set to 1 if the list stores string data, 0 otherwise.
Platform: Windows, Linux
Example:
#include "window9.bi"
Dim As Any Ptr p = CreateList()
AddStrList(p , "String 1")
AddStrList(p , "String 2")
Print getValueStrList(p , 0)
Print getValueStrList(p , 1)
Print "----After delete 0 item"
DeleteItemList(p , 0 , 1) // Delete first item (index 0), flag 1 for strings
Print getValueStrList(p , 0) // Now holds "String 2"
' Print getValueStrList(p , 1) ' This would now be out of bounds
DeleteList(p , 1)
Result:
String 1
String 2
----After delete 0 item
String 2

***
SUB: DeleteList
Syntax: Sub DeleteList(p As Any Ptr, bFlagFreeMemoryStrings As Long = 0)
Description: Deletes the entire list and frees associated memory.
Options:
p - List handle.
bFlagFreeMemoryStrings - Set to 1 for string data, 0 otherwise.
Platform: Windows, Linux
Example: (See AddStrList example)

***
SUB: FreeList
Syntax: Sub FreeList(p As Any Ptr , bFlagFreeMemoryStrings As Long = 0)
Description: Removes all elements from the list, freeing associated memory based on the flag. The list itself still exists but is empty.
Options:
p - List handle.
bFlagFreeMemoryStrings - Set to 1 for string data, 0 otherwise.
Platform: Windows, Linux
Example:
#include "window9.bi"
Dim As Any Ptr p = CreateList()
AddStrList(p , "String 1")
AddStrList(p , "String 2")
Print GetSizeList(p)
FreeList(p , 1) // Free string data
Print GetSizeList(p)
DeleteList(p , 1) // Still need to delete the list structure
Result:
2
0

***
FUNCTION: GetSizeList
Syntax: Function GetSizeList(p As Any Ptr) As Long
Description: Returns the number of elements currently in the list.
Options:
p - List handle.
Platform: Windows, Linux
Example: (See FreeList example)

***
FUNCTION: GetValueList
Syntax: Function GetValueList(p As Any Ptr , iIndex As Long) As Any Ptr
Description: Retrieves the data pointer stored at the specified zero-based index in the list. Returns NULL if the index is invalid. Use for non-string data.
Options:
p - List handle.
iIndex - Index of the element to retrieve.
Platform: Windows, Linux
Example: (See AddList example 1)

***
FUNCTION: GetValueStrList
Syntax: Function GetValueStrList(p As Any Ptr , iIndex As Long) As USTRING
Description: Retrieves the string value stored at the specified zero-based index in the list. Returns an empty string if the index is invalid. Use for string data.
Options:
p - List handle.
iIndex - Index of the element to retrieve.
Platform: Windows, Linux
Example: (See AddStrList example)

***
SUB: InsertItemList
Syntax: Sub InsertItemList(p As Any Ptr , iIndex As Long , anyValue As Any Ptr)
Description: Inserts a new element (storing a pointer) into the list at the specified zero-based index. Existing elements at or after the index are shifted. Does not manage the memory pointed to by anyValue. Integers can be stored using CAST. Avoid using with InsertItemStrList in the same list.
Options:
p - List handle.
iIndex - Index at which to insert the new element.
anyValue - Pointer to the data for the new element.
Platform: Windows, Linux
Example 1: (Inserting pointer)
#include "window9.bi"
dim as Integer iDim(2) = {1 , 2 , 3}
Dim As Any Ptr p = CreateList()
AddList(p , @iDim(0)) // List: {&1}
AddList(p , @iDim(2)) // List: {&1, &3}
InsertItemList(p , 1 , @iDim(1)) // Insert &2 at index 1. List: {&1, &2, &3}
for i as Long = 0 to GetSizeList(p)-1
Print *cast(integer ptr , GetValueList(p , i))
Next
DeleteList(p)
Result:
1
2
3
Example 2: (Inserting integer)
#include "window9.bi"
Dim As Any Ptr p = CreateList()
AddList(p , cast(any ptr , cint(1))) // List: {1}
AddList(p , cast(any ptr , cint(3))) // List: {1, 3}
InsertItemList(p , 1 , cast(any ptr , cint(2))) // Insert 2 at index 1. List: {1, 2, 3}
for i as Long = 0 to GetSizeList(p)-1
Print cint(GetValueList(p , i))
Next
DeleteList(p)
Result:
1
2
3

***
SUB: InsertItemStrList
Syntax: Sub InsertItemStrList(p As Any Ptr , iIndex As Long , anyValue As USTRING)
Description: Inserts a new element (storing a string) into the list at the specified zero-based index. The library manages the string memory. Avoid using with InsertItemList in the same list.
Options:
p - List handle.
iIndex - Index at which to insert the new element.
anyValue - The USTRING value for the new element.
Platform: Windows, Linux
Example:
#include "window9.bi"
Dim As Any Ptr p = CreateList()
AddStrList(p , "String 1") // List: {"String 1"}
AddStrList(p , "String 2") // List: {"String 1", "String 2"}
InsertItemStrList(p , 1 , "String 1.5") // Insert at index 1. List: {"String 1", "String 1.5", "String 2"}
for i as Long = 0 to GetSizeList(p)-1
Print GetValueStrList(p , i)
Next
DeleteList(p , 1) // Flag 1 for strings
Result:
String 1
String 1.5
String 2

***
SUB: MoveItemList
Syntax: Sub MoveItemList(p As Any Ptr , iIndexFrom As Long , iIndexTo As Long)
Description: Moves an element from one index position to another within the list.
Options:
p - List handle.
iIndexFrom - The zero-based index of the element to move.
iIndexTo - The zero-based index where the element should be moved to.
Platform: Windows, Linux
Example:
#include "window9.bi"
Dim As Any Ptr p = CreateList()
AddStrList(p , "String 1") // Index 0
AddStrList(p , "String 2") // Index 1
AddStrList(p , "String 3") // Index 2
MoveItemList(p , 2 , 0) // Move item from index 2 ("String 3") to index 0
for i as Long = 0 to GetSizeList(p)-1
Print GetValueStrList(p , i)
Next
DeleteList(p , 1)
Result:
String 3
String 1
String 2

***
SUB: SetValueList
Syntax: Sub SetValueList(p As Any Ptr , iIndex As Long , anyValue As Any Ptr)
Description: Replaces the data pointer of an existing element at the specified index. Does not free the old pointer's data. Use for non-string data.
Options:
p - List handle.
iIndex - Index of the element to modify.
anyValue - The new pointer value for the element.
Platform: Windows, Linux
Example:
#include "window9.bi"
Dim As Any Ptr p = CreateList()
AddList(p , cast(any Ptr , cint(1)))
AddList(p , cast(any Ptr , cint(2)))
for i as Long = 0 to GetSizeList(p)-1
Print cint(GetValueList(p , i))
Next
Print "Changed 1 element"
SetValueList(p , 1 , cast(any Ptr , cint(100))) // Change value at index 1
for i as Long = 0 to GetSizeList(p)-1
Print cint(GetValueList(p , i))
Next
DeleteList(p)
Result:
1
2
Changed 1 element
1
100

***
SUB: SetValueStrList
Syntax: Sub SetValueStrList(p As Any Ptr , iIndex As Long , anyValue As USTRING)
Description: Replaces the string value of an existing element at the specified index. Frees the old string memory and manages the new string's memory. Use for string data.
Options:
p - List handle.
iIndex - Index of the element to modify.
anyValue - The new USTRING value for the element.
Platform: Windows, Linux
Example:
#include "window9.bi"
Dim As Any Ptr p = CreateList()
AddStrList(p , "String 1")
AddStrList(p , "String 2")
for i as Long = 0 to GetSizeList(p)-1
Print GetValueStrList(p , i)
Next
Print "-----Changed 1 element-----"
SetValueStrList(p , 1 , "Changes String") // Change value at index 1
for i as Long = 0 to GetSizeList(p)-1
Print GetValueStrList(p , i)
Next
DeleteList(p , 1) // Flag 1 for strings
Result:
String 1
String 2
-----Changed 1 element-----
String 1
Changes String

--- SECTION: Data Containers - Map (Dictionary) ---
Description: An associative container (dictionary) storing key-value pairs, similar to HashTable but keeps keys sorted (implemented using an AVL tree). Keys are strings (case-sensitive), values can be pointers or strings. Interface is similar to HashTable.

***
FUNCTION: CreateMap
Syntax: Function CreateMap() As Any Ptr
Description: Creates a new, empty map (dictionary) and returns its handle. Use SetValueStr/GetValueStr functions for string data, SetValue/GetValue for pointer/integer data. Remember to use the correct flag (1 for strings, 0 for non-strings) in FreeMap, FreeKeyMap, DeleteMap. Avoid mixing data types.
Options: None
Platform: Windows, Linux
Example: (See HashTable CreateHashTable example, just replace HashTable with Map)

***
SUB: DeleteMap
Syntax: Sub DeleteMap(p As Any Ptr , bFlagFreeMemoryStrings As Long = 0)
Description: Deletes the map and frees associated memory.
Options:
p - Map handle.
bFlagFreeMemoryStrings - Set to 1 for string data, 0 otherwise.
Platform: Windows, Linux
Example: (See HashTable DeleteHashTable example, just replace HashTable with Map)

***
SUB: FreeKeyMap
Syntax: Sub FreeKeyMap(p As Any Ptr , sKey As String , bFlagFreeMemoryStrings As Long = 0)
Description: Removes a single key-value pair from the map.
Options:
p - Map handle.
sKey - The key of the entry to remove.
bFlagFreeMemoryStrings - Set to 1 for string data, 0 otherwise.
Platform: Windows, Linux
Example: (See HashTable FreeKeyHashTable example, just replace HashTable with Map)

***
SUB: FreeMap
Syntax: Sub FreeMap(p As Any Ptr , bFlagFreeMemoryStrings As Long = 0)
Description: Clears all entries from the map, freeing associated memory based on the flag.
Options:
p - Map handle.
bFlagFreeMemoryStrings - Set to 1 for string data, 0 otherwise.
Platform: Windows, Linux
Example: (See HashTable FreeHashTable example, just replace HashTable with Map)

***
FUNCTION: GetSizeMap
Syntax: Function GetSizeMap(p As Any Ptr) As Long
Description: Returns the number of key-value pairs currently stored in the map.
Options:
p - Map handle.
Platform: Windows, Linux
Example: (See HashTable GetSizeHashTable example, just replace HashTable with Map)

***
FUNCTION: GetValueMap
Syntax: Function GetValueMap(p As Any Ptr , sKey As String) As Any Ptr
Description: Retrieves the data pointer associated with the given key. Returns NULL if the key is not found. Use for non-string data.
Options:
p - Map handle.
sKey - The key to look up.
Platform: Windows, Linux
Example: (See HashTable GetValueHashTable example, just replace HashTable with Map)

***
FUNCTION: GetValueStrMap
Syntax: Function GetValueStrMap(p As Any Ptr , sKey As String) As USTRING
Description: Retrieves the string value associated with the given key. Returns an empty string if the key is not found. Use for string data.
Options:
p - Map handle.
sKey - The key to look up.
Platform: Windows, Linux
Example: (See HashTable GetValueStrHashTable example, just replace HashTable with Map)

***
SUB: SetValueMap
Syntax: Sub SetValueMap(p As Any Ptr , sKey As String , anyValue As Any Ptr)
Description: Adds or modifies a key-value pair where the value is a pointer. Does not manage the memory pointed to by anyValue. Integers can be stored using CAST. Avoid using with SetValueStrMap in the same map.
Options:
p - Map handle.
sKey - The key (case-sensitive string).
anyValue - Pointer to the data to associate with the key.
Platform: Windows, Linux
Example: (See HashTable SetValueHashTable example, just replace HashTable with Map)

***
SUB: SetValueStrMap
Syntax: Sub SetValueStrMap(p As Any Ptr , sKey As String , anyValue As USTRING)
Description: Adds or modifies a key-value pair where the value is a string. The library manages the memory for the stored string. Avoid using with SetValueMap in the same map.
Options:
p - Map handle.
sKey - The key (case-sensitive string).
anyValue - The USTRING value to associate with the key.
Platform: Windows, Linux
Example: (See HashTable SetValueStrHashTable example, just replace HashTable with Map)

--- SECTION: Data Containers - Queue ---
Description: A First-In, First-Out (FIFO) data structure.

***
FUNCTION: BackQueue
Syntax: Function BackQueue(p As Any Ptr) As Any Ptr
Description: Returns the pointer value from the back (most recently added) of the queue without removing it. Returns NULL if empty. Use for non-string data.
Options:
p - Queue handle (from CreateQueue).
Platform: Windows, Linux
Example: (Using integers)
#include "window9.bi"
Dim as Any Ptr p = CreateQueue()
PushQueue(p , cast(Any Ptr , cint(1))) // Queue: {1}
PushQueue(p , cast(Any Ptr , cint(2))) // Queue: {1, 2}
PushQueue(p , cast(Any Ptr , cint(3))) // Queue: {1, 2, 3}
Print cint(FrontQueue(p)) // Should print 1
Print cint(BackQueue(p)) // Should print 3
DeleteQueue(p)
Result:
1
3

***
FUNCTION: BackStrQueue
Syntax: Function BackStrQueue(p As Any Ptr) As USTRING
Description: Returns the string value from the back (most recently added) of the queue without removing it. Returns an empty string if empty. Use for string data.
Options:
p - Queue handle (from CreateQueue).
Platform: Windows, Linux
Example:
#include "window9.bi"
Dim as Any Ptr p = CreateQueue()
PushStrQueue(p , "s1") // Queue: {"s1"}
PushStrQueue(p , "s2") // Queue: {"s1", "s2"}
PushStrQueue(p , "s3") // Queue: {"s1", "s2", "s3"}
Print FrontStrQueue(p) // Should print s1
Print BackStrQueue(p) // Should print s3
DeleteQueue(p , 1) // Flag 1 for strings
Result:
s1
s3

***
FUNCTION: CreateQueue
Syntax: Function CreateQueue() As Any Ptr
Description: Creates a new, empty queue and returns its handle. Use PushStr/FrontStr/BackStr for string data, Push/Front/Back for non-string data. Remember to use the correct flag (1 for strings, 0 for non-strings) in PopQueue, FreeQueue, DeleteQueue. Avoid mixing data types.
Options: None
Platform: Windows, Linux
Example:
#include "window9.bi"
Dim as Any Ptr p = CreateQueue()
PushStrQueue(p , "s1")
PushStrQueue(p , "s2")
PushStrQueue(p , "s3")
dim as long qSize = GetSizeQueue(p) ' Get size before loop
for i as Long = 0 to qSize - 1
Print FrontStrQueue(p) // Print front
PopQueue(p,1) // Remove front (use flag 1 for strings)
Next
DeleteQueue(p , 1)
Result:
s1
s2
s3

***
SUB: DeleteQueue
Syntax: Sub DeleteQueue(p As Any Ptr , bFlagFreeMemoryStrings As Long = 0)
Description: Deletes the queue and frees associated memory.
Options:
p - Queue handle.
bFlagFreeMemoryStrings - Set to 1 for string data, 0 otherwise.
Platform: Windows, Linux
Example: (See CreateQueue example)

***
SUB: FreeQueue
Syntax: Sub FreeQueue(p As Any Ptr , bFlagFreeMemoryStrings As Long = 0)
Description: Removes all elements from the queue, freeing associated memory based on the flag. The queue itself still exists but is empty.
Options:
p - Queue handle.
bFlagFreeMemoryStrings - Set to 1 for string data, 0 otherwise.
Platform: Windows, Linux
Example:
#include "window9.bi"
Dim as Any Ptr p = CreateQueue()
PushStrQueue(p , "s1")
PushStrQueue(p , "s2")
PushStrQueue(p , "s3")
Print GetSizeQueue(p)
FreeQueue(p,1) // Free string data
Print GetSizeQueue(p)
DeleteQueue(p , 1) // Still need to delete queue structure
Result:
3
0

***
FUNCTION: FrontQueue
Syntax: Function FrontQueue(p As Any Ptr) As Any Ptr
Description: Returns the pointer value from the front (least recently added) of the queue without removing it. Returns NULL if empty. Use for non-string data.
Options:
p - Queue handle.
Platform: Windows, Linux
Example: (See BackQueue example)

***
FUNCTION: FrontStrQueue
Syntax: Function FrontStrQueue(p As Any Ptr) As USTRING
Description: Returns the string value from the front (least recently added) of the queue without removing it. Returns an empty string if empty. Use for string data.
Options:
p - Queue handle.
Platform: Windows, Linux
Example: (See BackStrQueue example)

***
FUNCTION: GetSizeQueue
Syntax: Function GetSizeQueue(p As Any Ptr) As Long
Description: Returns the number of elements currently in the queue.
Options:
p - Queue handle.
Platform: Windows, Linux
Example: (See FreeQueue example)

***
FUNCTION: PopQueue
Syntax: Function PopQueue(p As Any Ptr , bFlagFreeMemoryStrings As Long = 0) As Any Ptr
Description: Removes and returns the element from the front of the queue. If storing strings (bFlagFreeMemoryStrings=1), it frees the string memory and always returns NULL. If storing non-string pointers (bFlagFreeMemoryStrings=0), it returns the pointer value that was removed.
Options:
p - Queue handle.
bFlagFreeMemoryStrings - Set to 1 for string data, 0 otherwise.
Platform: Windows, Linux
Example: (See CreateQueue example for string usage, PushQueue example 2 for non-string usage)

***
SUB: PushQueue
Syntax: Sub PushQueue(p As Any Ptr , anyValue As Any Ptr)
Description: Adds a new element (storing a pointer) to the back of the queue. Does not manage the memory pointed to by anyValue. Integers can be stored using CAST. Avoid using with PushStrQueue in the same queue.
Options:
p - Queue handle.
anyValue - Pointer to the data to add.
Platform: Windows, Linux
Example 1: (Storing pointers)
#include "window9.bi"
dim as Integer iDim(2) = {1,2,3}
Dim as Any Ptr p = CreateQueue()
PushQueue(p , @iDim(0))
PushQueue(p , @iDim(1))
PushQueue(p , @iDim(2))
dim as long qSize = GetSizeQueue(p)
for i as Long = 0 to qSize - 1
Print *cast(integer ptr ,PopQueue(p)) // Flag 0 is default for non-strings
Next
DeleteQueue(p)
Result:
1
2
3
Example 2: (Storing integers)
#include "window9.bi"
Dim as Any Ptr p = CreateQueue()
PushQueue(p , cast(any ptr , cint(1)))
PushQueue(p , cast(any ptr , cint(2)))
PushQueue(p , cast(any ptr , cint(3)))
dim as long qSize = GetSizeQueue(p)
for i as Long = 0 to qSize-1
Print cint(PopQueue(p)) // Flag 0 is default
Next
DeleteQueue(p)
Result:
1
2
3

***
SUB: PushStrQueue
Syntax: Sub PushStrQueue(p As Any Ptr , anyValue As USTRING)
Description: Adds a new element (storing a string) to the back of the queue. The library manages the string memory. Avoid using with PushQueue in the same queue.
Options:
p - Queue handle.
anyValue - The USTRING value to add.
Platform: Windows, Linux
Example: (See CreateQueue example)

--- SECTION: Data Containers - Stack ---
Description: A Last-In, First-Out (LIFO) data structure.

***
FUNCTION: CreateStack
Syntax: Function CreateStack() As Any Ptr
Description: Creates a new, empty stack and returns its handle. Use PushStr/FrontStr for string data, Push/Front for non-string data. Remember to use the correct flag (1 for strings, 0 for non-strings) in PopStack, FreeStack, DeleteStack. Avoid mixing data types.
Options: None
Platform: Windows, Linux
Example:
#include "window9.bi"
Dim as Any Ptr p = CreateStack()
PushStrStack(p , "s1")
PushStrStack(p , "s2")
PushStrStack(p , "s3")
dim as long sSize = GetSizeStack(p)
for i as Long = 0 to sSize-1
Print FrontStrStack(p) // Print top
PopStack(p,1) // Remove top (use flag 1 for strings)
Next
DeleteStack(p , 1)
Result:
s3
s2
s1

***
SUB: DeleteStack
Syntax: Sub DeleteStack(p As Any Ptr , bFlagFreeMemoryStrings As Long = 0)
Description: Deletes the stack and frees associated memory.
Options:
p - Stack handle.
bFlagFreeMemoryStrings - Set to 1 for string data, 0 otherwise.
Platform: Windows, Linux
Example: (See CreateStack example)

***
SUB: FreeStack
Syntax: Sub FreeStack(p As Any Ptr , bFlagFreeMemoryStrings As Long = 0)
Description: Removes all elements from the stack, freeing associated memory based on the flag. The stack itself still exists but is empty.
Options:
p - Stack handle.
bFlagFreeMemoryStrings - Set to 1 for string data, 0 otherwise.
Platform: Windows, Linux
Example:
#include "window9.bi"
Dim as Any Ptr p = CreateStack()
PushStrStack(p , "s1")
PushStrStack(p , "s2")
PushStrStack(p , "s3")
Print GetSizeStack(p)
FreeStack(p,1) // Free string data
Print GetSizeStack(p)
DeleteStack(p , 1) // Still need to delete stack structure
Result:
3
0

***
FUNCTION: FrontStack
Syntax: Function FrontStack(p As Any Ptr) As Any Ptr
Description: Returns the pointer value from the top of the stack without removing it. Returns NULL if empty. Use for non-string data.
Options:
p - Stack handle (from CreateStack).
Platform: Windows, Linux
Example: (Using integers)
#include "window9.bi"
Dim as Any Ptr p = CreateStack()
PushStack(p , cast(Any Ptr , cint(1))) // Stack: {1}
PushStack(p , cast(Any Ptr , cint(2))) // Stack: {1, 2}
PushStack(p , cast(Any Ptr , cint(3))) // Stack: {1, 2, 3} <- top
Print cint(FrontStack(p)) // Should print 3
DeleteStack(p)
Result: 3

***
FUNCTION: FrontStrStack
Syntax: Function FrontStrStack(p As Any Ptr) As USTRING
Description: Returns the string value from the top of the stack without removing it. Returns an empty string if empty. Use for string data.
Options:
p - Stack handle (from CreateStack).
Platform: Windows, Linux
Example:
#include "window9.bi"
Dim as Any Ptr p = CreateStack()
PushStrStack(p , "s1") // Stack: {"s1"}
PushStrStack(p , "s2") // Stack: {"s1", "s2"}
PushStrStack(p , "s3") // Stack: {"s1", "s2", "s3"} <- top
Print FrontStrStack(p) // Should print s3
DeleteStack(p , 1) // Flag 1 for strings
Result: s3

***
FUNCTION: GetSizeStack
Syntax: Function GetSizeStack(p As Any Ptr) As Long
Description: Returns the number of elements currently on the stack.
Options:
p - Stack handle.
Platform: Windows, Linux
Example: (See FreeStack example)

***
FUNCTION: PopStack
Syntax: Function PopStack(p As Any Ptr , bFlagFreeMemoryStrings As Long = 0) As Any Ptr
Description: Removes and returns the element from the top of the stack. If storing strings (bFlagFreeMemoryStrings=1), it frees the string memory and always returns NULL. If storing non-string pointers (bFlagFreeMemoryStrings=0), it returns the pointer value that was removed.
Options:
p - Stack handle.
bFlagFreeMemoryStrings - Set to 1 for string data, 0 otherwise.
Platform: Windows, Linux
Example: (See CreateStack example for string usage, PushStack example 2 for non-string usage)

***
SUB: PushStack
Syntax: Sub PushStack(p As Any Ptr , anyValue As Any Ptr)
Description: Adds a new element (storing a pointer) to the top of the stack. Does not manage the memory pointed to by anyValue. Integers can be stored using CAST. Avoid using with PushStrStack in the same stack.
Options:
p - Stack handle.
anyValue - Pointer to the data to add.
Platform: Windows, Linux
Example 1: (Storing pointers)
#include "window9.bi"
dim as Integer iDim(2) = {1,2,3}
Dim as Any Ptr p = CreateStack()
PushStack(p , @iDim(0)) // Stack: {&1}
PushStack(p , @iDim(1)) // Stack: {&1, &2}
PushStack(p , @iDim(2)) // Stack: {&1, &2, &3} <- top
dim as long sSize = GetSizeStack(p)
for i as Long = 0 to sSize-1
Print *cast(integer ptr ,PopStack(p)) // Flag 0 default
Next
DeleteStack(p)
Result:
3
2
1
Example 2: (Storing integers)
#include "window9.bi"
Dim as Any Ptr p = CreateStack()
PushStack(p , cast(any ptr , cint(1))) // Stack: {1}
PushStack(p , cast(any ptr , cint(2))) // Stack: {1, 2}
PushStack(p , cast(any ptr , cint(3))) // Stack: {1, 2, 3} <- top
dim as long sSize = GetSizeStack(p)
for i as Long = 0 to sSize-1
Print cint(PopStack(p)) // Flag 0 default
Next
DeleteStack(p)
Result:
3
2
1

***
SUB: PushStrStack
Syntax: Sub PushStrStack(p As Any Ptr , anyValue As USTRING)
Description: Adds a new element (storing a string) to the top of the stack. The library manages the string memory. Avoid using with PushStack in the same stack.
Options:
p - Stack handle.
anyValue - The USTRING value to add.
Platform: Windows, Linux
Example: (See CreateStack example)

--- SECTION: Desktop ---
Description: Functions related to display and desktop properties.

***
FUNCTION: EnumSettingsDisplay
Syntax: Function EnumSettingsDisplay() As String
Description: Enumerates supported display settings (resolution, color depth, refresh rate). Returns settings as a string like "640x480x32x75". Call ResetEnum before starting a new enumeration. Returns an empty string when no more settings are available.
Options: None
Platform: Windows
Example:
#Include "window9.bi"
Dim As String Setting
Do
Setting=EnumSettingsDisplay()
If Setting <> "" Then
Print Setting
Else
Exit Do
EndIf
Loop
Sleep(2000)
Result: (Lists supported display modes)

***
FUNCTION: GetBitsDesktop
Syntax: Function GetBitsDesktop(Byref setting As String) As Integer
Description: Extracts the color depth (bits per pixel) from a display settings string obtained via EnumSettingsDisplay or GetCurrentSettingsDisplay.
Options:
setting - The display settings string (e.g., "1920x1080x32x60").
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As String Setting=GetCurrentSettingsDisplay()
If Setting<>"" Then
Print "Width: "; GetWidthDesktop(Setting)
Print "Height: "; GetHeightDesktop(Setting)
Print "Bits: "; GetBitsDesktop(Setting)
Print "Frequency: "; GetFrequencyDesktop(Setting)
EndIf
Sleep(2000)
Result: (Prints current display settings components)

***
FUNCTION: GetCurrentSettingsDisplay
Syntax: Function GetCurrentSettingsDisplay() As string
Description: Returns the current display settings as a string (e.g., "1920x1080x32x60").
Options: None
Platform: Windows, Linux
Example: (See GetBitsDesktop example)

***
FUNCTION: GetDesktopWindow
Syntax: function GetDesktopWindow() As Any ptr
Description: Returns a handle to the desktop window. (Standard WinAPI function on Windows, provides GDK root window on Linux).
Options: None
Platform: Windows, Linux
Example:
#include "window9.bi"
Dim As HWND hwnd=GetDesktopWindow()
// Example: Print the desktop window content (might require permissions)
// HWNDPrinter(hwnd,,,,,600,600)
Print "Desktop Handle: "; hwnd ' Just print the handle
Sleep(2000)
Result: (Prints the handle value)

***
FUNCTION: GetFrequencyDesktop
Syntax: Function GetFrequencyDesktop(Byref setting As String) As Integer
Description: Extracts the refresh rate (Hz) from a display settings string.
Options:
setting - The display settings string.
Platform: Windows, Linux
Example: (See GetBitsDesktop example)

***
FUNCTION: GetHeightDesktop
Syntax: Function GetHeightDesktop(Byref setting As String) As Integer
Description: Extracts the height (pixels) from a display settings string.
Options:
setting - The display settings string.
Platform: Windows, Linux
Example: (See GetBitsDesktop example)

***
FUNCTION: GetWidthDesktop
Syntax: Function GetWidthDesktop(Byref setting As String) As Integer
Description: Extracts the width (pixels) from a display settings string.
Options:
setting - The display settings string.
Platform: Windows, Linux
Example: (See GetBitsDesktop example)

***
FUNCTION: ResetEnum
Syntax: Function ResetEnum() As Integer
Description: Resets the internal counter for the EnumSettingsDisplay function, allowing enumeration from the beginning again.
Options: None
Platform: Windows
Example:
#Include "window9.bi"
Dim As String Setting
Print "First Pass:"
Do
Setting = EnumSettingsDisplay()
If Setting <> "" Then Print Setting Else Exit Do EndIf
Loop
ResetEnum()
Sleep(1000)
Print : Print "Second Pass:"
Do
Setting = EnumSettingsDisplay()
If Setting <> "" Then Print Setting Else Exit Do EndIf
Loop
Sleep(2000)
Result: (Lists supported display modes twice)

***
FUNCTION: SetCurrentSettingsDisplay
Syntax: Function SetCurrentSettingsDisplay(ByVal w As Integer, ByVal h As Integer,ByVal Bits As Integer,ByVal Frequency As Integer) As Integer
Description: Attempts to change the current display settings. Requires valid settings obtained from EnumSettingsDisplay. Returns non-zero on success. Use with caution!
Options:
w - New display width.
h - New display height.
Bits - New color depth.
Frequency - New refresh rate.
Platform: Windows
Example: (Interactive - Use carefully!)
#Include "window9.bi"
Dim As String Setting,currentSetting
Dim As Integer inputnumber,number=1
currentSetting = GetCurrentSettingsDisplay()
Print "Current Settings: " & currentSetting
Print "Available Settings:"
Do
Setting = EnumSettingsDisplay()
If Setting <> "" Then
Print "Number " & number & Chr(9) & Setting
Else
Exit Do
EndIf
number+=1
Loop
ResetEnum()
number=1
Input "Enter number of desired setting to apply (0 to cancel): "; inputnumber
If inputnumber > 0 Then
Do
Setting = EnumSettingsDisplay()
If Setting <> "" Then
If inputnumber = number Then
Print "Applying: " & Setting
SetCurrentSettingsDisplay(GetWidthDesktop(Setting),_
GetHeightDesktop(Setting),GetBitsDesktop(Setting),GetFrequencyDesktop(Setting))
Exit Do
EndIf
Else
Print "Invalid setting number."
Exit Do
EndIf
number+=1
Loop
Sleep(5000) // Wait 5 seconds
Print "Restoring original settings: " & currentSetting
SetCurrentSettingsDisplay(GetWidthDesktop(currentSetting),_
GetHeightDesktop(currentSetting),GetBitsDesktop(currentSetting),GetFrequencyDesktop(currentSetting))
Else
Print "Change cancelled."
EndIf
Sleep(2000)
Result: (Interactive console output, attempts to change and restore display settings)

--- SECTION: Event ---
Description: Constants and functions related to the library's event handling system.

***
CONSTANT: EventActivate
Syntax: #define EventActivate &H6
Description: Event constant indicating that a window has been activated. Check EventHwnd() to see which window.
Options: None
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As hwnd hwnd,hwnd2
hwnd=OpenWindow("Window 1",10,10,200,200)
hwnd2=OpenWindow("Window 2",100,100,200,200)
Do
Var event=WaitEvent()
Select Case event
Case EventClose
If EventHwnd()=hwnd Then End // Close main loop if hwnd closes
If EventHwnd()=hwnd2 Then Close_Window(hwnd2) // Close only hwnd2
Case EventActivate
Print "Window Activated: "; eventhwnd()
End Select
Loop
Result: Prints the handle of the window each time it becomes active.

***
CONSTANT: EventClose
Syntax: #define EventClose &H10
Description: Event constant indicating that a window's close button was clicked or it received a close request. Check EventHwnd() to identify the window.
Options: None
Platform: Windows, Linux
Example:
#Include "window9.bi"
OpenWindow("Test Close",10,10,200,200)
ButtonGadget(1,10,10,100,20, "Button")
TextGadget(2,10,50,100,20,"Text")
Do
Var event=WaitEvent()
Select Case event
Case EventClose
MessBox("Event","EventClose occurred. Exiting."): End
Case EventGadget
Select Case EventNumber()
Case 1: MessBox("Gadget","Button Clicked")
Case 2: MessBox("Gadget","Text Gadget Clicked (if SS_NOTIFY style used)")
End Select
End Select
Loop
Result: Program exits when the window close button is clicked.

***
CONSTANT: EventGadget
Syntax: #define EventGadget &h401
Description: Event constant indicating an event occurred related to a gadget (e.g., button click, text change). Use EventNumber() to get the gadget ID and EventHwnd() for the parent window.
Options: None
Platform: Windows, Linux
Example: (See EventClose example)

***
FUNCTION: EventHardwareKey
Syntax: function EventHardwareKey() as Long
Description: Returns the hardware scan code for the key involved in a keyboard event (EventKeyDown, EventKeyUp). This value is independent of keyboard layout or modifier keys (Shift, Ctrl, Alt).
Options: None
Platform: Linux
Example:
#Include "window9.bi"
Dim As Integer ev
OpenWindow("Key Test",10,10,300,300)
Print "Press keys..."
Do
ev=WaitEvent()
If ev=EventClose Then end
If ev=EventKeyUp Then
Print "EventKey (Virtual): "; EventKEY()
Print "EventHardwareKey (ScanCode): "; EventHardwareKey()
EndIf
Loop
Result: Prints virtual key code and hardware scan code on key release (Linux only for EventHardwareKey).

***
FUNCTION: EventHwnd
Syntax: Function EventHwnd() As HWND
Description: Returns the handle of the window associated with the current event.
Options: None
Platform: Windows, Linux
Example: (See EventActivate example)

***
FUNCTION: EventKey
Syntax: Function EventKEY() As Integer
Description: Returns the virtual key code associated with the current keyboard or mouse event. For keyboard events (EventKeyDown, EventKeyUp), it's the virtual key code (e.g., VK_A, VK_RETURN). For mouse events (EventLBDown, etc.), it can indicate modifier keys being held (MK_CONTROL, MK_SHIFT). Note: On Linux, key codes can differ based on case and layout.
Options: None
Platform: Windows, Linux
Example: (Keyboard)
#Include "window9.bi"
Dim As Integer ev
Dim As HWND hWnd
hwnd=OpenWindow("Key Test",10,10,300,300)
Print "Press T or U..."
Do
ev=WaitEvent()
If ev=EventClose Then end
If ev=EventKeyUp Then
If EventKEY() = VK_T Then // Check for 'T' key
windowcolor(hwnd,BGR(255,0,0))
ElseIf EventKEY() = VK_U Then // Check for 'U' key
windowcolor(hwnd,BGR(0,255,0))
EndIf
EndIf
Loop
Result: Window changes color when T or U is released.

***
CONSTANT: EventKeyDown
Syntax: #define EventKeyDown &h100
Description: Event constant indicating a key has been pressed down. Use EventKey() to identify the key.
Options: None
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Integer ev
Dim As HWND hWnd
hwnd=OpenWindow("Key Test",10,10,300,300)
Print "Hold T or U..."
Do
ev=WaitEvent()
If ev=EventClose Then end
If ev=EventKeyDOWN Then
If EventKEY()=VK_T Then // 'T' key is pressed down
windowcolor(hwnd,BGR(255,0,0))
ElseIf EventKEY()=VK_U Then // 'U' key is pressed down
windowcolor(hwnd,BGR(0,255,0))
EndIf
EndIf
Loop
Result: Window changes color while T or U key is held down.

***
CONSTANT: EventKeyUp
Syntax: #define EventKeyUp &h101
Description: Event constant indicating a key has been released. Use EventKey() to identify the key.
Options: None
Platform: Windows, Linux
Example: (See EventKey example)

***
CONSTANT: EventLBDown
Syntax: #define EventLBDown &H201
Description: Event constant indicating the left mouse button has been pressed down. EventKey() may contain modifier flags (MK_CONTROL, MK_SHIFT). MouseX() and MouseY() give coordinates.
Options: None
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As hwnd hwnd
hwnd=OpenWindow("Mouse Events",10,10,200,200)
Do
Var event=WaitEvent()
Select Case event
Case EventClose : Exit Do
Case EventLBDown : Print "EventLBDown"
Case EventRBDown : Print "EventRBDown"
Case EventMBDown : Print "EventMBDown"
Case EventLBUp : Print "EventLBUp"
Case EventRBUp : Print "EventRBUp"
Case EventMBUp : Print "EventMBUp"
End Select
Loop
Result: Prints mouse button events to the console.

***
CONSTANT: EventLBUp
Syntax: #define EventLBUp &H202
Description: Event constant indicating the left mouse button has been released. EventKey() may contain modifier flags.
Options: None
Platform: Windows, Linux
Example: (See EventLBDown example)

***
FUNCTION: EventLParam
Syntax: Function EventLParam() As LPARAM
Description: Returns the LPARAM value associated with the current window message (relevant when using low-level message handling or certain specific events). For mouse events, LOWORD(EventLParam) often contains the X coordinate, and HIWORD(EventLParam) contains the Y coordinate.
Options: None
Platform: Windows
Example:
#Include "window9.bi"
Dim As Integer event
Dim As HWND hwnd
hwnd=OpenWindow("LParam Test",10,10,500,500) : CenterWindow(hwnd)
Do
event=WindowEvent()
If event=EventLBDOWN Then
Print "LBUTTONDOWN - X:"; LOWORD(EventLParam()) ; " Y:"; HIWORD(EventLParam())
EndIf
If Event=EventClose Then End
Loop
Result: Prints mouse coordinates from LPARAM on left button down.

***
CONSTANT: EventMBDown
Syntax: #define EventMBDown &H207
Description: Event constant indicating the middle mouse button has been pressed down. EventKey() may contain modifier flags.
Options: None
Platform: Windows, Linux
Example: (See EventLBDown example)

***
CONSTANT: EventMBUp
Syntax: #define EventMBUp &H208
Description: Event constant indicating the middle mouse button has been released. EventKey() may contain modifier flags.
Options: None
Platform: Windows, Linux
Example: (See EventLBDown example)

***
CONSTANT: EventMenu
Syntax: #define EventMenu &h402
Description: Event constant indicating a menu item has been selected. Use EventNumber() to get the menu item ID.
Options: None
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As HMENU menu,MenName,MenName1
Dim As Long event
OpenWindow("Menu Test",10,10,400,400)
menu=Create_Menu()
MenName=MenuTitle(menu,"File")
MenName1=MenuTitle(menu,"Help")
MenuItem(1001,MenName,"1 Menu")
MenuItem(1002,MenName,"2 Menu")
Do
event=WaitEvent()
If event=EventMenu then
Select case EventNumber()
Case 1001 : MessBox("Menu","1 Menu Clicked")
Case 1002 : MessBox("Menu","2 Menu Clicked")
End Select
EndIf
If event=EventClose Then End
Loop
Result: Shows message boxes when menu items are clicked.

***
CONSTANT: EventMouseMove
Syntax: #define EventMouseMove &H200
Description: Event constant indicating the mouse cursor has moved within the window's client area. MouseX() and MouseY() give coordinates. EventKey() contains flags for buttons being held down (MK_LBUTTON, MK_MBUTTON, MK_RBUTTON) and modifier keys (MK_CONTROL, MK_SHIFT).
Options: None
Platform: Windows, Linux
Example:
#Include "window9.bi"
OpenWindow("Mouse Move",10,10,200,200)
Do
Var event=WaitEvent()
Select Case event
Case EventClose : Exit Do
Case EventMouseMove
Print "MOUSE: " & MouseX() & "," & MouseY()
If EventKEY() And MK_LBUTTON Then Print " - Left Button Down"
If EventKEY() And MK_SHIFT Then Print " - Shift Down"
End Select
Loop
Result: Prints mouse coordinates and button/key state during mouse movement.

***
CONSTANT: EventMouseWheel
Syntax: #define EventMouseWheel &H20A
Description: Event constant indicating the mouse wheel has been scrolled. EventKey() contains modifier flags (MK_CONTROL, MK_SHIFT, MK_LBUTTON, etc.) and the high word indicates the scroll direction/amount (positive for forward/up, negative for backward/down).
Options: None
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As hwnd hwnd
dim as Long aa
hwnd=OpenWindow("Mouse Wheel",10,10,200,200)
TextGadget(1,10,50,100,20,"Scroll Value: 0")
Do
Var event=WaitEvent()
Select Case event
Case EventClose : Exit Do
Case EventMouseWheel
Dim As Integer iEK = EventKEY()
Dim wheelDelta as Short = HiWord(iEK) // Get scroll amount/direction
Print "Wheel Event. Modifiers: "; LoWord(iEK) ; " Delta: "; wheelDelta
If wheelDelta > 0 Then
aa+=1
ElseIf wheelDelta < 0 Then
aa-=1
EndIf
SetGadgetText(1,"Scroll Value: " & Str(aa))
End Select
Loop
Result: Updates a text gadget with a value that increments/decrements on mouse wheel scroll.

***
FUNCTION: EventNumber
Syntax: Function EventNumber() As Integer
Description: Returns the ID number of the gadget, menu item, or SysTray icon associated with the current event (EventGadget, EventMenu, or SysTray events).
Options: None
Platform: Windows, Linux
Example 1: (Gadgets - See EventClose example)
Example 2: (Menu - See EventMenu example)

***
FUNCTION: EventNumberListView
Syntax: Function EventNumberListView() As Integer
Description: Specifically used within mouse events (EventLBDown, EventRBDown, etc.) to get the ID of the ListViewGadget under the cursor when the event occurred. Use this instead of EventNumber() for ListView mouse events.
Options: None
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var hwnd=OpenWindow("ListView Event",10,10,230,180)
ListViewGadget(1,10,10,150,100) // Gadget ID 1
AddListViewColumn(1, "Column",0,0,150)
AddListViewItem(1,"item 1", 0 ,0,0)
AddListViewItem(1,"item 2", 0 ,1,0)
TextGadget(2,170,20,40,30)
SetGadgetColor(2,255,&hff0000,3)
SetGadgetfont(2,LoadFont("",22))
Do
Var event=WaitEvent()
If Event=EventClose Then End
If event=EventLBDown Then
If EventNumberListView()=1 Then // Check if click was on ListView ID 1
SetGadgetText(2,Str( GetItemListView())) // Get clicked item index
EndIf
EndIf
Loop
Result: Displays the clicked item index in the text gadget when the ListView is clicked.

***
FUNCTION: EventNumberToolBar
Syntax: Function EventNumberToolBar() As Integer
Description: Returns the button ID associated with a toolbar event (usually within EventGadget).
Options: None
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Integer hwToolBar
dim as HWND hwnd
#Ifdef __FB_WIN32__
Var iStyle = TBSTYLE_FLAT Or TBSTYLE_TOOLTIPS // Use defined constant
#Else
Var iStyle = TBSTYLE_TOOLTIPS
#EndIf
hwnd=OpenWindow("Toolbar Event",10,10,185,100)
CenterWindow(hwnd)
hwToolBar=CreateToolBar(,iStyle)
Dim As String sStr(2) = {"Open" , "Cut" , "Copy"}
ToolBarStandardButton(hwToolBar,1,STD_FILEOPEN,sStr(0)) // Button ID 1
ToolBarStandardButton(hwToolBar,2,STD_CUT, sStr(1)) // Button ID 2
ToolBarStandardButton(hwToolBar,3,STD_COPY, sStr(2)) // Button ID 3
ToolBarToolTip(hwnd,1,sStr(0))
ToolBarToolTip(hwnd,2,sStr(1))
ToolBarToolTip(hwnd,3,sStr(2))
Do
Var ev=WaitEvent()
If ev=EventClose Then End
ElseIf ev=EventGadget Then // Toolbar events come as Gadget events
Select Case EventNumberToolBar() // Get the specific toolbar button ID
Case 1 To 3 : MessBox("Toolbar","Button Number " & EventNumberToolBar())
End Select
EndIf
Loop
Result: Shows a message box indicating which toolbar button was clicked.

***
FUNCTION: EventNumberTreeView
Syntax: Function EventNumberTreeView() As Integer
Description: Specifically used within mouse events (EventLBDown, EventRBDown, etc.) to get the ID of the TreeViewGadget under the cursor when the event occurred. Use this instead of EventNumber() for TreeView mouse events.
Options: None
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Integer event
Dim As HWND hwnd,tree
#Ifdef __FB_WIN32__
Var iStyle = TVS_HASLINES or TVS_HASBUTTONS or TVS_LINESATROOT
#Else
Var iStyle = 0
#EndIf
hwnd=OpenWindow("TreeView Event",10,10,180,200) : CenterWindow(hwnd)
Dim As HBITMAP hbmp = Load_image("1.png")
Dim As HBITMAP hbmp1 = Load_image("2.png")
tree=TreeViewGadget(1,10,10,140,140,iStyle , 0 ,32) // Gadget ID 1
Var Pos_=AddTreeViewItem(1,"1",hbmp,hbmp1,TVI_FIRST)
AddTreeViewItem(1,"1-1",hbmp,hbmp1,TVI_FIRST,Pos_)
Pos_=AddTreeViewItem(1,"2",hbmp,hbmp1,Pos_)
AddTreeViewItem(1,"2-1",hbmp,hbmp1,TVI_FIRST,Pos_)
Do
event=waitevent()
If event=EventClose Then End
If event=eventLBDOWN Then
If EventNumberTreeView()=1 Then // Check if click was on TreeView ID 1
Print GetItemTreeView(1) // Get clicked item handle (TVI_...)
EndIf
EndIf
Loop
Result: Prints the handle of the clicked TreeView item to the console.

***
CONSTANT: EventRBDown
Syntax: #define EventRBDown &H204
Description: Event constant indicating the right mouse button has been pressed down. EventKey() may contain modifier flags.
Options: None
Platform: Windows, Linux
Example: (See EventLBDown example)

***
CONSTANT: EventRBUp
Syntax: #define EventRBUp &H205 // Note: Original help had typo (&H205 matches standard WM_RBUTTONUP)
Description: Event constant indicating the right mouse button has been released. EventKey() may contain modifier flags.
Options: None
Platform: Windows, Linux
Example: (See EventLBDown example)

***
CONSTANT: EventSize
Syntax: #Define EventSize &h5
Description: Event constant indicating that a window has been resized. Use w9SizeWidth() and w9SizeHeight() to get the new client area dimensions.
Options: None
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As hwnd hwnd
hwnd=OpenWindow("Resize Test",10,10,200,200)
TextGadget(1,10,10,150,30,"Resize the window.")
Do
Var event=WaitEvent()
Select Case event
Case EventClose : Exit Do
Case EventSize
Print "New Size: "; w9SizeWidth() & " x " & w9SizeHeight()
End Select
Loop
Result: Prints the new client area dimensions to the console whenever the window is resized.

***
FUNCTION: w9SizeHeight
Syntax: Function w9SizeHeight() As Integer
Description: Returns the new height of the window's client area after an EventSize event has occurred.
Options: None
Platform: Windows, Linux
Example: (See EventSize example, or example using timer)
#Include "window9.bi"
Dim As hwnd hwnd
hwnd=OpenWindow("Resize Test",10,10,200,200)
TextGadget(1,10,10,150,30,"Resize the window. ")
function rr() As Integer
Static As Integer aa,bb
If aa <> w9SizeWidth() Or bb<>w9SizeHeight() then // Check if size changed
Print "Timer Check: "; w9SizeWidth() & " " & w9SizeHeight()
aa=w9SizeWidth() : bb=w9SizeHeight()
EndIf
Return TRUE
End Function
SetTimer(hwnd,1,15,Cast(Any Ptr,@rr)) // Check periodically
Do
Var event=WaitEvent()
Select Case event
Case EventClose : Exit Do
End Select
Loop
Result: Prints new dimensions periodically if the window is resized.

***
FUNCTION: w9SizeWidth
Syntax: Function w9SizeWidth() As Integer
Description: Returns the new width of the window's client area after an EventSize event has occurred.
Options: None
Platform: Windows, Linux
Example: (See EventSize and w9SizeHeight examples)

***
FUNCTION: SetTimer
Syntax: function SetTimer(hwnd as HWND, idEvent as Uinteger, uElapse as Uinteger, lpTimerFunc as any ptr) as Uinteger
Description: Creates a timer associated with a specific window. Returns a timer ID if successful, 0 otherwise. Use KillTimer to destroy the timer.
Options:
hwnd - Handle of the window to receive timer messages or associate the callback with.
idEvent - A non-zero timer identifier.
uElapse - Timeout interval in milliseconds. Minimum advisable value on Linux is ~5ms.
lpTimerFunc - Pointer to a callback function (TimerProc) to be called when the timer elapses. If 0, WM_TIMER messages (EventTimer) are sent to the window's event loop (WaitEvent/WindowEvent). Using a callback function is generally recommended. Callback prototype: Function MyTimerProc() As Integer (return TRUE to continue timer, FALSE might affect behavior depending on OS/implementation details - usually ignored, use KillTimer to stop).
Platform: Windows, Linux
Example: (Using callback)
#Include "window9.bi"
Dim As Integer event
Dim Shared As HWND hwnd
Function setText() As Integer
Dim As String sz = "CAPTION"
Static As Long i , j
If i = Len(sz) Then j = 1 ElseIf i = 0 Then j = 0 EndIf // Cycle index
If j = 0 Then i+=1 Else i-=1 EndIf
SetWindowText(hwnd,Left(sz,i)) // Update window title
Return TRUE // Keep timer running
End Function
hwnd = OpenWindow("",300,10,250,100)
ButtonGadget(1,10,10,150,30,"Disable timer")
SetTimer(hwnd,1,100,Cast(Any Ptr,@setText)) // Timer ID 1, 100ms interval
Do
event=WaitEvent()
If event=EventClose Then Exit Do
ElseIf event = eventgadget Then
If EventNumber() = 1 Then KillTimer(hwnd,1) // Stop timer on button click
EndIf
Loop
Result: Window title animates "C", "CA", "CAP", ..., "CAPTION", ..., "CAP", "CA", "C", ... until button is clicked.

***
FUNCTION: KillTimer
Syntax: function KillTimer(hwnd as HWND, IDEvent as Uinteger) as Bool
Description: Destroys the specified timer associated with the window. Returns non-zero on success.
Options:
hwnd - Handle of the window the timer is associated with.
IDEvent - The identifier of the timer to destroy (same as used in SetTimer).
Platform: Windows, Linux
Example: (See SetTimer example)

***
CONSTANT: EventTimer
Syntax: #Define EventTimer &H113
Description: Event constant indicating a timer set with lpTimerFunc=0 has elapsed. EventNumber() contains the timer ID (idEvent from SetTimer).
Options: None
Platform: Windows, Linux
Example: (Using event loop)
#Include "window9.bi"
Dim As hwnd hwnd,hwnd2
hwnd=OpenWindow("Timer 1",10,10,200,200)
hwnd2=OpenWindow("Timer 2",220,10,200,200)
SetTimer(hwnd,1,1200,0) // Timer ID 1 for window hwnd
SetTimer(hwnd2,2,1700,0) // Timer ID 2 for window hwnd2
Do
Var event=WindowEvent() // Use WindowEvent or WaitEvent
Select Case event
Case EventClose : Exit Do
Case EventTimer
Select Case EventNumber() // Check which timer fired
Case 1
WindowColor(hwnd,BGR(0,255,0)) : WindowColor(hwnd2,BGR(0,0,255))
Case 2
WindowColor(hwnd,BGR(0,0,255)) : WindowColor(hwnd2,BGR(255,0,0))
End Select
End Select
sleep(1)
Loop
Result: The two windows periodically change color based on their respective timers.

***
FUNCTION: EventWParam
Syntax: Function EventWParam() As WPARAM
Description: Returns the WPARAM value associated with the current window message. For mouse events, often contains flags indicating which keys/buttons were held down (MK_CONTROL, MK_SHIFT, MK_LBUTTON, etc.).
Options: None
Platform: Windows
Example:
#Include "window9.bi"
Dim As Integer event
CenterWindow(OpenWindow("WParam Test",10,10,500,500))
Do
event=WindowEvent()
If event=EventLBDOWN Then
Print "LBUTTONDOWN - WParam (Key Flags):"; EventWParam()
' Key flags: MK_CONTROL, MK_LBUTTON, MK_MBUTTON, MK_RBUTTON, MK_SHIFT
EndIf
If Event=EventClose Then End
Loop
Result: Prints the WPARAM value (key/button state flags) when the left mouse button is pressed.

***
FUNCTION: WaitEvent
Syntax: Function WaitEvent() As Long
Description: Waits for the next event to occur in the application and returns the event code. The program loop pauses until an event happens, reducing CPU usage compared to WindowEvent.
Options: None
Platform: Windows, Linux
Example: (See EventClose example)

***
FUNCTION: WindowEvent
Syntax: Function WindowEvent() As Long
Description: Checks for pending events and returns the event code if one occurred, otherwise returns 0. The program loop continues to run even if no event occurs. Can lead to high CPU usage if not paired with Sleep or similar delay mechanism.
Options: None
Platform: Windows, Linux
Example:
#Include "window9.bi"
OpenWindow("WindowEvent Test",10,10,200,200)
ButtonGadget(1,10,10,100,20, "Button")
TextGadget(2,10,50,100,20,"Text")
Do
Var event=WindowEvent() // Poll for events
Sleep(15) // IMPORTANT: Add sleep to prevent 100% CPU usage
Select Case event
Case EventClose : End // Exit loop on close
Case EventGadget
Select Case EventNumber()
Case 1 : MessBox("Event","Button Clicked")
Case 2 : MessBox("Event","Text Gadget Clicked")
End Select
End Select
Loop
Result: Standard window behavior, responds to events without consuming excessive CPU.

--- SECTION: Dialog ---
Description: Pre-built dialog boxes for common tasks.

***
FUNCTION: FontRequester
Syntax: function FontRequester(byval hwnd As HWND = 0, byval nColor As Integer = 0) As Integer ' Returns HFONT handle
Description: Opens a standard system dialog for selecting a font. Returns the HFONT handle of the selected font. After calling, use SelectedFontName(), SelectedFontColor() (Win only), SelectedFontSize(), SelectedFontStyle() to get specific properties.
Options:
hwnd - Parent window handle for the dialog.
nColor - (Windows only) Initial color selected in the dialog.
Platform: Windows, Linux
Example:
#Include "window9.bi"
OpenWindow("Font Requester",10,10,200,200)
Var font = FontRequester()
If font Then
Print "Selected Font Name: "; SelectedFontName()
Print "Selected Font Size: "; SelectedFontSize()
' Print "Selected Font Color (Win): "; SelectedFontColor() ' Windows only
Print "Is Italic?: "; SelectedFontStyle(2)
SetGadgetFont(,font) // Set as default for subsequent gadgets
ButtonGadget(1,10,10,100,20,"Button")
' FreeFont(font) ' Free font when no longer needed
Else
Print "Font selection cancelled."
EndIf
Do
Var event=WaitEvent()
Select Case event
Case EventClose : Exit Do
End Select
Loop
Result: Opens a font dialog. Prints selected font info to console. Button uses selected font.

***
FUNCTION: InputBox
Syntax: Function InputBox(ByRef Caption As String="", ByRef Message As String="Enter text:", ByRef DefaultString As String="", ByVal flag As Integer=0, ByVal flag2 As Integer=0, hParentWin as Hwnd = 0) As String
Description: Displays a simple dialog box to get text input from the user. Returns the entered string or an empty string if cancelled.
Options:
Caption - Text for the dialog window title bar.
Message - Prompt message displayed above the input field.
DefaultString - Initial text displayed in the input field.
flag - (Windows only) Style flags for the input field (e.g., ES_PASSWORD, ES_NUMBER, ES_MULTILINE, ES_CENTER - see original doc for full list).
flag2 - If non-zero, the DefaultString is automatically selected/cleared when the user starts typing.
hParentWin - Parent window handle for the dialog.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As String userInput
userInput = InputBox("Input Needed", "Please enter your name:", "Default Name", 0, 1)
If userInput <> "" Then
MessBox("Input Received", "You entered: " & userInput)
Else
MessBox("Input Cancelled", "No input was provided.")
EndIf
Sleep(1000)
Result: Displays an input dialog and then a message box with the result.

***
FUNCTION: MessBox / MsgBox
Syntax (Cross-Platform): Function MessBox(ByRef Caption As String, ByRef Message As String, ByVal flag As Integer=0,ByVal ParentWin as Hwnd = 0) As Integer
Syntax (Windows Only): Function MsgBox(ByRef Caption As String, ByRef Message As String, ByVal flag As Integer=0,ByVal ParentWin as Hwnd = 0) As Integer
Description: Displays a standard message box with text, optional icons, and buttons. Returns a value indicating which button was pressed (e.g., IDYES, IDNO, IDCANCEL, IDOK). Use MessBox for cross-platform compatibility.
Options:
Caption - Text for the message box title bar.
Message - The main text message to display.
flag - Combination of flags to control buttons, icons, default button, and modality.
- Buttons (Combine one): MB_OK (default), MB_OKCANCEL, MB_YESNO, MB_YESNOCANCEL, MB_RETRYCANCEL (Win), MB_ABORTRETRYIGNORE (Win).
- Icons (Combine one, optional): MB_ICONINFORMATION, MB_ICONQUESTION, MB_ICONEXCLAMATION, MB_ICONSTOP.
- Default Button (Combine one, optional, Win only): MB_DEFBUTTON1, MB_DEFBUTTON2, MB_DEFBUTTON3, MB_DEFBUTTON4.
- Modality (Combine one, optional, Win only): MB_APPLMODAL, MB_SYSTEMMODAL, MB_TASKMODAL.
- Other (Combine as needed, Win only): MB_HELP, MB_RIGHT, MB_RTLREADING, MB_SETFOREGROUND, MB_TOPMOST, etc.
ParentWin - Parent window handle. Recommended on Linux/GTK3 to avoid warnings.
Platform: Windows, Linux (Linux supports basic button/icon combinations)
Example:
#Include "window9.bi"
Dim As Integer result
result = MessBox("Question?", "Do you want to proceed?", MB_YESNO Or MB_ICONQUESTION)
If result = IDYES Then
MessBox("Result", "You clicked Yes.")
ElseIf result = IDNO Then
MessBox("Result", "You clicked No.")
End If
Result: Displays a question message box with Yes/No buttons, then a result box.

***
FUNCTION: NextSelectedFilename
Syntax: Function NextSelectedFilename() As String
Description: Used after calling OpenFileRequester with the OFN_ALLOWMULTISELECT flag to retrieve subsequent selected filenames when multiple files are chosen. Returns an empty string when no more files are available in the selection.
Options: None
Platform: Windows, Linux
Example:
#Include "window9.bi"
#ifdef UNICODE
// For Unicode, use "|" as separator in pattern if needed, but not required for OFN flags.
Var Pattern = "Text files (*.txt, *.ini, *.doc)|*.txt;*.ini;*.doc|"
#else
Var Pattern = "Text files (*.txt, *.ini, *.doc)"+Chr(0)+"*.txt;*.ini;*.doc"+Chr(0)+Chr(0)
#EndIf
Var firstFile = OpenFileRequester("Select Files","C:\", Pattern ,OFN_ALLOWMULTISELECT)
If firstFile <> "" Then
Print "Selected:"
Print firstFile // Print the first file path (might be directory if multiple selected)
Dim As String nextFile = firstFile
While nextFile <> ""
nextFile = NextSelectedFilename() // Get subsequent files
If nextFile <> "" Then Print nextFile
Wend
EndIf
Sleep(2000)
Result: Opens a file dialog allowing multiple selections. Prints the selected file paths to the console.

***
FUNCTION: OpenFileRequester
Syntax: Function OpenFileRequester(ByRef Title As String, ByRef curentdir As String, ByRef Pattern As String = "All files(*.*)|*.*|", ByVal flag As Integer=0, ByRef templateName As String = "", ByVal hParentWin as HWND = 0) As String
Description: Opens a standard system dialog box for selecting one or more files to open. Returns the full path of the selected file(s).
Options:
Title - Text for the dialog window title bar.
curentdir - Initial directory displayed in the dialog.
Pattern - File filter pattern string. Format: "Description1|*.ext1;*.ext2|Description2|*.ext3|" (UNICODE) or "Description1"+Chr(0)+"*.ext1;*.ext2"+Chr(0)+"Description2"+Chr(0)+"*.ext3"+Chr(0)+Chr(0) (ASCII).
flag - Dialog flags:
- Common: OFN_ALLOWMULTISELECT (allow multiple file selection).
- Linux Only: OFN_DIRECTORY (select folders instead of files).
- Windows Only: OFN_CREATEPROMPT, OFN_ENABLEHOOK, OFN_ENABLETEMPLATE*, OFN_EXTENSIONDIFFERENT, OFN_FILEMUSTEXIST, OFN_HIDEREADONLY, OFN_LONGNAMES, OFN_NOCHANGEDIR, OFN_NODEREFERENCELINKS, OFN_NOLONGNAMES, OFN_NONETWORKBUTTON, OFN_NOREADONLYRETURN, OFN_NOTESTFILECREATE, OFN_NOVALIDATE, OFN_OVERWRITEPROMPT, OFN_PATHMUSTEXIST, OFN_READONLY, OFN_SHAREAWARE, OFN_SHOWHELP.
templateName - (Windows only) Default filename to display initially.
hParentWin - Parent window handle.
Platform: Windows, Linux
Example 1: (Multiple Selection - See NextSelectedFilename example)
Example 2: (Single Selection)
#Include "window9.bi"
#ifdef UNICODE
Var Pattern = "Text files (*.txt, *.ini, *.doc)|*.txt;*.ini;*.doc|"
#else
Var Pattern = "Text files (*.txt, *.ini, *.doc)"+Chr(0)+"*.txt;*.ini;*.doc"+Chr(0)+Chr(0)
#EndIf
Dim As String selectedFile
selectedFile = OpenFileRequester("Open File","C:\", Pattern)
If selectedFile <> "" Then
MessBox("File Selected", selectedFile)
Else
MessBox("Cancelled", "No file selected.")
EndIf
Sleep(1000)
Result: Opens a file dialog; displays the selected file path in a message box.

***
FUNCTION: SaveFileRequester
Syntax: Function SaveFileRequester(ByRef Title As String, ByRef Curentdir As String, ByRef Pattern As String = "All files(*.*)|*.*|", ByVal Defaultsetpattern As bool=0, ByRef TemplateName As String = "", ByVal hParentWin as HWND = 0) As String
Description: Opens a standard system dialog box for selecting a filename and path to save a file. Returns the full path entered/selected by the user.
Options:
Title - Text for the dialog window title bar.
Curentdir - Initial directory displayed in the dialog.
Pattern - File filter pattern string (see OpenFileRequester for format).
Defaultsetpattern - (Windows only) If 1, automatically appends the default extension from the selected filter if the user doesn't provide one.
TemplateName - Default filename to display initially.
hParentWin - Parent window handle.
Platform: Windows, Linux
Example:
#Include "window9.bi"
#ifdef UNICODE
Var Pattern = "Text files (*.txt)|*.txt|All Files (*.*)|*.*|"
#else
Var Pattern = "Text files (*.txt)"+Chr(0)+"*.txt"+Chr(0)+"All Files (*.*)"+Chr(0)+"*.*"+Chr(0)+Chr(0)
#EndIf
Dim As String savePath
savePath = SaveFileRequester("Save As","C:\", Pattern, 1, "default.txt")
If savePath <> "" Then
MessBox("Save Path", savePath)
Else
MessBox("Cancelled", "Save operation cancelled.")
EndIf
Sleep(1000)
Result: Opens a save file dialog; displays the chosen path in a message box.

***
FUNCTION: ShellFolder
Syntax: Function ShellFolder(byRef NameDialog as string, ByRef DefaultFolder as String, ByVal FlagOption As Integer=BIF_RETURNONLYFSDIRS Or BIF_USENEWUI, ByVal hParentWin as HWND = 0) as String
Description: Opens a Windows Shell dialog box specifically for selecting folders. Returns the selected folder path.
Options:
NameDialog - Title/prompt displayed in the dialog.
DefaultFolder - Initial folder selected when the dialog opens.
FlagOption - Flags controlling the dialog's behavior (e.g., BIF_RETURNONLYFSDIRS, BIF_USENEWUI, BIF_BROWSEFORCOMPUTER - see original doc for more).
hParentWin - Parent window handle.
Platform: Windows
Example:
#Include "Window9.bi"
Dim As String selectedFolder
selectedFolder = ShellFolder( "Select Installation Folder", "C:\Program Files")
If selectedFolder <> "" Then
MessBox("Folder Selected", selectedFolder)
Else
MessBox("Cancelled", "No folder selected.")
EndIf
sleep(1000)
Result: Opens a folder selection dialog; displays the result.

--- SECTION: File ---
Description: Basic functions for creating, opening, reading from, and writing to files using handles.

***
SUB: Close_File
Syntax: Sub Close_File(Byref H As HANDLE)
Description: Closes a file previously opened with Create_File, Open_File, or Read_File, releasing the file handle.
Options:
H - File handle to close.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var handle=Create_File("Example.txt")
If handle <> Cast(Any Ptr,-1) Then
Write_Byte(handle,56)
Write_Byte(handle,47)
Close_file(handle) // Close the file
Else
Print "Error creating file."
EndIf
// Example reopening (optional):
handle=Read_file("Example.txt")
If handle <> Cast(Any Ptr,-1) Then
Print "Read after reopen: "; Read_Byte(handle)
Close_file(handle)
Else
Print "Error reopening file."
EndIf
Sleep(1000)
Result: (Creates Example.txt with bytes 56, 47. Console output shows 56 if reopen succeeds).

***
FUNCTION: Create_File
Syntax: Function Create_File(ByRef FileName As String,ByVal flag As Integer=FILE_ATTRIBUTE_NORMAL) As HANDLE
Description: Creates a new file for reading and writing. If the file exists, it is overwritten. Returns a file handle or -1 (casted to Any Ptr) on failure.
Options:
FileName - Full path and name of the file to create.
flag - (Windows only) File attributes and flags (e.g., FILE_ATTRIBUTE_HIDDEN, FILE_FLAG_DELETE_ON_CLOSE - see original doc for extensive list). Default is FILE_ATTRIBUTE_NORMAL.
Platform: Windows, Linux
Example: (See Close_File example)

***
FUNCTION: E_O_F (End Of File)
Syntax: Function E_O_F(ByVal fileHandle As HANDLE) As Long
Description: Checks if the end of the file has been reached during read operations. Returns 1 if EOF is reached, 0 otherwise.
Options:
fileHandle - Handle of the file being read.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var handle=Create_File("Example.txt")
If handle <> Cast(Any Ptr,-1) Then Write_String(handle,"FB") : Close_file(handle)
handle=Read_file("Example.txt")
If handle <> Cast(Any Ptr,-1) Then
While E_O_F(handle)=0 // Loop until end of file
Print Read_Character(handle)
wend
Close_file(handle)
EndIf
Sleep(1000)
Result:
F
B

***
FUNCTION: Get_File_Pointer
Syntax: Function Get_File_Pointer(ByVal fileHandle As HANDLE) As Integer ' Should likely be Long or LongInt for large files
Description: Returns the current position (offset in bytes from the beginning) of the file pointer.
Options:
fileHandle - Handle of the open file.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var handle=Create_File("Example.txt")
If handle <> Cast(Any Ptr, -1) Then
Write_StringN(handle,"Line1")
Write_StringN(handle,"Line2")
Close_file(handle)
EndIf
handle=Read_file("Example.txt")
If handle <> Cast(Any Ptr, -1) Then
Print Read_string(handle) // Read "Line1" + newline
Print "Pointer after reading Line1: "; Get_File_Pointer(Handle)
Set_File_Pointer(Handle, 0, FILE_BEGIN) // Seek back to beginning (using constant)
Print "Pointer after seeking to start: "; Get_File_Pointer(Handle)
Print Read_string(handle); // Read "Line1" again
Print Read_string(handle) // Read "Line2"
Close_file(handle)
EndIf
sleep(1000)
Result: (Shows pointer positions after reads/seeks)

***
FUNCTION: Open_File
Syntax: Function Open_File(ByRef FileName As String,ByVal flag As Integer=FILE_ATTRIBUTE_NORMAL) As HANDLE
Description: Opens an existing file for reading and writing. If the file doesn't exist, it creates it. Returns a file handle or -1 (casted to Any Ptr) on failure.
Options:
FileName - Full path and name of the file to open/create.
flag - (Windows only) File attributes and flags (see Create_File for list).
Platform: Windows, Linux
Example: (Similar to Create_File, but doesn't explicitly overwrite)
#Include "window9.bi"
Var handle=Open_File("Example.txt") // Open or create
If handle <> Cast(Any Ptr,-1) Then
Write_Byte(handle,56)
Set_File_Pointer(handle, 0, FILE_BEGIN) // Go to start to read back
Print "Read byte: "; Read_Byte(handle)
Close_file(handle)
EndIf
Sleep(1000)
Result: (Creates/opens Example.txt, writes 56, reads it back. Console shows 56).

***
FUNCTION: Read_Byte
Syntax: Function Read_Byte(ByVal fileHandle As HANDLE) As Byte
Description: Reads a single byte from the current file pointer position and advances the pointer.
Options:
fileHandle - Handle of the open file.
Platform: Windows, Linux
Example: (See Close_File example)

***
FUNCTION: Read_Character
Syntax: Function Read_Character(ByVal fileHandle As HANDLE) As String
Description: Reads a single character (1 byte) from the current file pointer position and returns it as a string. Advances the pointer. Assumes single-byte encoding.
Options:
fileHandle - Handle of the open file.
Platform: Windows, Linux
Example: (See E_O_F example)

***
SUB: Read_Data
Syntax: sub Read_Data(ByVal fileHandle As HANDLE,ByRef pMemory As Byte ptr ,ByVal Lenght As Integer)
Description: Reads a specified number of bytes from the file into a pre-allocated memory buffer.
Options:
fileHandle - Handle of the open file.
pMemory - Pointer to the destination memory buffer. Must be large enough to hold 'Lenght' bytes.
Lenght - Number of bytes to read.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Byte Ptr data_buffer
Var handle=Create_File("Example.txt")
If handle <> Cast(Any Ptr, -1) Then Write_String(handle,"FreeBasic") : Close_File(handle)
handle=Read_file("Example.txt")
If handle <> Cast(Any Ptr, -1) Then
Dim dataSize As Long = Size_File(handle)
If dataSize > 0 Then
data_buffer=Allocate(dataSize) // Allocate buffer
Read_Data(handle, data_buffer, dataSize) // Read into buffer
For a As Integer=0 To dataSize-1
Print Chr(data_buffer[a]) // Print characters
Next
DeAllocate(data_buffer) // Free buffer
EndIf
Close_File(handle)
EndIf
Sleep(1000)
Result: (Prints characters F r e e B a s i c)

***
FUNCTION: Read_DataA
Syntax: Function Read_DataA(ByVal fileHandle As HANDLE, ByVal Lenght As Integer) As Byte Ptr
Description: Reads a specified number of bytes from the file, allocates memory for it, and returns a pointer to the allocated buffer. The caller must free this memory using DeAllocate.
Options:
fileHandle - Handle of the open file.
Lenght - Number of bytes to read and allocate.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Byte Ptr data_ptr
Var handle=Create_File("Example.txt")
If handle <> Cast(Any Ptr, -1) Then Write_String(handle,"FreeBasic") : Close_File(handle)
handle=Read_file("Example.txt")
If handle <> Cast(Any Ptr, -1) Then
Dim dataSize As Long = Size_File(handle)
If dataSize > 0 Then
data_ptr=Read_DataA(handle, dataSize) // Read and allocate
If data_ptr Then
For a As Integer=0 To dataSize-1
Print data_ptr[a] // Print byte values
Next
DeAllocate(data_ptr) // Free allocated memory
EndIf
EndIf
Close_File(handle)
EndIf
Sleep(1000)
Result: (Prints ASCII values for F, r, e, e, B, a, s, i, c)

***
FUNCTION: Read_DataS
Syntax: Function Read_DataS(ByVal fileHandle As HANDLE, ByVal Lenght As Integer) As Byte Ptr
Description: Reads a specified number of bytes, allocates memory (Length + 1 byte), adds a null terminator, and returns a pointer suitable for use with string functions like PeekS. Caller must free memory using DeAllocate.
Options:
fileHandle - Handle of the open file.
Lenght - Number of bytes to read (excluding null terminator).
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Byte Ptr data_ptr
Var handle=Create_File("Example.txt")
If handle <> Cast(Any Ptr, -1) Then Write_String(handle,"FreeBasic") : Close_file(handle)
handle=Read_file("Example.txt")
If handle <> Cast(Any Ptr, -1) Then
Dim dataSize As Long = Size_File(handle)
If dataSize > 0 Then
data_ptr=Read_DataS(handle, dataSize) // Read and allocate (+null)
If data_ptr Then
Print PeekS(data_ptr) // Print as string
DeAllocate(data_ptr) // Free allocated memory
EndIf
EndIf
Close_file(handle)
EndIf
Sleep(1000)
Result: FreeBasic

***
FUNCTION: Read_Double
Syntax: Function Read_Double(ByVal fileHandle As HANDLE) As Double
Description: Reads an 8-byte double-precision floating-point number from the current file pointer position.
Options:
fileHandle - Handle of the open file.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var handle=Create_File("Example.txt")
If handle <> Cast(Any Ptr, -1) Then Write_Double(handle, 123.456789) : Close_file(handle)
handle=Read_file("Example.txt")
If handle <> Cast(Any Ptr, -1) Then Print Read_Double(handle) : Close_file(handle)
Sleep(1000)
Result: 123.456789

***
FUNCTION: Read_File
Syntax: Function Read_File(ByRef FileName As String,ByVal flag As Integer=FILE_ATTRIBUTE_NORMAL) As HANDLE
Description: Opens an existing file for reading only. Returns a file handle or -1 (casted to Any Ptr) if the file doesn't exist or cannot be opened.
Options:
FileName - Full path and name of the file to open.
flag - (Windows only) File attributes and flags (see Create_File for list - primarily relevant attributes like FILE_FLAG_SEQUENTIAL_SCAN might be useful here).
Platform: Windows, Linux
Example: (See Close_File example's reopening part)

***
FUNCTION: Read_Integer
Syntax: Function Read_Integer(ByVal fileHandle As HANDLE) As Long ' Assuming Long is 32-bit Integer
Description: Reads a 4-byte signed integer from the current file pointer position.
Options:
fileHandle - Handle of the open file.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var handle=Create_File("Example.txt")
If handle <> Cast(Any Ptr, -1) Then Write_Integer(handle, 123456) : Close_file(handle)
handle=Read_file("Example.txt")
If handle <> Cast(Any Ptr, -1) Then Print Read_Integer(handle) : Close_file(handle)
Sleep(1000)
Result: 123456

***
FUNCTION: Read_LONGINT
Syntax: Function Read_LongInt(ByVal fileHandle As HANDLE) As LongInt ' Assuming LongInt is 64-bit Integer
Description: Reads an 8-byte signed integer (LongInt) from the current file pointer position.
Options:
fileHandle - Handle of the open file.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var handle=Create_File("Example.txt")
If handle <> Cast(Any Ptr, -1) Then Write_LONGINT(handle, 9876543210) : Close_file(handle)
handle=Read_file("Example.txt")
If handle <> Cast(Any Ptr, -1) Then Print Read_LONGINT(handle) : Close_file(handle)
Sleep(1000)
Result: 9876543210

***
FUNCTION: Read_Single
Syntax: Function Read_Single(ByVal fileHandle As HANDLE) As Single
Description: Reads a 4-byte single-precision floating-point number from the current file pointer position.
Options:
fileHandle - Handle of the open file.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var handle=Create_File("Example.txt")
If handle <> Cast(Any Ptr, -1) Then Write_Single(handle, 123.456) : Close_file(handle)
handle=Read_file("Example.txt")
If handle <> Cast(Any Ptr, -1) Then Print Read_Single(handle) : Close_file(handle)
Sleep(1000)
Result: 123.456

***
FUNCTION: Read_String
Syntax: Function Read_String(ByVal fileHandle As HANDLE) As String
Description: Reads a line of text from the file, up to a newline character (CR/LF or LF). Newline characters are not included in the returned string. Advances the file pointer past the newline.
Options:
fileHandle - Handle of the open file.
Platform: Windows, Linux
Example: (See Write_StringN example)

***
FUNCTION: Read_WORD
Syntax: Function Read_Word(ByVal fileHandle As HANDLE) As Short ' Assuming Short is 16-bit WORD
Description: Reads a 2-byte signed integer (Short/Word) from the current file pointer position.
Options:
fileHandle - Handle of the open file.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var handle=Create_File("Example.txt")
If handle <> Cast(Any Ptr, -1) Then Write_Word(handle, 12345) : Close_File(handle)
handle=Read_file("Example.txt")
If handle <> Cast(Any Ptr, -1) Then Print Read_Word(handle) : Close_file(handle)
sleep(1000)
Result: 12345

***
SUB: Set_File_Pointer
Syntax: sub Set_File_Pointer(ByVal fileHandle As HANDLE,ByVal Pos As LongInt, ByVal flag As Integer=FILE_CURRENT) ' Use LongInt for Pos
Description: Sets the file pointer to a new position within the file.
Options:
fileHandle - Handle of the open file.
Pos - The offset (in bytes) to move the pointer. Can be positive (forward) or negative (backward).
flag - Starting point for the offset: FILE_BEGIN (0, from start), FILE_CURRENT (1, from current position), FILE_END (2, from end of file).
Platform: Windows, Linux
Example: (See Get_File_Pointer example)

***
FUNCTION: Size_File
Syntax: Function Size_File(ByVal fileHandle As HANDLE) As LongInt ' Should be LongInt for large files
Description: Returns the total size of the open file in bytes.
Options:
fileHandle - Handle of the open file.
Platform: Windows, Linux
Example: (See Read_DataS example)

***
SUB: Write_Byte
Syntax: sub Write_Byte(ByVal fileHandle As HANDLE, ByVal value As Byte)
Description: Writes a single byte to the file at the current file pointer position.
Options:
fileHandle - Handle of the open file.
value - The byte value to write.
Platform: Windows, Linux
Example: (See Close_File example)

***
SUB: Write_Character
Syntax: sub Write_Character(ByVal fileHandle As HANDLE, ByVal value As String)
Description: Writes the first byte of a string (treated as a single character) to the file. Assumes single-byte encoding.
Options:
fileHandle - Handle of the open file.
value - The string containing the character to write (only the first byte is used).
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var handle=Create_File("Example.txt")
If handle <> Cast(Any Ptr, -1) Then
Write_Character(handle,"R")
Close_file(handle)
EndIf
handle=Read_file("Example.txt")
If handle <> Cast(Any Ptr, -1) Then
Print Read_Character(handle)
Close_file(handle)
EndIf
Sleep(1000)
Result: R

***
SUB: Write_Data
Syntax: Sub Write_Data(ByVal Handle As HANDLE, ByVal pAddress As Any Ptr, ByVal Lenght As Long)
Description: Writes a specified number of bytes from a memory buffer to the file.
Options:
Handle - Handle of the open file.
pAddress - Pointer to the source memory buffer.
Lenght - Number of bytes to write from the buffer.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim adf(0 to 100) As Long ' Array of Longs (4 bytes each on 32-bit)
For a As Long=0 To 100 : adf(a)=a : Next
Var handle=Create_File("Example.txt")
If handle <> Cast(Any Ptr, -1) Then
Write_Data(handle,@adf(0),SizeOf(adf)) // Write the whole array
Close_file(handle)
EndIf
// Verification (optional)
handle=Read_file("Example.txt")
If handle <> Cast(Any Ptr, -1) Then
Dim check_adf(0 to 100) As Long
Read_Data(handle, @check_adf(0), SizeOf(check_adf))
Print "Read back first value: "; check_adf(0)
Print "Read back last value: "; check_adf(100)
Close_file(handle)
EndIf
Sleep(1000)
Result: (Console output shows 0 and 100 if verification added)

***
SUB: Write_Double
Syntax: sub Write_Double(ByVal fileHandle As HANDLE, ByVal value As Double)
Description: Writes an 8-byte double-precision floating-point number to the file.
Options:
fileHandle - Handle of the open file.
value - The double value to write.
Platform: Windows, Linux
Example: (See Read_Double example)

***
SUB: Write_Integer
Syntax: sub Write_Integer(ByVal fileHandle As HANDLE, ByVal value As Long) ' Assuming Long is 32-bit Integer
Description: Writes a 4-byte signed integer to the file.
Options:
fileHandle - Handle of the open file.
value - The integer value to write.
Platform: Windows, Linux
Example: (See Read_Integer example)

***
SUB: Write_Longint
Syntax: sub Write_Longint(ByVal fileHandle As HANDLE, ByVal value As Longint) ' Assuming LongInt is 64-bit Integer
Description: Writes an 8-byte signed integer (LongInt) to the file.
Options:
fileHandle - Handle of the open file.
value - The LongInt value to write.
Platform: Windows, Linux
Example: (See Read_LONGINT example)

***
SUB: Write_Single
Syntax: sub Write_Single(ByVal fileHandle As HANDLE, ByVal value As Single)
Description: Writes a 4-byte single-precision floating-point number to the file.
Options:
fileHandle - Handle of the open file.
value - The single value to write.
Platform: Windows, Linux
Example: (See Read_Single example)

***
SUB: Write_String
Syntax: sub Write_String(ByVal fileHandle As HANDLE, ByVal value As string)
Description: Writes the contents of a string (excluding any null terminator) to the file.
Options:
fileHandle - Handle of the open file.
value - The string value to write.
Platform: Windows, Linux
Example: (See E_O_F example)

***
SUB: Write_StringN
Syntax: sub Write_StringN(ByVal fileHandle As HANDLE, ByVal value As string)
Description: Writes the contents of a string to the file, followed by a platform-specific newline sequence (CR+LF on Windows, LF on Linux).
Options:
fileHandle - Handle of the open file.
value - The string value to write.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Var handle=Create_File("Example.txt")
If handle <> Cast(Any Ptr, -1) Then
Write_StringN(handle,"STRING_1")
Write_StringN(handle,"STRING_2")
Close_File(handle)
EndIf
handle=Read_File("Example.txt")
If handle <> Cast(Any Ptr, -1) Then
Print Read_String(handle) // Reads "STRING_1"
Print Read_String(handle) // Reads "STRING_2"
Close_File(handle)
EndIf
Sleep(1000)
Result:
STRING_1
STRING_2

***
SUB: Write_Word
Syntax: sub Write_Word(ByVal fileHandle As HANDLE, ByVal value As Short) ' Assuming Short is 16-bit WORD
Description: Writes a 2-byte signed integer (Short/Word) to the file.
Options:
fileHandle - Handle of the open file.
value - The Short value to write.
Platform: Windows, Linux
Example: (See Read_WORD example)

--- SECTION: FileSystem ---
Description: Functions for managing files and directories (copying, moving, deleting, renaming, examining).

***
SUB: CopyDir
Syntax: Sub CopyDir(ByRef SourseDir As String, ByRef NewDir As String, ByVal flag As long=0)
Description: Copies files or directories. Can use wildcards.
Options:
SourseDir - Source directory or file pattern (e.g., "C:\Source", "C:\Source\*.txt").
NewDir - Destination directory.
flag - (Windows only) Flags controlling the copy operation (e.g., FOF_ALLOWUNDO, FOF_NOCONFIRMATION, FOF_SILENT - see original doc).
Platform: Windows, Linux
Example 1: (Copy only txt files)
#include "window9.bi"
' Ensure C:\33 and C:\66 exist, C:\33 has some .txt files
' CopyDir("C:\33\*.txt","C:\66")
Print "CopyDir executed (txt files)."
Example 2: (Copy entire directory)
#include "window9.bi"
' Ensure C:\33 and C:\66 exist
' CopyDir("C:\33","C:\66")
Print "CopyDir executed (full directory)."

***
SUB: CreateDir
Syntax: Sub CreateDir(ByRef sDir As String)
Description: Creates a new directory (folder).
Options:
sDir - Name of the directory to create (can include path).
Platform: Windows, Linux
Example:
#Include "window9.bi"
CreateDir("NEW_TEST_FOLDER")
Print "Directory NEW_TEST_FOLDER created (if permissions allow)."
Sleep(1000)
' Optional: Clean up
RemoveDir("NEW_TEST_FOLDER") // Or use DeleteDir

***
SUB: DeleteDir
Syntax: Sub DeleteDir(ByRef DeleteDirName As String,ByVal flag As Integer=0)
Description: Deletes files or directories. Can use wildcards. Use FOF_ALLOWUNDO flag (Windows) to move to Recycle Bin.
Options:
DeleteDirName - Name of the directory or file pattern to delete (e.g., "C:\Temp\MyDir", "C:\Temp\*.tmp").
flag - (Windows only) Flags controlling the delete operation (e.g., FOF_ALLOWUNDO, FOF_NOCONFIRMATION, FOF_SILENT - see original doc).
Platform: Windows, Linux
Example 1: (Delete only files matching pattern)
#include "window9.bi"
' Create dummy files in C:\33 first
' DeleteDir("C:\33\*.*")
Print "DeleteDir executed (files only)."
Example 2: (Delete directory to Recycle Bin - Windows only)
#include "window9.bi"
Const FOF_ALLOWUNDO=64
' Create dummy directory C:\33 first
' DeleteDir("C:\33",FOF_ALLOWUNDO)
Print "DeleteDir executed (to recycle bin)."

***
SUB: Delete_File
Syntax: Sub Delete_File (ByRef sFile As String)
Description: Deletes a single specified file.
Options:
sFile - Full path and name of the file to delete.
Platform: Windows, Linux
Example:
#include "window9.bi"
' Create a dummy file 1.txt first
' Delete_File("1.txt")
Print "Delete_File executed for 1.txt."

***
FUNCTION: DirectoryEntryAttributes
Syntax: Function DirectoryEntryAttributes(ByVal HandleDirectory As integer) As UInteger
Description: Returns the attributes of the current file/directory during an enumeration started by ExamineDirectory. Use bitwise AND to check specific attributes.
Return Values (Combine with AND): FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_COMPRESSED (Win), FILE_ATTRIBUTE_DIRECTORY, FILE_ATTRIBUTE_ENCRYPTED (Win), FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_NORMAL (Win), FILE_ATTRIBUTE_OFFLINE (Win), FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_REPARSE_POINT (Win), FILE_ATTRIBUTE_SPARSE_FILE (Win), FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_TEMPORARY (Win).
Options:
HandleDirectory - Search handle from ExamineDirectory.
Platform: Windows, Linux
Example: (List only directories)
#Include "window9.bi"
#Ifdef __FB_WIN32__
Dim As String searchDir = "C:\"
#Else
Dim As String searchDir = "/"
#EndIf
Var DirHandle=ExamineDirectory(searchDir, "*.*")
If DirHandle Then
Var dirCount=0
Do
If DirectoryEntryAttributes(DirHandle) And FILE_ATTRIBUTE_DIRECTORY Then
Print "[DIR] "; DirectoryEntryName(DirHandle)
dirCount+=1
Endif
Loop While NextDirectoryEntry(DirHandle)
Print : Print "Total Directories ="; dirCount
FinishDirectory(DirHandle)
Else
Print "Could not examine directory: "; searchDir
EndIf
Sleep(2000)
Result: (Lists directories in the specified path)

***
FUNCTION: DirectoryEntryDate
Syntax: Function DirectoryEntryDate(ByVal HandleDirectory As Integer, ByVal flag As Long) As String
Description: Returns the creation, last access, or last modification timestamp of the current file/directory during an enumeration.
Options:
HandleDirectory - Search handle from ExamineDirectory.
flag - Specifies which date to return: 1 = Creation Time (unreliable on Linux), 2 = Last Access Time, 3 = Last Modification Time.
Platform: Windows, Linux
Example:
#Include "window9.bi"
#Ifdef __FB_WIN32__
Dim As String searchDir = "C:\"
#Else
Dim As String searchDir = "/"
#EndIf
Var DirHandle=ExamineDirectory(searchDir, "*.*")
If DirHandle Then
Do
Print DirectoryEntryName(DirHandle) & " (Modified: "& DirectoryEntryDate(DirHandle,3) & ")"
Loop While NextDirectoryEntry(DirHandle)
FinishDirectory(DirHandle)
Else
Print "Could not examine directory: "; searchDir
EndIf
Sleep(2000)
Result: (Lists files/dirs with their modification dates)

***
FUNCTION: DirectoryEntryName
Syntax: Function DirectoryEntryName(ByVal HandleDirectory As integer) As string
Description: Returns the name of the current file or directory during an enumeration.
Options:
HandleDirectory - Search handle from ExamineDirectory.
Platform: Windows, Linux
Example: (See DirectoryEntryDate example)

***
FUNCTION: DirectoryEntrySize
Syntax: Function DirectoryEntrySize(ByVal HandleDirectory As integer) As ULongInt
Description: Returns the size (in bytes) of the current file during an enumeration. Returns 0 for directories.
Options:
HandleDirectory - Search handle from ExamineDirectory.
Platform: Windows, Linux
Example:
#Include "window9.bi"
#Ifdef __FB_WIN32__
Dim As String searchDir = "C:\"
#Else
Dim As String searchDir = "/"
#EndIf
Var DirHandle=ExamineDirectory(searchDir, "*.*")
If DirHandle Then
Do
Print DirectoryEntryName(DirHandle) & " (Size: "& DirectoryEntrySize(DirHandle) & ")"
Loop While NextDirectoryEntry(DirHandle)
FinishDirectory(DirHandle)
Else
Print "Could not examine directory: "; searchDir
EndIf
Sleep(2000)
Result: (Lists files/dirs with their sizes)

***
FUNCTION: ExamineDirectory
Syntax: Function ExamineDirectory(ByRef DirectoryName As string, ByRef Pattern As string) As Integer ' Returns Handle
Description: Starts an enumeration of files and directories matching a pattern within a specified directory. Returns a search handle used by other DirectoryEntry* functions, or 0 on failure. Remember to call FinishDirectory when done.
Options:
DirectoryName - The path of the directory to search.
Pattern - File matching pattern (e.g., "*.*", "*.txt", "myfile.*").
Platform: Windows, Linux
Example: (See DirectoryEntryAttributes example)

***
SUB: FinishDirectory
Syntax: Sub FinishDirectory(ByVal HandleDirectory As integer)
Description: Releases the resources associated with a directory search handle obtained from ExamineDirectory.
Options:
HandleDirectory - The search handle to finish.
Platform: Windows, Linux
Example: (See DirectoryEntryAttributes example)

***
FUNCTION: GetCurentDir
Syntax: Function GetCurentDir() As String
Description: Returns the current working directory of the application.
Options: None
Platform: Windows, Linux
Example:
#Include "window9.bi"
Print "Current Directory: "; GetCurentDir()
sleep(2000)
Result: (Prints the application's current working directory)

***
FUNCTION: GetCurrentFileName
Syntax: Function GetCurrentFileName() As String
Description: Returns the filename including extension of the currently running executable module. Use GetCurrentFileNameA to get only the name without extension.
Options: None
Platform: Windows
Example:
#Include "window9.bi"
Print "Full Filename: "; GetCurrentFileName()
Print "Base Filename: "; GetCurrentFileNameA()
Sleep(2000)
Result: (Prints filename with and without extension, e.g., FbTemp.exe and FbTemp)

***
FUNCTION: GetCurrentFileNameA
Syntax: Function GetCurrentFileNameA() As String
Description: Returns the filename (without extension) of the currently running executable module.
Options: None
Platform: Windows
Example: (See GetCurrentFileName example)

***
FUNCTION: GetExtensionPart
Syntax: Function GetExtensionPart(ByRef sPath As String) As String
Description: Extracts the file extension (part after the last dot) from a path string. Returns empty string if no extension.
Options:
sPath - The full path or filename string.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As String ss= "D:\freebasic\MyProgram.bas"
Print "Extension: "; GetExtensionPart(ss)
Sleep(2000)
Result: bas

***
FUNCTION: GetFilePart
Syntax: Function GetFilePart(ByRef sPath As String) As String
Description: Extracts the filename including extension from a full path string. Handles both Windows (\) and Linux (/) path separators.
Options:
sPath - The full path string.
Platform: Windows, Linux
Example:
#Include "window9.bi"
#Ifdef __FB_WIN32__
Dim As String ss= "D:\freebasic\MyProgram.bas"
#Else
Dim As String ss= "/home/user/MyProgram.bas"
#EndIf
Print "File Part: "; GetFilePart(ss)
sleep(2000)
Result: MyProgram.bas

***
FUNCTION: GetPathPart
Syntax: Function GetPathPart(ByRef sPath As String) As String
Description: Extracts the directory path part (excluding the filename) from a full path string. Handles both Windows (\) and Linux (/) path separators.
Options:
sPath - The full path string.
Platform: Windows, Linux
Example:
#Include "window9.bi"
#Ifdef __FB_WIN32__
Dim As String ss= "D:\freebasic\MyProgram.bas"
#Else
Dim As String ss= "/home/user/MyProgram.bas"
#EndIf
Print "Path Part: "; GetPathPart(ss)
Sleep(2000)
Result: D:\freebasic (or /home/user)

***
FUNCTION: GetSpecialFolder
Syntax: function GetSpecialFolder(ByVal folderFlag As integer) As String
Description: Returns the path to various Windows special folders (e.g., Desktop, My Documents, AppData, Program Files).
Options:
folderFlag - A CSIDL constant specifying the desired folder (e.g., CSIDL_DESKTOPDIRECTORY, CSIDL_APPDATA, CSIDL_PROGRAM_FILES - see original doc for full list).
Platform: Windows
Example:
#Include "window9.bi"
Print "Desktop Path: "; GetSpecialFolder(CSIDL_DESKTOPDIRECTORY)
Print "AppData Path: "; GetSpecialFolder(CSIDL_APPDATA)
Print "Program Files: "; GetSpecialFolder(CSIDL_PROGRAM_FILES)
Sleep(2000)
Result: (Prints paths to Desktop, AppData, Program Files folders)

***
FUNCTION: GetSystemDir
Syntax: Function GetSystemDir() As String
Description: Returns the path to the Windows System32 directory.
Options: None
Platform: Windows
Example:
#Include "window9.bi"
Print "System Directory: "; GetSystemDir()
sleep(2000)
Result: (Prints path like C:\Windows\System32)

***
FUNCTION: GetTempDir
Syntax: Function GetTempDir() As String
Description: Returns the path to the user's temporary files directory.
Options: None
Platform: Windows
Example:
#Include "window9.bi"
Print "Temp Directory: "; GetTempDir()
sleep(2000)
Result: (Prints path to the temp folder)

***
FUNCTION: GetWindowsDir
Syntax: Function GetWindowsDir() As String
Description: Returns the path to the main Windows directory.
Options: None
Platform: Windows
Example:
#Include "window9.bi"
Print "Windows Directory: "; GetWindowsDir()
sleep(2000)
Result: (Prints path like C:\Windows)

***
FUNCTION: CopyFile (WinAPI)
Syntax: function CopyFile alias "CopyFileA"(byval lpExistingFileName as LPCSTR, byval lpNewFileName as LPCSTR, byval bFailIfExists as WINBOOL) as WINBOOL
Description: Standard WinAPI function to copy a file. Included for reference. Returns non-zero on success.
Options:
lpExistingFileName - Path to the existing file.
lpNewFileName - Path for the new copy.
bFailIfExists - If TRUE, the function fails if lpNewFileName already exists. If FALSE, it overwrites.
Platform: Windows
Example:
#include "window9.bi"
' Ensure C:\1.exe exists
' CopyFile(@"C:\1.exe",@"C:\2.exe" ,0) // Overwrite if exists
Print "CopyFile executed."

***
SUB: MoveDir
Syntax: Sub MoveDir(ByRef SourseDir As String, ByRef NewDir As String, ByVal flag As Long=0)
Description: Moves files or directories. Can use wildcards.
Options:
SourseDir - Source directory or file pattern.
NewDir - Destination path (can be a directory or a new filename if moving a single file).
flag - (Windows only) Flags controlling the move operation (e.g., FOF_ALLOWUNDO, FOF_NOCONFIRMATION - see CopyDir flags).
Platform: Windows, Linux
Example 1: (Move only files matching pattern)
#include "window9.bi"
' Ensure C:\33 and C:\66 exist, C:\33 has files
' MoveDir("C:\33\*.*","C:\66")
Print "MoveDir executed (files only)."
Example 2: (Move entire directory)
#include "window9.bi"
' Ensure C:\33 exists, C:\66 does not exist or is empty
' MoveDir("C:\33","C:\66") // Moves C:\33 *into* C:\66 if C:\66 exists, otherwise renames C:\33 to C:\66
Print "MoveDir executed (full directory)."

***
FUNCTION: MoveFile / MoveFileEx (WinAPI)
Syntax (MoveFile): function MoveFile alias "MoveFileA"(byval lpExistingFileName as LPCSTR, byval lpNewFileName as LPCSTR) as WINBOOL
Syntax (MoveFileEx): function MoveFileEx alias "MoveFileExA"(byval lpExistingFileName as LPCSTR, byval lpNewFileName as LPCSTR, byval dwFlags as DWORD) as WINBOOL
Description: Standard WinAPI functions to move or rename a file or directory. MoveFileEx provides more options. May not work correctly with non-ASCII paths; MoveDir might be more reliable. Returns non-zero on success.
Options (MoveFileEx):
lpExistingFileName - Current path/name.
lpNewFileName - New path/name.
dwFlags - Flags like MOVEFILE_REPLACE_EXISTING, MOVEFILE_COPY_ALLOWED, MOVEFILE_DELAY_UNTIL_REBOOT.
Platform: Windows
Example:
#include "window9.bi"
' Ensure C:\1.exe exists
' MoveFile(@"C:\1.exe",@"D:\2.exe") // Move file across drives (requires MOVEFILE_COPY_ALLOWED in MoveFileEx for reliability)
Print "MoveFile executed."

***
FUNCTION: NextDirectoryEntry
Syntax: Function NextDirectoryEntry(ByVal HandleDirectory As integer) As Integer
Description: Advances the directory enumeration to the next file or directory. Returns non-zero if successful, 0 if no more entries are found.
Options:
HandleDirectory - Search handle from ExamineDirectory.
Platform: Windows, Linux
Example: (See DirectoryEntryAttributes example)

***
FUNCTION: RemoveDir
Syntax: Function RemoveDir(ByRef sDir As String) As Integer
Description: Removes an empty directory. Primarily for older Windows versions; DeleteDir is generally preferred. Returns non-zero on success.
Options:
sDir - Path of the empty directory to remove.
Platform: Windows
Example:
#Include "window9.bi"
CreateDir("TEMP_EMPTY_FOLDER") // Create it first
Sleep(500)
If RemoveDir("TEMP_EMPTY_FOLDER") <> 0 Then
Print "Removed TEMP_EMPTY_FOLDER successfully."
Else
Print "Failed to remove TEMP_EMPTY_FOLDER (might not be empty or permissions issue)."
EndIf
Sleep(1000)

***
SUB: RenameDir
Syntax: sub RenameDir(ByRef SourseDirName As String,ByRef NewDirName As String, ByVal flag As Integer=0)
Description: Renames a file or directory. Uses the same underlying mechanism as MoveDir/DeleteDir on Windows.
Options:
SourseDirName - Current name/path of the file or directory.
NewDirName - New name/path.
flag - (Windows only) Flags controlling the operation (see CopyDir/DeleteDir flags).
Platform: Windows, Linux
Example:
#Include "window9.bi"
' Ensure directory C:\33 exists
' RenameDir("C:\33","C:\66_Renamed")
Print "RenameDir executed."

***
SUB: SetCurentDir
Syntax: Sub SetCurentDir(ByRef sDir As String)
Description: Sets the application's current working directory.
Options:
sDir - The directory path to set as current.
Platform: Windows, Linux
Example:
#Include "window9.bi"
#Ifdef __FB_WIN32__
Var sDir = "C:\"
#Else
Var sDir = "/"
#EndIf
Print "Current dir before: "; GetCurentDir()
SetcurentDir(sDir)
Print "Current dir after: "; GetCurentDir()
Sleep(2000)
Result: (Prints current directory before and after changing it)

***
FUNCTION: w9isDirExists
Syntax: Function w9isDirExists(sFileName As UString) As Long
Description: Checks if a given path exists and refers to a directory. Returns 1 if it exists and is a directory, 0 otherwise.
Options:
sFileName - The path to check.
Platform: Windows, Linux
Example:
#include "window9.bi"
if w9isDirExists("C:\Windows") then // Use a known directory
Print "C:\Windows exists and is a directory."
EndIf
if w9isDirExists("C:\Windows\notepad.exe") then // Use a known file
Print "C:\Windows\notepad.exe is a directory."
else
Print "C:\Windows\notepad.exe is NOT a directory."
EndIf
Sleep(2000)
Result:
C:\Windows exists and is a directory.
C:\Windows\notepad.exe is NOT a directory.

***
FUNCTION: w9isFile
Syntax: Function w9isFile(sFileName As UString) As Long
Description: Checks if a given path exists and refers to a regular file (not a directory). Returns 1 if it exists and is a file, 0 otherwise.
Options:
sFileName - The path to check.
Platform: Windows, Linux
Example:
#include "window9.bi"
if w9isFile("C:\Windows\notepad.exe") then // Use a known file
Print "C:\Windows\notepad.exe is a file."
else
Print "C:\Windows\notepad.exe is NOT a file."
EndIf
if w9isFile("C:\Windows") then // Use a known directory
Print "C:\Windows is a file."
else
Print "C:\Windows is NOT a file."
EndIf
Sleep(2000)
Result:
C:\Windows\notepad.exe is a file.
C:\Windows is NOT a file.

***
FUNCTION: w9isFileExists
Syntax: Function w9isFileExists(sFileName As UString) As Long
Description: Checks if a given path exists (can be a file or a directory). Returns 1 if it exists, 0 otherwise.
Options:
sFileName - The path to check.
Platform: Windows, Linux
Example:
#include "window9.bi"
if w9isFileExists("C:\Windows\notepad.exe") then
Print "C:\Windows\notepad.exe exists."
EndIf
if w9isFileExists("C:\NonExistentFile.xyz") then
Print "C:\NonExistentFile.xyz exists."
else
Print "C:\NonExistentFile.xyz does NOT exist."
EndIf
Sleep(2000)
Result:
C:\Windows\notepad.exe exists.
C:\NonExistentFile.xyz does NOT exist.

--- SECTION: Font ---
Description: Functions for loading, using, and querying font properties.

***
SUB: FontDraw
Syntax: Sub FontDraw(ByVal FontID As HFONT)
Description: Sets the font to be used by subsequent 2D_Draw text functions (like TextDraw).
Options:
FontID - Handle of the font (from LoadFont, FontRequester, etc.)
Platform: Windows, Linux
Example: (See 2D_Draw / FontDraw example)

***
FUNCTION: FontRequester
Syntax: function FontRequester(byval hwnd As HWND = 0, byval nColor As Integer = 0) As Integer ' Returns HFONT
Description: Opens the system font selection dialog. See Dialog / FontRequester for details.
Options: (See Dialog / FontRequester)
Platform: Windows, Linux
Example: (See Dialog / FontRequester example)

***
SUB: FreeFont
Syntax: sub FreeFont(iFont as integer) ' iFont is HFONT
Description: Releases the resources associated with a font handle created by LoadFont or FontRequester.
Options:
iFont - The HFONT handle to free.
Platform: Windows, Linux
Example:
#Include "window9.bi"
OpenWindow("Font Test",10,10,200,100)
StringGadget(1,10,10,150,50,"String")
Var font = LoadFont("Courier New",30)
SetGadgetFont(1,CINT(font))
Do
Var event = WaitEvent()
Select Case event
Case EventClose
FreeFont(CINT(font)) // Free the font before ending
End
End Select
Loop
Result: Shows a string gadget with a custom font.

***
FUNCTION: GetCurentDefaultFont
Syntax: Function GetCurentDefaultFont() As Integer ' Returns HFONT
Description: Gets the handle of the font currently set as the default for subsequently created gadgets (via SetGadgetFont(, fontHandle)).
Options: none
Platform: Windows, Linux
Example:
#include "window9.bi"
Var hwnd=Openwindow("Default Font Test",10,10,200,200)
dim as Integer font = Loadfont("Arial" , 36 , , 1 , 1) // Bold, Italic
SetGadgetFont(,font) // Set as default for new gadgets
dim as Integer defaultFont = GetCurentDefaultFont()
Print "Default Font Name: "; GetNameFromFont(defaultFont)
Print "Default Font Size: "; GetSizeFromFont(defaultFont)
Print "Default Font Bold?: "; GetStyleFromFont(defaultFont,1)
Print "Default Font Italic?: "; GetStyleFromFont(defaultFont,2)
ButtonGadget(1, 10, 10, 150, 50, "Uses Default") // This button uses Arial 36 Bold Italic
Do
var Event=Waitevent()
If Event=Eventclose Then End
Loop
FreeFont(font)
Result: (Prints font details and shows a button with that font)

***
FUNCTION: GetNameFromFont
Syntax: Function GetNameFromFont(font As Integer) As UString ' font is HFONT
Description: Gets the name of the font associated with the given handle. Note: For the system default font (from GetSystemDefaultFont), this returns "System" on Windows.
Options:
font - The HFONT handle.
Platform: Windows, Linux
Example:
#include "window9.bi"
dim as Integer font = Loadfont("Times New Roman" , 24 , , 1 , 0) // Bold
Print "Font Name: "; GetNameFromFont(font)
FreeFont(font)
sleep (2000)
Result: Times New Roman

***
FUNCTION: GetSizeFromFont
Syntax: Function GetSizeFromFont(font As Integer) As Long ' font is HFONT
Description: Gets the size (height) of the font associated with the given handle. May not work for the system default font on Windows.
Options:
font - The HFONT handle.
Platform: Windows, Linux
Example: (See GetNameFromFont example, add Print GetSizeFromFont(font))

***
SUB: GetSizeStringFromFont
Syntax: Sub GetSizeStringFromFont(sText As UString , font As Integer , Byref iW As Long , Byref iH As Long) ' font is HFONT
Description: Calculates the width (iW) and height (iH) required to display the given text string using the specified font. Results are returned in the iW and iH variables.
Options:
sText - The text string to measure.
font - The HFONT handle of the font to use for measurement.
iW - Variable to receive the calculated width.
iH - Variable to receive the calculated height.
Platform: Windows, Linux
Example: (Auto-sizing button)
#include "window9.bi"
Var hwnd=Openwindow("Auto-Size Button",10,10,400,150)
Var Event=0
dim as Integer font = Loadfont("Arial" , 18)
Setgadgetfont( , font) // Set default font for button
Dim As Long iW , iH
dim as Ustring s = "This is a Button With Auto Size"
GetSizeStringFromFont(s , GetCurentDefaultFont() , iW , iH) // Measure text
iW+=20 // Add padding
iH+=10 // Add padding
Buttongadget(1, 10 , 10 , iW, iH , s) // Create button with calculated size
Do
Event=Waitevent()
If Event=Eventclose Then End
Loop
freefont(font)
Result: Shows a button sized appropriately for its text content.

***
FUNCTION: GetStyleFromFont
Syntax: Function GetStyleFromFont(font As Integer, iStyle As Long) As Long ' font is HFONT
Description: Checks if a specific style attribute (Bold, Italic, etc.) is set for the given font handle. Returns non-zero if the style is set, 0 otherwise.
Options:
font - The HFONT handle.
iStyle - The style flag to check: 1=Bold, 2=Italic, 3=Underline (Win only), 4=Strikeout (Win only).
Platform: Windows, Linux
Example: (See GetNameFromFont example)

***
FUNCTION: GetSystemDefaultFont
Syntax: Function GetSystemDefaultFont() As Integer ' Returns HFONT
Description: Gets the handle of the default system font used by the OS for UI elements.
Options: none
Platform: Windows, Linux
Example:
#include "window9.bi"
dim as Integer sysFont = GetSystemDefaultFont()
Print "System Default Font Name: "; GetNameFromFont(sysFont) // Returns "System" on Windows
// FreeFont(sysFont) // Do not free system fonts
sleep(2000)
Result: System (on Windows)

***
FUNCTION: LoadFont
Syntax: Function LoadFont(ByRef sFileName As String , ByVal Size As Long, ByVal Corner As Long=0, ByVal Bold As Long=0, ByVal Italic As Long=0, ByVal Underline As Long=0, ByVal StrikeOut As long=0) As integer ' Returns HFONT
Description: Loads a font installed on the system and returns its handle (HFONT).
Options:
sFileName - Name of the font (e.g., "Arial", "Courier New").
Size - Font size (usually in points, but interpretation might depend on OS context).
Corner - (Windows only) Angle of rotation/tilt in degrees (0-360). Often not used.
Bold - Set to 1 for bold, 0 otherwise.
Italic - Set to 1 for italic, 0 otherwise.
Underline - (Windows only) Set to 1 for underline, 0 otherwise.
StrikeOut - (Windows only) Set to 1 for strikeout, 0 otherwise.
Platform: Windows, Linux
Example: (See FreeFont example)

***
FUNCTION: SelectedFontName
Syntax: Function SelectedFontName() As String
Description: Gets the name of the font selected in the most recent call to FontRequester.
Options: None
Platform: Windows, Linux
Example: (See FontRequester example)

***
FUNCTION: SelectedFontColor
Syntax: Function SelectedFontColor() As Integer
Description: Gets the color selected in the most recent call to FontRequester.
Options: None
Platform: Windows
Example: (See FontRequester example - Windows only)

***
FUNCTION: SelectedFontSize
Syntax: Function SelectedFontSize() As Integer
Description: Gets the size of the font selected in the most recent call to FontRequester.
Options: None
Platform: Windows, Linux
Example: (See FontRequester example)

***
FUNCTION: SelectedFontStyle
Syntax: Function SelectedFontStyle(ByVal flagstyle As Byte) As Byte
Description: Checks the style attributes of the font selected in the most recent call to FontRequester. Returns non-zero if the specified style is set.
Options:
flagstyle - Style to check: 1=Bold, 2=Italic, 3=Underline (Win only), 4=Strikeout (Win only).
Platform: Windows, Linux
Example: (See FontRequester example)

***
FUNCTION: SetGadgetFont
Syntax: Function SetGadgetFont(ByVal gadget As Long = -1 ,ByVal Font As integer=-1) As Integer ' Font is HFONT
Description: Sets the font for a specific gadget, or sets the default font for subsequently created gadgets.
Supported Gadgets: ButtonGadget, EditorGadget, TextGadget, StringGadget, SpinGadget, CalendarGadget, CheckBoxGadget, OptionGadget, HyperLinkGadget, ListBoxGadget, GroupGadget, ListViewGadget (Linux GTK2 row font only), TreeViewGadget, PanelGadget, ComboBoxGadget (Win only), ComboBoxImageGadget (Win only), ExplorerListGadget (Win only), GadgetToolTip (Win only), StatusBarGadget.
Options:
gadget - Gadget ID number. If -1 (default), sets the default font for future gadgets.
Font - HFONT handle of the font to set. If -1 (default when gadget is also -1), resets the default font to the system default.
Platform: Windows, Linux (Support varies by gadget)
Example:
#Include "window9.bi"
OpenWindow("Set Font Test",10,10,250,500)
StringGadget(1,10,10,150,40,"Default Font") // Uses initial default
Var fontArial36 = LoadFont("arial",36)
SetGadgetFont(,CINT(fontArial36)) // Set default font to Arial 36
OptionGadget(2,10,70,200,40,"Arial 36") // Uses new default
Var fontArial22 = LoadFont("arial",22)
TextGadget(3,10,140,100,30,"Arial 22")
SetGadgetFont(3,CINT(fontArial22)) // Set font for gadget 3 only
SetGadgetFont() // Reset default font to system default
EditorGadget(4,10,200,150,100,"System Font") // Uses system default
Do
Var event=WaitEvent()
Select Case event
Case EventClose
FreeFont(CINT(fontArial36))
FreeFont(CINT(fontArial22))
End
End Select
Loop
Result: Shows various gadgets using different explicitly set or default fonts.

--- SECTION: Gadget ---
Description: UI controls (widgets) and related functions.

--- Gadget: ButtonImageGadget ---
FUNCTION: ButtonImageGadget
Syntax: Function ButtonImageGadget(ByVal gadget As Long, ByVal x As Long, ByVal y As Long, ByVal w As Long, ByVal h As Long, ByVal imageId As Any ptr = 0, ByVal Style As Long=BS_BITMAP) As HWND
Description: Creates a button that displays an image (HBITMAP) or an icon (HICON).
Options:
gadget - Gadget ID.
x, y, w, h - Location and dimensions.
imageId - Handle to the HBITMAP or HICON to display. Can be set later using SetImageGadget/SetIconGadget.
Style - Button style. Common: BS_BITMAP (default), BS_ICON. Use FB_BS_PUSHLIKE for a toggle button effect.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As integer event
OpenWindow("Image Button",300,10,100,120)
Var HIMAGE=Load_image("1.png") // Assuming 1.png exists
ButtonImageGadget(1,10,10,80,80,HIMAGE, FB_BS_PUSHLIKE or BS_BITMAP) // Toggle image button
Do
event=WaitEvent()
If event=EventClose Then End
Loop
Free_Image(HIMAGE) // Free image when done
Result: Shows a window with a button displaying an image, acting as a toggle.

--- Gadget: ButtonGadget ---
FUNCTION: ButtonGadget
Syntax: Function ButtonGadget(ByVal gadget As Long, ByVal x As Long, ByVal y As Long, ByVal w As Long, ByVal h As Long, ByRef s As String="", ByVal Style As Long=0) As HWND
Description: Creates a standard push button with text.
Options:
gadget - Gadget ID.
x, y, w, h - Location and dimensions.
s - Text displayed on the button.
Style - Button style. Use FB_BS_PUSHLIKE for toggle behavior. See original docs for extensive Windows-only styles (BS_...).
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Integer event
OpenWindow("Button Test",300,10,150,100)
ButtonGadget(1,10,10,100,30,"Click Me")
Do
event=WaitEvent()
If event=EventClose Then End
If event=eventgadget Then
If EventNumber() = 1 Then MessBox("Button","Button Clicked!")
EndIf
Loop
Result: Shows a window with a clickable button.

--- Gadget: CalendarGadget ---
FUNCTION: CalendarGadget
Syntax: Function CalendarGadget(ByVal gadget As long, ByVal x As long, ByVal y As long, ByVal w As long, ByVal h As long,ByVal Style As long=0) As HWND
Description: Creates a monthly calendar control for selecting dates.
Options:
gadget - Gadget ID.
x, y, w, h - Location and dimensions.
Style - (Windows Only) Extended window style flags (WS_EX_...).
Platform: Windows, Linux
Example:
#Include "window9.bi"
OpenWindow("Calendar",10,10,400,300)
CalendarGadget(1,10,10,220,220)
ButtonGadget(2,250,100,130,25,"Get Date")
TextGadget(3,250,140,130,20,"")
Do
var event=WaitEvent()
If event=eventclose Then End
If event=eventgadget Then
If eventnumber()=2 Then
Dim selectedDate as Long = GetStateCalendar(1) // Get YYYYMMDD
SetGadgetText(3,Str(selectedDate))
EndIf
EndIf
Loop
Result: Shows a calendar; button click displays the selected date (YYYYMMDD format).

--- Gadget: CheckBoxGadget ---
FUNCTION: CheckBoxGadget
Syntax: Function CheckBoxGadget(ByVal gadget As Long, ByVal x As Long, ByVal y As Long, ByVal w As Long, ByVal h As Long, ByRef s As String="", ByVal Style As Long=3) As HWND ' Default BS_AUTOCHECKBOX
Description: Creates a check box control with associated text.
Options:
gadget - Gadget ID.
x, y, w, h - Location and dimensions.
s - Text label displayed next to the check box.
Style - (Windows Only) Button style. Use 6 (BS_AUTO3STATE) for a three-state check box. Default is 3 (BS_AUTOCHECKBOX).
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Integer event
OpenWindow("Checkbox",300,10,200,150)
CheckBoxGadget(1,10,10,150,30,"Enable Feature")
ButtonGadget(2,10,50,150,30, "Check Status")
Do
event=WaitEvent()
If event=EventClose Then End
If event=eventgadget Then
If EventNumber()=2 Then
If GetGadgetState(1)=1 Then // 1 = Checked, 0 = Unchecked
MessBox("Status","Feature Enabled")
Else
MessBox("Status","Feature Disabled")
EndIf
EndIf
EndIf
Loop
Result: Shows a check box and a button to report its state.

--- Gadget: ComboBoxGadget ---
FUNCTION: ComboBoxGadget
Syntax: Function ComboBoxGadget(ByVal gadget As Long, ByVal x As Long, ByVal y As Long, ByVal w As Long, ByVal h As Long, ByVal Style As Long=CBS_DROPDOWNLIST Or WS_VSCROLL) As HWND
Description: Creates a combo box control (drop-down list). Color/font changes only supported on Windows.
Options:
gadget - Gadget ID.
x, y, w - Location and width.
h - Height. On Windows, this is the height of the *drop-down list*. On Linux, it's the height of the *gadget itself*.
Style - (Windows Only) Combo box style flags (e.g., CBS_DROPDOWN, CBS_SIMPLE, CBS_SORT - see original doc for full list). Default is a non-editable drop-down list.
Platform: Windows, Linux (Styling limitations on Linux)
Example:
#Include "window9.bi"
#Ifdef __FB_WIN32__
Dim h As Long = 80 // Dropdown height for Win
#Else
Dim h As Long = 30 // Gadget height for Lin
#EndIf
OpenWindow("ComboBox",10,10,300,150) // Increased height for dropdown
ComboBoxGadget(1,10,10,100,h)
AddComboBoxItem(1,"Option 1",-1)
AddComboBoxItem(1,"Option 2",-1)
AddComboBoxItem(1,"Option 3",-1)
TextGadget(2,150,10,130,20, "Selection:")
Do
var event=WaitEvent()
If event=eventclose Then End
If event=eventgadget Then
If eventnumber()=1 Then
dim selectedIndex as Long = GetItemComboBox(1)
if selectedIndex >= 0 then
setgadgettext(2,"Selected: " & GetComboBoxText(1, selectedIndex))
else
setgadgettext(2,"Selection:")
end if
EndIf
EndIf
Loop
Result: Shows a combo box; selected item text is displayed in a text gadget.

--- Gadget: ComboBoxImageGadget ---
FUNCTION: ComboBoxImageGadget
Syntax: Function ComboBoxImageGadget(ByVal gadget As Long, ByVal x As Long, ByVal y As Long, ByVal w As Long, ByVal h As Long, ByVal SizeIcon As Long=16, ByVal Style As Long=CBS_DROPDOWNLIST Or WS_VSCROLL) As HWND
Description: Creates a combo box control that can display images next to items.
Options:
gadget - Gadget ID.
x, y, w - Location and width.
h - Height (see ComboBoxGadget notes regarding Win/Lin differences).
SizeIcon - (Windows only) Size of the icon area (default 16x16). Linux size depends on image.
Style - (Windows Only) Combo box style flags (see ComboBoxGadget).
Platform: Windows, Linux
Example:
#Include "window9.bi"
#Ifdef __FB_WIN32__
Dim h As Long = 80
#Else
Dim h As Long = 30
#EndIf
If OpenWindow("Image Combo",10,10,300,150) Then
ComboBoxImageGadget(1,10,10,150,h)
AddComboBoxImageItem(1,"No Image",0,-1) // Item with no image (pass 0)
AddComboBoxImageItem(1,"Image 1",Load_image("1.png"),-1) // Assuming 1.png exists
AddComboBoxImageItem(1,"Image 2",Load_image("2.png"),-1) // Assuming 2.png exists
EndIf
Var event=0
Do
event=WaitEvent()
If Event=EventClose Then End
Loop
// Remember to Free_Image loaded images
Result: Shows a combo box with items potentially having images next to them.

--- Gadget: ContainerGadget ---
FUNCTION: ContainerGadget
Syntax: Function ContainerGadget(ByVal gadget As Long, ByVal x As Long,ByVal y As Long,ByVal w As Long, ByVal h As Long, ByVal parameter As Long=0) As HWND
Description: Creates an invisible container gadget used to group other gadgets. Moving or hiding the container affects all gadgets placed within it (using UseGadgetList).
Options:
gadget - Gadget ID for the container.
x, y, w, h - Location and dimensions of the container.
parameter - (Windows Only) Extended window style flags (WS_EX_...) for the container itself.
Platform: Windows, Linux
Example: (Container moves randomly)
#Include "window9.bi"
Dim Shared As HWND ph
ph=OpenWindow("Container",10,10,500,500)
ContainerGadget(4,100,0,300,300) // Container ID 4
UseGadgetList(GadgetID(4)) // Tell subsequent gadgets to use container 4
ButtonGadget(1,10,10,100,20, "Button A")
ButtonGadget(2,10,40,100,30, "Button B")
UseGadgetList(ph) // Switch back to main window if needed for other gadgets
function tt() As Integer
Static As Integer rx,ry
rx=Rnd*200
ry=Rnd*200
ResizeGadget(4,rx,ry) // Move the container (and its contents)
SetGadgetColor(GadgetID(4),BGR(rnd*255,rnd*255,rnd*255),0,1) // Set container background (Win only?)
Return 1
End Function
SetTimer(ph,1,500,Cast(Any Ptr,@tt))
Do
Var ev=WindowEvent()
If ev=EventClose Then End
Loop
Result: Shows a window where two buttons inside an invisible container move randomly together.

--- Gadget: DateCalendarGadget ---
FUNCTION: DateCalendarGadget
Syntax: Function DateCalendarGadget(ByVal gadget As long,ByVal x As long, ByVal y As long, ByVal w As long, ByVal h As long) As HWND
Description: Creates a Date and Time Picker control (Windows specific appearance).
Options:
gadget - Gadget ID.
x, y, w, h - Location and dimensions.
Platform: Windows
Example:
#Include "window9.bi"
OpenWindow("Date Picker",10,10,300,100)
DateCalendarGadget(1,10,10,200,25) // Create the gadget
ButtonGadget(2,10,50,130,25,"Set Date to Oct 26, 2000")
Do
var event=WaitEvent()
If event=eventclose Then End
If event=eventgadget Then
If eventnumber()=2 Then
SetStateCalendar(1,2000,10,26) // Set the date in the gadget
EndIf
EndIf
Loop
Result: Shows a Windows date picker control; button sets the displayed date.

--- Gadget: EditorGadget ---
FUNCTION: EditorGadget
Syntax: Function EditorGadget(ByVal gadget As Long, ByVal x As Long, ByVal y As Long, ByVal w As Long,ByVal h As Long, ByRef text As String="", ByVal style As Long=0 ,ByVal tag as long = 0) As HWND
Description: Creates a multi-line text editing control.
Options:
gadget - Gadget ID.
x, y, w, h - Location and dimensions.
text - Initial text content.
style - Style flags:
- Common: ES_CENTER, ES_LEFT, ES_RIGHT.
- Windows Only: ES_MULTILINE (implied usually), ES_AUTOHSCROLL, ES_AUTOVSCROLL, ES_LOWERCASE, ES_NOHIDESEL, ES_NUMBER, ES_OEMCONVERT, ES_PASSWORD, ES_READONLY, ES_UPPERCASE, ES_WANTRETURN. (See original doc for details). Add WS_VSCROLL / WS_HSCROLL for scrollbars.
tag - (Linux Only) Controls selection highlighting behavior. 0 = Default internal tag, 1 = Requires manual tag creation named "gui_tag_bg_fg" after gadget creation.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As integer event
OpenWindow("Editor",300,10,400,400)
EditorGadget(1,10,10,300,300, "This is an Editor Gadget." & Chr(10) & "With multiple lines.", ES_MULTILINE Or WS_VSCROLL)
Do
event=WaitEvent()
If event=EventClose Then End
Loop
Result: Shows a window with a multi-line text editor.

--- Gadget: ExplorerListGadget ---
FUNCTION: ExplorerListGadget
Syntax: Function ExplorerListGadget(byval gadget As long, byval x As long, byval y As long, byval w As long=400, byval h As long=300, byref szPath As String = "C:\", byval LGELocal As OptionsExplorerGadget ptr= 0) As HWND
Description: Creates a gadget that mimics Windows Explorer's file/folder list view, allowing navigation.
Options:
gadget - Gadget ID.
x, y, w, h - Location and dimensions.
szPath - Initial directory path to display.
LGELocal - Pointer to an OptionsExplorerGadget structure to customize column names, error messages, initial column widths, and style. Structure Definition:
Type OptionsExplorerGadget
szName As String*15 = "Name"
szSize As String*15 = "Size"
szType As String*15 = "Type"
szModified As String*15 = "Modified"
szCaptionError As String*15 = "Error"
szTextError As String*50 = "Access Denied"
iStyle As Integer = 0 ' Extended Window Style (WS_EX_...)
iOneWidth As Integer = FB_IGNORE
iTwoWidth As Integer = FB_IGNORE
iThreeWidth As Integer = FB_IGNORE
iFourWidth As Integer = FB_IGNORE
End Type
Platform: Windows
Example:
#Include "window9.bi"
CenterWindow(OpenWindow("Explorer List",10,10,440,400))
Dim OP As OptionsExplorerGadget
OP.iStyle = WS_EX_CLIENTEDGE // Add a sunken border
OP.szName = "Filename" // Custom column name
ExplorerListGadget(1,10,10,,,,@OP) // Create gadget using options
Do:Loop Until EventClose=WaitEvent()
Result: Shows an Explorer-like list view gadget.

--- Gadget: GadgetToolTip ---
FUNCTION: GadgetToolTip
Syntax: Function GadgetToolTip(ByVal parentGadget as long, ByRef text As String, ByVal gadget As long=0) As Integer
Description: Assigns a tooltip popup to another gadget.
Options:
parentGadget - ID of the gadget the tooltip should appear for.
text - The text to display in the tooltip.
gadget - Optional Gadget ID for the tooltip itself. Needed if you want to modify the tooltip later (e.g., change text, color, font) using its ID.
Platform: Windows, Linux (Color/Font changes Win only)
Example:
#Include "window9.bi"
OpenWindow("Tooltips",10,10,300,100)
StringGadget(1,10,10,100,20, "Hover Me")
ButtonGadget(2,120,10,130,20, "Hover Me Too")
GadgetToolTip(1,"This is a String Gadget's tooltip.") // Tooltip for gadget 1
GadgetToolTip(2,"This is the Button's tooltip.", 10) // Tooltip for gadget 2, with ID 10
Do
var event = WaitEvent()
If event = eventclose Then End
Loop
Result: Shows tooltips when hovering over the string gadget or button.

--- Gadget: GroupGadget ---
FUNCTION: GroupGadget
Syntax: Function GroupGadget(ByVal gadget As long, ByVal x As long, ByVal y As long, ByVal w As long, ByVal h As long, ByRef text As String="") As HWND
Description: Creates a frame with a text label, visually grouping controls placed within its bounds.
Options:
gadget - Gadget ID.
x, y, w, h - Location and dimensions of the frame.
text - Text label displayed in the top-left corner of the frame.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As integer event
OpenWindow("Group Box",300,10,300,200)
GroupGadget(1,10,10,260,150,"Options Group")
// Place other gadgets visually inside the group box area
CheckBoxGadget(2, 20, 40, 100, 20, "Option A")
CheckBoxGadget(3, 20, 70, 100, 20, "Option B")
Do
event=WaitEvent()
If event=EventClose Then End
Loop
Result: Shows a framed group box labeled "Options Group" containing two check boxes.

--- Gadget: HyperlinkGadget ---
FUNCTION: HyperLinkGadget
Syntax: Function HyperLinkGadget(ByVal gadget As long, ByVal x As long, ByVal y As long, ByVal w As long, ByVal h As long, ByRef textlink As String="") As HWND
Description: Creates a text label that looks and behaves like a web hyperlink. Clicking it generates an EventGadget event.
Options:
gadget - Gadget ID.
x, y, w, h - Location and dimensions.
textlink - The text to display (usually the URL).
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As Integer event
Dim As HWND hwnd
hwnd=OpenWindow("Hyperlink",10,10,300,100) : CenterWindow(hwnd)
Dim url as String = "https://www.freebasic.net/"
HyperLinkGadget(1,10,10,250,20, url)
Do
event=WaitEvent()
If Event=EventClose Then End
If event=eventgadget Then
If EventNumber()=1 Then
RunProgram(url) // Open the URL in default browser
EndIf
EndIf
Loop
Result: Shows clickable text; clicking opens the URL.

--- Gadget: ImageGadget ---
FUNCTION: ImageGadget
Syntax: Function ImageGadget(ByVal gadget As Long, ByVal x As Long, ByVal y As Long, ByVal w As Long, ByVal h As Long, ByVal imageId As any ptr =0, byval ExSyle As Long =0, byval Style As Long = SS_BITMAP) As HWND
Description: Creates a gadget to display a static image (bitmap or icon).
Options:
gadget - Gadget ID.
x, y, w, h - Location and dimensions.
imageId - Handle of the HBITMAP or HICON to display. Can be 0 initially and set later.
ExStyle - (Windows only) If non-zero (e.g., WS_EX_CLIENTEDGE), adds a frame/border.
Style - (Windows only) Specifies content type: SS_BITMAP (default) for bitmaps, SS_ICON for icons.
Platform: Windows, Linux
Example:
#Include "window9.bi"
Dim As integer event
OpenWindow("Image Gadget",300,10,200,150)
ImageGadget(1,10,10,32,32,Load_icon("1.ico"),,SS_ICON) // Display icon (Win)
ImageGadget(2,50,10,100,100,Load_image("1.png")) // Display bitmap
Do
event=WaitEvent()
If event=EventClose Then End
Loop
// Remember to free loaded images/icons
Result: Shows a window displaying an icon and a bitmap in separate gadgets.

--- Gadget: IpAddressGadget ---
FUNCTION: IpAddressGadget
Syntax: Function IpAddressGadget(ByVal gadget As Integer, ByVal x As Integer, ByVal y As Integer, ByVal w As Integer, ByVal h As Integer) As HWND
Description: Creates a specialized control for entering IP addresses.
Options:
gadget - Gadget ID.
x, y, w, h - Location and dimensions.
Platform: Windows
Example:
#Include "window9.bi"
Dim As integer event
dim as HWND hwnd
hwnd=OpenWindow("IP Address",300,10,230,150)
ButtonGadget(1,10,10,200,30,"Get IP Address from Gadget")
IpAddressGadget(2,10,50,150,25) // Create the control
SetIpAddress(2,"192.168.1.1") // Set an initial value
Do
event=WaitEvent()
If event=EventClose Then End
If event=eventgadget Then
If eventnumber()=1 then
MessBox("IP Entered",GetIpAddress(2)) // Get the current value
EndIf
EndIf
Loop
Result: Shows an IP address entry control; button retrieves and displays its value.

--- Gadget: ListBoxGadget ---
FUNCTION: ListBoxGadget
Syntax (Windows): Function ListBoxGadget(ByVal gadget As long, ByVal x As Long, ByVal y As Long, ByVal w As Long, ByVal h As Long, ByVal iStyle As Long=LBS_SORT Or WS_VSCROLL Or WS_HSCROLL Or LBS_NOTIFY, ByVal iStyle2 As Long=0) As HWND
Syntax (Linux): Function ListBoxGadget( iGadget as Long , x as Long, y as long, w as Long, h as long , iStyle as Long = 0 , iStyle2 as long = 0 ) as Hwnd
Description: Creates a list box control to display a selectable list of text items.
Options:
gadget - Gadget ID.
x, y, w, h - Location and dimensions.
iStyle - List box style flags.