How to use msgbox library?

Discussions related to the code libraries supplied with BB4W & BBCSDL
User avatar
zachnoland
Posts: 22
Joined: Sat 07 Dec 2024, 15:22
Location: somewhere in Southeast Asia

How to use msgbox library?

Post by zachnoland »

While I was opening the lib folder of bbcsdl I found the file msgbox.bbc. I tried looking for it in the bbcsdl manual but I didn't find any hints about this library. In this library there are 4 functions like:

Code: Select all

FN_messageboxdpi(title$, message$, flags%, dark%, scale)
FN_messageboxex(title$, message$, flags%, dark%) 
FN_messagebox(title$, message$, flags%)
FN_msgboxcb(D%, K%)     
It looks quite simple and seems easy.
I wrote the code like this, got error on line 20:

Code: Select all

   10 INSTALL @lib$+"msgbox"
   20 FN_messagebox("FIRST BASIC GUI", "HELLO, WORLD!", MB_OK)
   30 END
After I read it again I found this comment

Code: Select all

      REM Message Box for 'BBC BASIC for SDL 2.0' (replaces SDL_ShowMessageBox)
      REM Needs "dlglib" to be INSTALLed;
It seems like my journey to mastering GUI in basic is still very far.

This reminds me of Win16 API or Win32 API. So is this library Windows only, or does it work on other platforms like Android?
Richard Russell
Posts: 457
Joined: Tue 18 Jun 2024, 09:32

Re: How to use msgbox library?

Post by Richard Russell »

zachnoland wrote: Thu 24 Jul 2025, 08:28 After I read it again I found this comment

Code: Select all

      REM Message Box for 'BBC BASIC for SDL 2.0' (replaces SDL_ShowMessageBox)
      REM Needs "dlglib" to be INSTALLed;
It's arguably a weakness of BBC BASIC that there's no 'automatic' way to ensure that dependent libraries, i.e. libraries that another library relies on, are INSTALLed. There are relatively few cases of this, but they can catch you out as you found. Ones that I know about include:
  • box2ddbg.bbc needs 'box2dlib'.
  • filedlg.bbc needs 'dlglib', 'sortlib' and 'stringlib'.
  • msgbox.bbc needs 'dlglib'.
  • ogllib.bbc may need 'gleslib' and 'webgllib'.
So is this library Windows only, or does it work on other platforms like Android?
There's nothing "Windows only" in BBC BASIC for SDL 2.0, it's a cross-platform implementation of BBC BASIC!

The msgbox library, of course, works on all the supported platforms. Indeed, if you search the supplied example programs you'll find that it's used in all of the following: dibley.bbc, lemmings.bbc, recorder.bbc, sheet.bbc, textedit.bbc and SDLIDE.bbc (plus its sub-modules addconst.bbc, compiler.bbc, crossref.bbc and versinfo.bbc).
User avatar
zachnoland
Posts: 22
Joined: Sat 07 Dec 2024, 15:22
Location: somewhere in Southeast Asia

Re: How to use msgbox library?

Post by zachnoland »

Richard Russell wrote: Thu 24 Jul 2025, 09:40
  • msgbox.bbc needs 'dlglib'.
Ok I will try to learn 'dlglib'. I'm trying to create a basic messagebox with static text and an OK button.

Code: Select all

   10 INSTALL @lib$+"dlglib"
   20
   30 OSCLI "FONT """ + @lib$+ "DejaVuSans"", 12"
   40 DLG% = FN_newdialog("FIRST GUI", 100, 50)
   50
   60 PROC_static(DLG%, "HELLO, WORLD!", 0, 25, 5, 65, 10, 0)
   70 PROC_button(DLG%, "OK", 1, 35, 25, 30, 15, 0)
   80
   90 PROC_setdialogpalette(TRUE)
  100 REPEAT
  110   RESULTS% = FN_showdialog(DLG%, 10, 700)
  120 UNTIL RESULTS% = 1
  130 PROC_closedialog(DLG%)
  140 END
This is the result I got, from the basic usage of dlglib.
Richard Russell wrote: Thu 24 Jul 2025, 09:40 There's nothing "Windows only" in BBC BASIC for SDL 2.0, it's a cross-platform implementation of BBC BASIC!
I think so cuz the procedure used in msgbox reminds me of the Win32 API
You do not have the required permissions to view the files attached to this post.
Richard Russell
Posts: 457
Joined: Tue 18 Jun 2024, 09:32

Re: How to use msgbox library?

Post by Richard Russell »

zachnoland wrote: Thu 24 Jul 2025, 13:41 Ok I will try to learn 'dlglib'. I'm trying to create a basic messagebox with static text and an OK button.
Using msgbox.bbc is much easier than rolling your own with dlglib:

Code: Select all

   10 INSTALL @lib$+"msgbox"
   20 INSTALL @lib$+"dlglib"
   30
   40 RESULTS% = FN_messagebox("FIRST GUI", "HELLO, WORLD!", 0)
Having said that, dlglib gives you more flexibility and control, of course.
I think so cuz the procedure used in msgbox reminds me of the Win32 API
Message boxes are pretty generic across different operating systems, I think. If you prefer a more 'native' looking GUI you have the option of calling SDL_ShowSimpleMessageBox:

Code: Select all

   10 SYS "SDL_ShowSimpleMessageBox", 0, "FIRST GUI", "HELLO, WORLD!", FALSE, @memhdc% TO RESULTS%
Richard Russell
Posts: 457
Joined: Tue 18 Jun 2024, 09:32

Re: How to use msgbox library?

Post by Richard Russell »

Richard Russell wrote: Thu 24 Jul 2025, 16:17 Using msgbox.bbc is much easier than rolling your own with dlglib
A significant difference between msgbox.bbc and calling dlglib directly is that the former is designed to be called from 'any' program, so it automatically saves the VDU state on entry (colours, viewports, palette etc.) and restores it on exit. Therefore you can display a message box with minimal disturbance to the program from which it was called.

By contrast dlglib.bbc does none of that, it is entirely your responsibility to ensure that the VDU state is set as dlglib needs it on entry, and restore the state your program needs (if different) after the dialogue box has been dismissed. So the overhead of calling dlglib may be greater, if you don't actually need the extra flexibility it provides.