|
Post by Marco Kurvers on Mar 9, 2024 9:54:15 GMT
In addition to the built-in dialog boxes, it is also possible to create your own dialog boxes.
|
|
|
Post by Marco Kurvers on Mar 9, 2024 9:59:38 GMT
The example below shows how to create a MessageBox. You can determine which controls the window needs based on the given constants.
'*** MessageBox zonder API *** ' Zonder Icon 'gebruik onderstaande losse LB variabelen of de ingebouwde ID constanten van Liberty BASIC 'LB.OK = 1 '_IDOK 'LB.Cancel = 2 '_IDCancel 'LB.Abort = 3 '_IDAbort 'LB.Retry = 4 '_IDRetry 'LB.Ignore = 5 '_IDIgnore 'LB.Yes = 6 '_IDYes 'LB.No = 7 '_IDNo
'Toegestane iconen '_MB_ICONASTERISK '_MB_ICONERROR '_MB_ICONEXCLAMATION '_MB_ICONHAND '_MB_ICONINFORMATION '_MB_ICONNONE '_MB_ICONQUESTION '_MB_ICONSTOP '_MB_ICONWARNING
'Toegestane buttons '_MB_ABORTRETRYIGNORE '_MB_OK '_MB_OKCANCEL '_MB_RETRYCANCEL '_MB_YESNO '_MB_YESNOCANCEL
global DialogResult 'welke knop geklikt global buttonConstant 'welke knoppen zijn aanwezig
call TestMessage
sub TestMessage WindowWidth = 300 WindowHeight = 200 button #w.btnMsg, "Bericht", btnMsg, UL, 20, 20 button #w.btnQuestion, "Vraag", btnQuestion, UL, 20, 70 button #w.btnResult, "Resultaat", btnResult, UL, 20, 120 stylebits #w, 0, _WS_MINIMIZEBOX, 0, 0 open "TestMessage" for window as #w #w "trapclose Quit" wait end sub
sub Quit handle$ close #handle$ end end sub
sub btnMsg handle$ call MsgBox "Mededeling", "Dit berichtvenster werkt." end sub
sub btnQuestion handle$ call ShowDialog "Vraag", "Weet je het zeker?", _MB_ICONQUESTION, _MB_YESNO 'call ShowDialog "Fout!", "Je hebt een fout gemaakt!", _MB_ICONERROR, _MB_OK 'call ShowDialog "Downloadfout", "Kan het bestand niet verder downloaden.", _MB_ICONEXCLAMATION, _MB_ABORTRETRYIGNORE end sub
sub btnResult handle$ select case DialogResult case _IDOK s$ = "OK" case _IDCancel s$ = "Annuleren" case _IDAbort s$ = "Stoppen" case _IDRetry s$ = "Opnieuw" case _IDIgnore s$ = "Overslaan" case _IDYes s$ = "Ja" case _IDNo s$ = "Nee" end select call MsgBox "Resultaat", "Je hebt op de "; s$; " knop geklikt." end sub
sub MsgBox title$, bericht$ WindowWidth = len(bericht$) * 16 WindowHeight = 4 * 64 statictext #dlg.lblIcon, "!", 40, 20, 55, 55 statictext #dlg.lblMsg, bericht$, 120, 80, WindowWidth - 56, 35 button #dlg.btnOK, "&OK", btnOK, UL, WindowWidth - 130, WindowHeight - 100, 100, 35 open title$ for dialog_modal as #dlg #dlg "trapclose CloseDialog" #dlg.lblIcon "!font arial 32" wait end sub
sub btnOK handle$ DialogResult = _IDOK close #dlg end sub
sub ShowDialog title$, bericht$, icon, buttons select case icon case _MB_ICONASTERISK icon$ = "*" case _MB_ICONERROR icon$ = "X" case _MB_ICONEXCLAMATION icon$ = "!" case _MB_ICONINFORMATION icon$ = "I" case _MB_ICONQUESTION icon$ = "?" case else icon$ = "" end select WindowWidth = len(bericht$) * 16 if WindowWidth < 400 then WindowWidth = 400 WindowHeight = 4 * 64 if icon$ <> "" then statictext #dlgMsg.lblIcon, icon$, 40, 20, 55, 55 statictext #dlgMsg.lblMsg, bericht$, 120, 80, WindowWidth - 56, 35 else statictext #dlgMsg.lblMsg, bericht$, 40, 80, WindowWidth - 56, 35 end if EersteKnop$ = "" TweedeKnop$ = "" DerdeKnop$ = "" buttonConstant = buttons 'de knoppen moeten herkent worden in de click events select case buttons case _MB_ABORTRETRYIGNORE EersteKnop$ = "&Stoppen" TweedeKnop$ = "&Opnieuw" DerdeKnop$ = "O&verslaan" case _MB_OK EersteKnop$ = "&OK" TweedeKnop$ = "" DerdeKnop$ = "" case _MB_OKCANCEL EersteKnop$ = "&OK" TweedeKnop$ = "&Annuleren" DerdeKnop$ = "" case _MB_RETRYCANCEL EersteKnop$ = "&Opnieuw" TweedeKnop$ = "&Annuleren" DerdeKnop$ = "" case _MB_YESNO EersteKnop$ = "&Ja" TweedeKnop$ = "&Nee" DerdeKnop$ = "" case _MB_YESNOCANCEL EersteKnop$ = "&Ja" TweedeKnop$ = "&Nee" DerdeKnop$ = "&Annuleren" case else EersteKnop$ = "&OK" TweedeKnop$ = "" DerdeKnop$ = "" end select button #dlgMsg.btnEerste, EersteKnop$, btnEerste, UL, WindowWidth - 310, WindowHeight - 100, 100, 35 if len(TweedeKnop$) > 0 then _ button #dlgMsg.btnTweede, TweedeKnop$, btnTweede, UL, WindowWidth - 220, WindowHeight - 100, 100, 35 if len(DerdeKnop$) > 0 then _ button #dlgMsg.btnDerde, DerdeKnop$, btnDerde, UL, WindowWidth - 130, WindowHeight - 100, 100, 35 open title$ for dialog_modal as #dlgMsg #dlgMsg "trapclose CloseDialog" #dlgMsg.lblIcon "!font arial 32" wait end sub
sub CloseDialog handle$ close #handle$ end sub
sub btnEerste handle$ select case buttonConstant case _MB_ABORTRETRYIGNORE DialogResult = _IDAbort case _MB_OK, _MB_OKCANCEL DialogResult = _IDOK case _MB_RETRYCANCEL DialogResult = _IDRetry case _MB_YESNO, _MB_YESNOCANCEL DialogResult = _IDYes end select close #dlgMsg end sub
sub btnTweede handle$ select case buttonConstant case _MB_ABORTRETRYIGNORE DialogResult = _IDRetry case _MB_OKCANCEL, _MB_RETRYCANCEL DialogResult = _IDCancel case _MB_YESNO, _MB_YESNOCANCEL DialogResult = _IDNo end select close #dlgMsg end sub
sub btnDerde handle$ select case buttonConstant case _MB_ABORTRETRYIGNORE DialogResult = _IDIgnore case _MB_YESNOCANCEL DialogResult = _IDCancel end select close #dlgMsg end sub
|
|
|
Post by Marco Kurvers on Mar 9, 2024 10:06:33 GMT
Maybe, the buttons do not stay on the perfect place. Can you place them so that there is an offset between the buttons?
See more about the dialogwindows on my Liberty BASIC ebook. If the dutch version is ready, then I make an English version too.
|
|