Author Topic: Smallest possible code for a MessageBox?  (Read 2068 times)

0 Members and 1 Guest are viewing this topic.

Arnold

  • Guest
Smallest possible code for a MessageBox?
« 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
« Last Edit: February 07, 2019, 04:35:14 AM by Arnold »

jack

  • Guest
Re: Smallest possibe code for a MessageBox?
« Reply #1 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)

Arnold

  • Guest
Re: Smallest possible code for a MessageBox?
« Reply #2 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
« Last Edit: February 07, 2019, 04:35:49 AM by Arnold »

JRS

  • Guest
Re: Smallest possible code for a MessageBox?
« Reply #3 on: February 07, 2019, 10:30:16 AM »
Here is my code challenge submission for the Smallest possible code for a MessageBox.

Aurel

  • Guest
Re: Smallest possible code for a MessageBox?
« Reply #4 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 )  :)
« Last Edit: February 07, 2019, 02:31:05 PM by Aurel »

JRS

  • Guest
Re: Smallest possible code for a MessageBox?
« Reply #5 on: February 07, 2019, 02:05:06 PM »
I think Charles takes the prize with PRINT generating a message box.  :)