Oxygen Basic

Programming => Example Code => General => Topic started by: Arnold on February 07, 2019, 01:56:45 AM

Title: Smallest possible code for a MessageBox?
Post by: Arnold on February 07, 2019, 01:56:45 AM
Hello,

I am not a user of Freebasic, although I am interested in this language and would like to learn more about the possibilities. I was able to create a MessageBox in Freebasic without using windows.bi:
Code: [Select]
'fbc -s gui "msgboxFB.bas"

Declare function MessageBox alias "MessageBoxA"(byval hWnd as long ptr, byval lpText as zstring ptr, byval lpCaption as zstring ptr, byval uType as ulong) as Long
MessageBox(0, "Ok","FreeBasic", 0)

This is also possible in Oxygenbasic:
Code: [Select]
$ filename "msgboxO2.exe"
'uses rtl32
Declare function MessageBox alias "MessageBoxA" lib "user32.dll" (byval hWnd as sys, byval lpText as zstring ptr, byval lpCaption as zstring ptr, byval uType as uint) as Long
MessageBox(0, "Ok","OxygenBasic", 0)

In Oxygenbasic I can also apply this code:
Code: [Select]
$ filename "msgboxO2.exe"
'uses rtl32
Declare function MessageBox alias "MessageBoxA" lib "user32.dll"
MessageBox(0, "Ok","OxygenBasic", 0)

Is something similar possible in Freebasic too?

Roland
Title: Re: Smallest possibe code for a MessageBox?
Post by: jack on February 07, 2019, 03:07:23 AM
hello Arnold
you can specify a dll in FreeBasic, but it's not needed as in your example.

Code: [Select]
extern  "Windows-MS" lib "user32.dll" '' Extern { "C" | "C++" | "Windows" | "Windows-MS" } [ Lib "libname" ]
Declare function MessageBox alias "MessageBoxA"(byval hWnd as long ptr, byval lpText as zstring ptr, byval lpCaption as zstring ptr, byval uType as ulong) as Long
end extern

MessageBox(0, "Ok","FreeBasic", 0)
you may omit the alias clause and use MessageBoxA instead
Code: [Select]
extern  "Windows-MS" lib "user32.dll" '' Extern { "C" | "C++" | "Windows" | "Windows-MS" } [ Lib "libname" ]
Declare function MessageBoxA(byval hWnd as long ptr, byval lpText as zstring ptr, byval lpCaption as zstring ptr, byval uType as ulong) as Long
end extern

MessageBoxA(0, "Ok","FreeBasic", 0)
Title: Re: Smallest possible code for a MessageBox?
Post by: Arnold on February 07, 2019, 04:01:30 AM
Hi Jack,

thank you for the code. I found the corresponding places in the Freebasic help file. Using "Windows-MS" failed, but "Windows" succeeded with my system. Although the example looks simple it was very instructive for me.

Roland
Title: Re: Smallest possible code for a MessageBox?
Post by: JRS on February 07, 2019, 10:30:16 AM
Here is my code challenge submission for the Smallest possible code for a MessageBox (https://www.scriptbasic.org/forum/index.php/topic,105.msg230.html#msg230).
Title: Re: Smallest possible code for a MessageBox?
Post by: Aurel on February 07, 2019, 01:36:42 PM
I already have one :

Info ("hello!")

if you don't believe here is it:

(..i also fix one stupid bug in awinh )  :)
Title: Re: Smallest possible code for a MessageBox?
Post by: JRS on February 07, 2019, 02:05:06 PM
I think Charles takes the prize with PRINT generating a message box.  :)