This version does not use the Windows System Dialog Box (window class "#32770"), so programming a GUI is in line with the standard procedure (registering a window class and using a window callback function (WndProc)). The syntax of the already existing library has been taken largely so that coding a GUI should be fairly simple and clear.
Code example: a simple calculator (enter two numbers, add, subtract, divide or multiply and show the result):
Code: Select all
#Include "WinLib.bi"
Dim Shared As HWND MainWindow, Text_a, Text_b, Text_c, Button_Plus, Button_Minus, Button_Mult, Button_Div
Sub Calculate(ByVal method As String)
'Get a and b from Text boxes, calculate and set result c into Text box
Dim As Single a, b, c
a = Val(TextBox_GetText(Text_a))
b = Val(TextBox_GetText(Text_b))
Select Case method
Case "+"
c = a + b
Case "-"
c = a - b
Case "*"
c = a * b
Case "/"
c = a / b
End Select
TextBox_SetText(Text_c, Str(c))
End Sub
Function WndProc(ByVal hWnd As HWND, ByVal message As UINT, ByVal wParam As WPARAM, _
ByVal lParam As LPARAM ) As LRESULT
Select Case message
Case WM_CREATE
Var Label_a = Label_New (10, 10, 90, 20, "Number 1:",, hWnd)
Text_a = TextBox_New (100, 10, 100, 20, "0",, hWnd)
Var Label_b = Label_New (10, 40, 90, 20, "Number 2:",, hWnd)
Text_b = TextBox_New (100, 40, 100, 20, "0",, hWnd)
Var Label_c = Label_New (10, 70, 90, 20, "Result:",, hWnd)
Text_c = TextBox_New (100, 70, 100, 20, "0", ES_READONLY, hWnd)
Button_Plus = Button_New (210, 10, 20, 20, "+",, hWnd)
Button_Minus = Button_New (240, 10, 20, 20, "-",, hWnd)
Button_Mult = Button_New (210, 40, 20, 20, "*",, hWnd)
Button_Div = Button_New (240, 40, 20, 20, "/",, hWnd)
Case WM_COMMAND
Select Case lParam
Case Button_Plus
Calculate("+")
Case Button_Minus
Calculate("-")
Case Button_Mult
Calculate("*")
Case Button_Div
Calculate("/")
End Select
Case WM_DESTROY
PostQuitMessage(0)
Exit Function
End Select
Return DefWindowProc(hWnd, message, wParam, lParam)
End Function
RegisterWindowClass("WindowClass", @WndProc)
MainWindow = Window_New("WindowClass", 200, 200, 300, 150, "Simple Calculator")
RunMessageLoop()
End