C++: MessageBox with MacosX?

Hi

Did someone knows an equivalent to messagebox function working with macosX?
I really need a simple function like this, in C++, to continue my development!

Thank you

macbook, Mac OS X (10.5.5), Have all kind of computer & Os except Novell IBM & BeOS

Posted on Oct 17, 2008 7:59 AM

Reply
23 replies

Oct 17, 2008 12:47 PM in response to globoeil

You don't want to use that function. You would have to figure out how to make old-style MacOS resources (and include them in your app!). You have a new Macbook that doesn't run Classic and, hence, can't run RezEdit, so you would have to figure out how to compile the resource files using the compiler. You would have to learn how to make a Universal Proc Pointer.

In sort, it is much, much easier to learn Objective-C and use NSBeginAlertSheet, NSAlert, or any number of other options.

Oct 17, 2008 6:03 PM in response to globoeil

Sure, it's possible. Add one or more alert resources to your application. By resources, I mean an actual resource fork. Then call one of the Alert functions. You can also put together the Window by hand and do modalDialog. That is more involved than a MessageBox/Alert function though.

The Carbon library is a compatibility library so that old MacOS applications can be re-compiled and run with (relatively) minor changes on MacOS X. Much of the infrastructure needed to build these old applications is gone. Very few people know how to do this in Xcode because, back in the day, we all did it with RezEdit and Codewarrior.

Yes, it is absolutely possible. It probably isn't even that difficult. However, if you aren't familiar with how things used to be done 10 years ago, it will probably be much, much more difficult. I'm not all that familiar with it because I always used 3rd party tools to make the process less horribly painful. Today, I have no idea how to build an application with an actual resource fork. I could probably figure it out if I had to, but I don't.

Oct 18, 2008 7:27 AM in response to orangekay

Thank you for the link!
It can be helpful, but I think I had to include Carbon/Carbon.h in my project, and I have a lot of errors (36 errors).

I created a "SDL Standard application" with Xcode, simply, and all I want is add a quick message box (as shown in your link).
But in your link, if I copy the example, it doesn't compile!

I just wanted an equivalent of the 2 only required lines in Windows:

#include <windows.h>
MessageBox(NULL,"Title", "Message", MB OK|MBICONINFORMATION);

Is it really too complicated to show a simple message box with MacOSX? If I had to spend too much time to code such simple things, I'll have to stop MacosX support of my program (lack of time), so please help me to understand how to do =D

Oct 18, 2008 8:38 AM in response to globoeil

Glo, you can add frameworks at will.

You can create any project-type you like and add what you need. I only suggested it because I think you may be having fundamental issues in how to use Xcode. Maybe that's not the case.

Here's the simplest program I can think of to show a message box.


#include <Carbon/Carbon.h>
int main (int argc, const char * argv[]) {
DialogRef alertDialog;

CreateStandardAlert(kAlertStopAlert, CFSTR("foo"), CFSTR("bar"),NULL, &alertDialog);

RunStandardAlert (alertDialog, NULL, NULL);
return 0;
}

Oct 18, 2008 5:04 PM in response to globoeil

What is SDL? I don't have anything like that in my Xcode. Is that the 3rd party Simple DirectMedia Layer? Is this the origin of your C++ requirement?

While I congratulate people on finding that MacOS 8.5 Appearance Manager function, there is no reason why you can't have some Cocoa source files that export their behavior as pure C functions. You don't really want your App stuck in that pre-MacOS X compatibility world.

If you really insist on C only, and this is a Simple DirectMedia Layer application, then you'll have more luck trying to add the Carbon framework to that rather than trying to add SDL support to the standard Carbon project.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

C++: MessageBox with MacosX?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.