BewertungBisher keine Bewertung
(Zum Abstimmen auf die Sterne klicken.)
Dies ist eine modifizierte Version der bereits hier vorhandenen Bibliothek (downloads/bibliotheken/wingui-eine-einfache-winapi-gui-bibliothek-358.html. Es wird nicht die Windows System Dialog Box (Fensterklasse "#32770") verwendet, so dass die Programmierung eines GUI dem standardmäßigen Vorgehen entspricht (Registrieren einer Fensterklasse und Verwendung einer Callback-Funktion (WndProc) für das Fenster). Die Syntax der bereits vorhandenen Bibliothek wurde weitgehend übernommen, so dass die Codierung eines GUI relativ einfach und übersichtlich erfolgen kann.
This is a modified version of the existing library (downloads/bibliotheken/wingui-eine-einfache-winapi-gui-bibliothek-358.html. 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.
Coded with FreeBASIC version 1.10.0
Tested with Windows 11
Project Site: https://www.freebasic.net/forum/viewtopic.php?t=32421
Code example:
'===============================================================================
' GUI_Template.bas
' Template with Menu, Textbox, Editor, Buttons, Listbox
' Created on November 23, 2022
' Last changed on October 12, 2023
'===============================================================================
#Include "WinLib.bi"
Dim Shared As HMENU hMenu, hFile, hHelp
Dim Shared As HWND MainWindow, Text1, Text2, List1, Button1, Button2
Function WndProc(ByVal hWnd As HWND, ByVal message As UINT, ByVal wParam As WPARAM, _
ByVal lParam As LPARAM ) As LRESULT
Dim As HFONT Font
Dim As Integer i
Dim As String text
Select Case message
Case WM_CREATE
'Menu:
hMenu = CreateMenu()
hFile = CreateMenu()
hHelp = CreateMenu()
MenuTitle(hMenu, hFile, "File")
MenuTitle(hMenu, hHelp, "Help")
MenuItem(hFile, 1, "New")
MenuItem(hFile, 2, "Open")
MenuItem(hFile, 3, "Save")
MenuItem(hFile, 4, "Quit")
MenuItem(hHelp, 5, "?")
SetMenu(hwnd, hMenu)
'Controls:
Var Label1 = Label_New (20, 20, 200, 20, "Enter a text here:",, hWnd)
Text1 = TextBox_New (20, 50, 200, 20, "Text ...",, hWnd)
Button1 = Button_New (60, 80, 100, 20, "Copy",, hWnd)
Text2 = TextEditor_New (20, 120, 300, 200, "Enter text!",, hWnd)
Button2 = Button_New (340, 200, 100, 20, "Copy",, hWnd)
List1 = ListBox_New (20, 350, 200, 200,, hWnd)
'Font for the editor:
Font = Control_Createfont("Courier New", 16, 8)
Control_Setfont(Text2, Font)
TextBox_SetText(Text2, "Please write a text here!")
'Fill listbox:
For i = 0 To 20
ListBox_AddString(List1, "Item No. " & Str(i))
Next
Case WM_COMMAND
Select Case LoWord(wParam)
'Menu:
Case 1
MessageBox(0, "New file ...", "File", 0)
Case 2
MessageBox(0, "Open ...", "File", 0)
Case 3
MessageBox(0, "Save ...", "File", 0)
Case 4
SendMessage(hWnd, WM_CLOSE, 0, 0)
Case 5
MessageBox(0, "I am sorry, I cannot help you!", "Help", 0)
End Select
Select Case lParam
Case Button1
'Copy text from Text1 to console:
text = TextBox_GetText(Text1)
Print text
Case Button2
'Copy text from Text2 to console:
text = TextBox_GetText(Text2)
Print text
Case List1
If HiWord(wParam) = LBN_SELCHANGE Then
'Copy selected index and text to console:
i = ListBox_GetCurSel(List1)
text = ListBox_GetText(List1, i)
Print i; Space(1); text
End If
End Select
Case WM_PAINT
Case WM_SIZE
Case WM_KEYDOWN
If(LoByte(wParam) = 27) Then PostMessage(hWnd, WM_CLOSE, 0, 0)
Case WM_DESTROY
Control_Deletefont(Font)
PostQuitMessage(0)
Exit Function
End Select
Return DefWindowProc(hWnd, message, wParam, lParam)
End Function
RegisterWindowClass("WindowClass", @WndProc)
MainWindow = Window_New("WindowClass", 10, 10, 500, 650, "Windows GUI")
RunMessageLoop()
End
|