Download at https://www.freebasic-portal.de/downloa ... k-358.html.
Latest update on January 07, 2018
Here are some examples:
Example 1:
Window with text editor (multiline editbox) and a button to copy text from the editor to the console window:
Code: Select all
#Include "WinGUI.bi"
Dim As HWND Window_Main, Editor_txt, Button_Ok
Dim As MSG msg
'Create a window with a text editor and a button:
Window_Main = Window_New (100, 100, 400, 400, "I am a beautiful window!")
Var Label_txt = Label_New (10, 10, 150, 20, "Enter a text:",, Window_Main)
Editor_txt = Editor_New (10, 40, 360, 250, "",, Window_Main)
Button_Ok = Button_New (160, 300, 60, 20, "Ok",, Window_Main)
'Event loop:
Do
WaitEvent(Window_Main, msg)
Select Case msg.hwnd
Case Button_Ok
If msg.message = WM_LBUTTONDOWN Then
'Print text from editor on the console
Cls
Print EditBox_GetText(Editor_txt)
End If
End Select
Loop Until Window_Event_Close(Window_Main, msg)
End
Window with menu and a "Close" button
Code: Select all
#Include "WinGUI.bi"
Dim As HWND Window_Main, Button_Close
Dim As HMENU hMenu, hFile, hHelp
Dim As MSG msg
'Create a window:
Window_Main = Window_New (100, 100, 500, 500, "Test menu")
'Create menu and nenu headers:
hMenu = CreateMenu()
hFile = CreateMenu()
hHelp = CreateMenu()
'Create menu titles:
MenuTitle(hMenu, hFile, "File")
MenuTitle(hMenu, hHelp, "Help")
'Create menu items:
MenuItem(hFile, 1, "New")
MenuItem(hFile, 2, "Open")
MenuItem(hFile, 3, "Save")
MenuItem(hFile, 4, "Exit")
MenuItem(hHelp, 5, "Info")
'Assign menu to the window:
SetMenu(Window_Main, hMenu)
'Create a "Close" button:
Button_Close = Button_New(200, 200, 80, 20, "Close",, Window_Main)
'Event loop:
Do
WaitEvent(Window_Main, msg)
Select Case msg.hwnd
Case Window_Main
Select Case msg.message
Case WM_COMMAND ' Menu commands
Select Case msg.wParam
Case 1
Print "New"
Case 2
Print "Open"
Case 3
Print "Save"
Case 4
Print "Exit"
Case 5
Messagebox(0, "Test of menu functions", "Info", 0)
End Select
End Select
Case Button_Close
If msg.message = WM_LBUTTONDOWN Then Exit Do
End Select
Loop Until Window_Event_Close(Window_Main, msg)
End
A simple calculator: Write two numbers into two different edit boxex, click a button "+", "-", "*" or "/" and show the result in a third edit box
Code: Select all
#Include "WinGUI.bi"
Dim Shared As MSG msg
Dim Shared As HWND Window_Main, Edit_a, Edit_b, Edit_c, _
Button_Plus, Button_Minus, Button_Mult, Button_Div
Sub CreateWindow_Main()
'Main window
Window_Main = Window_New (200, 200, 300, 150, "Simple Calculator")
Var Label_a = Label_New (10, 10, 90, 20, "Number 1:",, Window_Main)
Edit_a = EditBox_New (100, 10, 100, 20, "0",, Window_Main)
Var Label_b = Label_New (10, 40, 90, 20, "Number 2:",, Window_Main)
Edit_b = EditBox_New (100, 40, 100, 20, "0",, Window_Main)
Var Label_c = Label_New (10, 70, 90, 20, "Result:",, Window_Main)
Edit_c = EditBox_New (100, 70, 100, 20, "0", WS_TABSTOP Or ES_READONLY, Window_Main)
Button_Plus = Button_New (210, 10, 20, 20, "+",, Window_Main)
Button_Minus = Button_New (240, 10, 20, 20, "-",, Window_Main)
Button_Mult = Button_New (210, 40, 20, 20, "*",, Window_Main)
Button_Div = Button_New (240, 40, 20, 20, "/",, Window_Main)
End Sub
Sub Calculate(ByVal method As String)
'Get a and b from edit boxes, calculate and set result c into edit box
Dim As Single a, b, c
a = Val(EditBox_GetText(Edit_a))
b = Val(EditBox_GetText(Edit_b))
Select Case method
Case "+"
c = a + b
Case "-"
c = a - b
Case "*"
c = a * b
Case "/"
c = a / b
End Select
EditBox_SetText(Edit_c, Str(c))
End Sub
'Callback functions:
Sub Button_Plus_Event()
Calculate("+")
End Sub
Sub Button_Minus_Event()
Calculate("-")
End Sub
Sub Button_Mult_Event()
Calculate("*")
End Sub
'
Sub Button_Div_Event()
Calculate("/")
End Sub
'Main:
CreateWindow_Main()
Do
WaitEvent(Window_Main, msg)
Select Case msg.hwnd
Case Button_Plus
If msg.message = WM_LBUTTONDOWN Then Button_Plus_Event()
Case Button_Minus
If msg.message = WM_LBUTTONDOWN Then Button_Minus_Event()
Case Button_Mult
If msg.message = WM_LBUTTONDOWN Then Button_Mult_Event()
Case Button_Div
If msg.message = WM_LBUTTONDOWN Then Button_Div_Event()
End Select
Loop Until Window_Event_Close(Window_Main, msg)
End
Window with a listbox and controls to add, delete, insert or replace items
Code: Select all
#Include "WinGUI.bi"
Dim As MSG msg
Dim As HWND WinMain, List, Edit_Index, Edit_SelText, Edit_Text, Button_Add, _
Button_Delete, Button_Insert, Button_Replace
Dim As Integer i, index
'Create window:
WinMain = Window_New (100, 100, 400, 400, "Test Listbox")
List = ListBox_New (20, 20, 150, 300,, WinMain)
Var Label_Index = Label_New (200, 50, 150, 20, "Selected index:",, WinMain)
Edit_Index = EditBox_New (200, 70, 150, 20, "", WS_TABSTOP Or ES_CENTER Or ES_READONLY, WinMain)
Var Label_SelText = Label_New (200, 100, 150, 20, "Selected text:",, WinMain)
Edit_SelText = EditBox_New (200, 120, 150, 20, "", WS_TABSTOP Or ES_READONLY, WinMain)
Button_Delete = Button_New (200, 150, 150, 20, "Delete selected item",, WinMain)
Edit_Text = EditBox_New (200, 200, 150, 20, "Type text here",, WinMain)
Button_Add = Button_New (200, 230, 150, 20, "Add to list",, WinMain)
Button_Insert = Button_New (200, 260, 150, 20, "Insert",, WinMain)
Button_Replace = Button_New (200, 290, 150, 20, "Replace",, WinMain)
For i = 0 To 20
ListBox_AddString(List, "Item number " + Str(i))
Next
ListBox_SetCurSel(List, 0)
Do
WaitEvent(WinMain, msg)
If msg.message = WM_LBUTTONDOWN Then
Select Case msg.hwnd
Case List
index = ListBox_GetCurSel(List)
EditBox_SetText(Edit_Index, Str(index))
EditBox_SetText(Edit_SelText, ListBox_GetText(List, index))
Case Button_Add
ListBox_AddString(List, EditBox_GetText(Edit_Text))
Case Button_Delete
ListBox_DeleteString(List, index)
Case Button_Insert
ListBox_InsertString(List, index, EditBox_GetText(Edit_Text))
Case Button_Replace
ListBox_ReplaceString(List, index, EditBox_GetText(Edit_Text))
End Select
End If
Loop Until Window_Event_Close(WinMain, msg)
End