msgbox

New to FreeBASIC? Post your questions here.
djthain
Posts: 36
Joined: Mar 31, 2006 1:53

msgbox

Post by djthain »

How do I setup a msgbox or message box in freebasic?

I got this from a visual basic example but it compiled with an error. (Array not dimensioned)

#include "windows.bi"

dim answer
answer=MsgBox("Hello everyone!",65,"Example")
document.write(answer)
diffeecult
Posts: 84
Joined: Feb 03, 2007 2:37

Post by diffeecult »

Code: Select all

#Include "windows.bi"
MessageBox NULL, "Hello Everyone", "Example", MB_ICONASTERISK
djthain
Posts: 36
Joined: Mar 31, 2006 1:53

message box

Post by djthain »

Thanks, It worked. Now I also need to identify the IDOK and IDCANCEL as in
MessageBox NULL, "Hello Everyone This is a test", "Example", MB_OKCANCEL
if IDOK=1 then beep
end

What am I doing wrong?
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

Code: Select all

#include "windows.bi"
dim as integer answer

answer=MessageBox( NULL, "Hello Everyone This is a test", "Example", MB_OKCANCEL )

' 1=first button but you can use the right constant for it
if answer=1 then
  print "ok ..."
' 2=second button but you can use the right constant for it
elseif answer=2 then
  print "cancel ..."
else
  print "ups what you are doing?"
end if

sleep
djthain
Posts: 36
Joined: Mar 31, 2006 1:53

msgbox

Post by djthain »

Thanks to everyone. You all were very helpful and everything works!
Landeel
Posts: 777
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Post by Landeel »

Very nice. But is there such a simple way to do the same on Linux???
Sisophon2001
Posts: 1706
Joined: May 27, 2005 6:34
Location: Cambodia, Thailand, Lao, Ireland etc.
Contact:

Post by Sisophon2001 »

Landeel wrote:Very nice. But is there such a simple way to do the same on Linux???
This is a gtk example on Linux...

Garvan

Code: Select all

#include once "gtk/gtk.bi"

#define NULL 0

dim as GtkWidget ptr dialog
dim as integer answer

gtk_init(NULL, NULL)


dialog = gtk_message_dialog_new(NULL, _
				GTK_DIALOG_DESTROY_WITH_PARENT, _
				GTK_MESSAGE_QUESTION, _
				GTK_BUTTONS_OK_CANCEL, _
				"Hello Everyone This is a test")

answer = gtk_dialog_run(GTK_DIALOG(dialog))

If answer=GTK_RESPONSE_OK Then
  Print "ok ..."
Elseif answer=GTK_RESPONSE_CANCEL Then
  Print "cancel ..."
Else
  Print "ups what you are doing?"
End If

gtk_widget_destroy(dialog)
Landeel
Posts: 777
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Post by Landeel »

Very nice. I'll just write a multiplatform function to do that (with IFDEF).
Thanks a lot.
Antoni
Posts: 1393
Joined: May 27, 2005 15:40
Location: Barcelona, Spain

Post by Antoni »

I asked for a built-in message box a year ago, someone told me there was no portable way to do it...it does'nt look that complicated.
Landeel
Posts: 777
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Post by Landeel »

I guess that's because it would increase the EXE size even when not used.
cha0s
Site Admin
Posts: 5319
Joined: May 27, 2005 6:42
Location: USA
Contact:

Post by cha0s »

Making fbc dependent on gtk (for messageboxes on Linux) is unacceptable.
yetifoot
Posts: 1710
Joined: Sep 11, 2005 7:08
Location: England
Contact:

Post by yetifoot »

It is kind of a problem with being cross platform, on linux using GTK is not such a good idea, for its another dependency, even if it was done in X, you have the fact that fb linux allows you to use framebuffer or whatever it is, where you don't need X, plus in DOS you have the problem, it could be done in a graphical mode, but what about text mode?

I'm sure there are ways to do it to satisfy all the different combinations, but i can imagine it being being a bit of a hacky maintenance nightmare.
Landeel
Posts: 777
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Post by Landeel »

Bah, better use external libs. :)
exagonx
Posts: 314
Joined: Mar 20, 2009 17:03
Location: Italy
Contact:

Post by exagonx »

Sisophon2001 wrote:
Landeel wrote:Very nice. But is there such a simple way to do the same on Linux???
This is a gtk example on Linux...

Garvan

Code: Select all

#include once "gtk/gtk.bi"

#define NULL 0

dim as GtkWidget ptr dialog
dim as integer answer

gtk_init(NULL, NULL)


dialog = gtk_message_dialog_new(NULL, _
				GTK_DIALOG_DESTROY_WITH_PARENT, _
				GTK_MESSAGE_QUESTION, _
				GTK_BUTTONS_OK_CANCEL, _
				"Hello Everyone This is a test")

answer = gtk_dialog_run(GTK_DIALOG(dialog))

If answer=GTK_RESPONSE_OK Then
  Print "ok ..."
Elseif answer=GTK_RESPONSE_CANCEL Then
  Print "cancel ..."
Else
  Print "ups what you are doing?"
End If

gtk_widget_destroy(dialog)
This code is fantastic Thank you the best solution
JL35
Posts: 76
Joined: Oct 02, 2007 21:11
Location: France

Post by JL35 »

Please, where could I get the syntax and parameters for the MessageBox command ?
I know: MessageBox xxx, "Text msg", "window title", MB_value
- is xxx always 'NULL', and what means it ?
- In Text msg, I have tried with success CHR(13)+CHR(10) for line feed, and CHR(9) for tab, is there something else ?
- MB_value defines the icon before 'Text msg' and the kind and number of buttons to click. e.g. ICONASTERISK, OK or OKONLY, ICONERROR, OKCANCEL, ABORTRETRYIGNORE, YESNO, YESNOCANCEL, RETRYCANCEL, etc.
- How to get the button clicked in FreeBasic, if more than one ?
Post Reply