How do I open a Open File dialog in OS X using C++? - c++

I'm working on an application using OpenGL and C++ that parses some structured input from a file and displays it graphically. I'd like to start an Open File dialog when the application loads to allow the user to choose the file they want to have displayed. I haven't been able to find what I need on the web. Is there a way to achieve this in C++? If so, how? Thank you in advance.

You have two choices, a quick one, and a good one:
Quick and pretty simple, use the Navigation Services framework from Carbon and NavCreateGetFileDialog(). You'll be done quick, and you'll have to learn almost nothing new, but your code won't run in 64-bit (which Apple is pushing everyone towards) and you'll have to link the Carbon framework. Navigation Services is officially removed in 64-bit, and is generally deprecated going forward (though I expect it to linger in 32-bit for quite a while).
A little more work the first time you do it (because you need to learn some Objective-C), but much more powerful and fully supported, wrap up NSOpenPanel in an Objective-C++ class and expose that to your C++. This is my Wrapping C++ pattern, just backwards. If you go this way and have trouble, drop a note and I'll try to speed up posting a blog entry on it.

To add to what Rob wrote:
Unfortunately, there's no simple equivalent to Windows's GetOpenFileName.
If you use Carbon: I don't really think NavCreatGetFileDialog is easy to use... you can use this code in the CarbonDev to see how to use it. The code there returns CFURLRef. To get the POSIX path, use CFURLGetFileSystemReprestnation.
That said, I recommend you to use Cocoa. Rob will write a blog post how to use NSOpenPanel from GLUT :)

Related

gtkmm for desktop application

Is it a good idea to use gtkmm gui toolkit for some desktop client application ?
Is this toolkit stable and is there enough documentation online ?
I used gtkmm to write professional applications and yes you can use it for real world software development.
But I also used C/GTK+ and C++/Qt and my opinion is that using Gtkmm you have the feeling that the original toolkit was meant to be used in C and the porting to C++ is ok but in many cases you feel that C++ features could have been used better.
For Comparison:
If you have to choose between Gtk and Gtkmm go for Gtkmm even though you might find yourself stuck in some not well documented or supported function. Eventually you always manage to find a solution (you can check the source code) and c++ is way better then c.
If you have to choose between Gtkmm and Qt, go for Qt. There is a HUGE gap between the two. Not only in the toolkit itself but in the documentation and all the other classes that you need when writing an application.
I started two month ago with gtkmm. I actually port a tcl/tk application and it feels very hard for my to get the things run. The only useful documentation I found is the https://developer.gnome.org/gtkmm-tutorial/3.4/
But many things described in the manual are not working! I actually run into trouble while overriding signal handlers which should work but didn't. Maybe you will take a look in gtkmm-list#gnome.org to find out what kind of problems yo will maybe run in :-)
The docs derived from the doxygen input seems useless for me, because the functions are mostly not described and the parameter names or often not very clear to me.
In comparison to tcl/tk the interface looks inconsistent. Sometimes a parameter must be provided by a text, sometimes by a pointer and sometimes by the native value itself. Especially the menus are very "mysterious" with the string based configuration. The need of having parameters as text is very unhandy! You have to convert the parameter with ostrstream into a text and parse the parameters sometimes yourself from text to real values.
I decided to give gtk+ a chance is the existence of the c++ interface. I thought it would be helpful to get the errors in compile time and not while running the app like with tcl/tk. But this is not the always true with gtkmm. With gtkmm you are also able to run into run time errors because all string parameters will be parsed during run time! This makes the things error prone!
Maybe I will start again and give Qt a chance. But a first view on it shows, that this seems not really better :-)
Writing a gui application still is a really annoying job!
gtkmm is a official supported binding of GTK (gtk.org/language-bindings.php).
"inkscape" and "ardour" are notable applications written in gtkmm
The bindings that are official GNOME Bindings follow the GNOME release schedule which guarantees API stability and time-based releases.
If you want to write your Application in C, go with GTK+ (and the GLib).
You can find a link to the documentation at http://www.gtkmm.org/ (https://developer.gnome.org/gtkmm-tutorial/).
With Glade (and ie. PyGTK) you could rapid prototype your application.
Building a GUI with Glade is easy and the resulting UI is a xml file, that is not bound to a programming language.

Can I make a game using c++ that will run on the web?

There is some libraries that lets you run C++. So, it is it possible to run a game that uses directx full mode screen?
Google is developing a tool to allow this kind of thing via Chrome. It is called Chrome Native Client, or NACL for short. http://blog.chromium.org/2010/05/sneak-peek-at-native-client-sdk.html
In general, no. Most online games are written with Javascript, Flash, the newly hatchedd HTML5 and similar technologies. Perhaps C++ integration is possible on some level, but you definitely cannot write a browser-hosted game purely and entirely in C++.
it could also be done with an ActiveX control. ActiveX only works in IE. there are Netscape plugins that work in other browsers. so make a solution that contains both. you need a book on ActiveX/COM/OLE. Better yet, take a class if you can find one, you will learn far more, because COM is not an easy subject to just read about and then really do - versioning is a big problem.
nope, not supported in firefox. but read this: http://www.google.com/chrome/intl/en/webmasters-faq.html#activex
some people may have activex controls disabled. if this is the case, your game will not run. you will have to tell the user that they will need to change their security settings in IE. you can get feedback from the object element in javascript as to whether or not the activex loaded. there is code out there for that.
http://msdn.microsoft.com/en-us/library/7sw4ddf8%28v=vs.85%29.aspx
examples are all over the internet.

Look for ways to enable printing from my C++/MFC application

Since time immemorial I've been trying to avoid printing from my Windows-based applications due to the lack of native support for it. Whenever absolutely necessary I was resorting to dynamically making a simple HTML layout and then opening it in a web browser with a short Java Script in it to pop up a printing dialog for a user. Now I need to find something more substantial.
Let me explain. I have a project that deals with medical charts and it has to be able to print into those charts (at specific locations) as well as print on to a Letter/A4 size page in general. It also has to provide a preview of what is being printed in a paged-view environment.
In light of that I was wondering what is available from MFC/C++ environment (not C#) in regarding to printing?
PS. I was thinking to look into the RTF format but that seems like quite a daunting task, so I was also wondering, is there any libraries/already written code that can allow to compose/view/print RTFs? If not, what else is out there that can provide printing support like I explained above?
"lack of native support"? It's been covered by Petzold since forever, and it's integrated straight into GDI. Compared to UNIX, it's a complete breeze. And MFC makes it even easier.
Anyway, here's how you do print preview with MFC, and here's how you subsequently print. Lots of links from there, and it's all straightforward. Printers are just another Device Context on which you can draw.
I always found it very convenient to generate PDF files from my MFC/C++ application, There are many libraries out there which enable easy creation of PDF files, preview functionality and so on (also open source). I'm using this (also handles RTF):
PDF Library
There is no support like you call a framework method with some parameters and the framework prints a document or the content of a window for you. You need to manually draw everything on the printing device context. So as already said, you might find it more convenient to use a PDF generator, but of course that depends on your application requirements.
Please try www.oxetta.com , it's a free report builder solution that easily integrates into a C/C++ application.

making a gui editor

For my school project, I would like to build a gui that someone else can use to create a gui. Upon some research I saw lot of gui builders but didn't see anything along the lines of what I am looking for.
But then I did find a tutorial using C# on here
I rather create this gui editor for linux environment.
Any suggestions to where I should start? what tools I can use? Any links to any tutorials?
Any help/direction would be greatly appreciated.
P.S. I would like to add that it only needs to be very simple. like few text input fields and some button type fields that user can arrange in the order desired.
I would recommend that you not try to build your own GUI builder. It is a daunting task that you will not be able to accomplish as a school project. C++ is fully-compiled, which means that it lacks almost every feature that enables people to build meta-tools (like GUI editors) for it. This mainly has to do with the fact that C++ does not have runtime reflection (natively, anyway). Beyond that, there is no "one GUI toolkit and/or paradigm to rule them all." This makes your problem incredibly difficult to deal with.
So: I would recommend Qt, because it works on a ton of platforms, is easy to use and is just plain awesome. You could also look at the billions of other GUI toolkits like Gtk+, Tk, FLTK, YAAF, GLUI, dlib, CLX...
I'm aware that this does not actually answer the question. However, I do not think that the author is aware of how incredibly difficult the task he has set in front of himself is.
I would recommend starting by implementing it like an interpreter. Start with a very simple command line tool that takes commands like window(300, 400, "window1") and button(50,100, "button1") etc and output the code (native or whatever other GUI code you want), to a file. The goal should be to output a file that can be run and show the GUI that was designed. Once you have that, build a GUI that uses the command line functions as a back-end.
I don't have any exact links to this, but here's an example of what you could do. Gtk has the option of loading a GUI by using a class called GtkBuilder. Glade (the usual Gtk gui editor) has support for outputting it's result as an XML file that the GtkBuilder class then reads.
It would be possible for your program to output an equivalently formed XML file that GtkBuilder could read.
I have no clue as to how difficult it would be to target that XML though.
You should use GTK+ or Qt if you are targeting the linux environment. I think the first step is to learn how to program gui, which takes some time considering you are writing c/c++ code wich is different from higher level languages. Don't you think learning to code gui programs and writing a gui builder at the same time is a little bit too much.? First you should master the basics about gui and then go on to harder projects.
Here's a link to an excellent book on gtk. (Foundations of gtk+ development - Andrew Krause)
http://books.google.com/books?id=L1BZZYRrqSgC&printsec=frontcover&dq=foundations+krause&hl=es&cd=1#v=onepage&q=&f=false
And here's a great tutorial/cookbook for gtk+.
http://zetcode.com/tutorials/gtktutorial/
The official documentation is on library.gnome.org
My final advice is learn one thing at a time.

How do I create a certain control using Windows Forms in Visual C++?

I am new to using Windows Forms in C++ (and just in general), and I am not exactly sure of the name or if it's even possible to do.
Currently I am currently working on a school project in which we must make a program for an imaginary bookstore. I am trying right now to make a sort of list that shows what the "customer" is buying. I have to make it sort by price and ISBN and any other variable that the book has.
In essence I am trying to make something like the following:
I just need to know how to get started. I can't figure out what the name of the control is or how to even get it to sort every time the user clicks on the header.
You need to write a managed C++
Please look at
http://www.codeproject.com/KB/miscctrl/mfcandwindowsforms.aspx?fid=3422&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=2509859
Try to do your control same way.
The WindowsForms control you are looking for is called a DataGrid
It's not entirely clear by your question, but if you are trying to access Windows Forms from standard c++ you are out of luck. Windows Forms lives in the Managed world while c++ is unmanaged. To use windows forms you'd have to switch to C++/CLI or C#. Which if you are doing something for a school project may not be an option.
If it is an option to switch languages like that. I'd start looking at C++/CLI documentation to get a feel for how things might work for you.
If you want to know Windows UI inner workings, I recommend you to stay away from .NET for now, and learn some basic things in C++ and WinAPI. Sometimes programming .NET (or C++ / COM) requires you to invoke unmanaged components/functions and you'll be glad you understand how the low-level things work.
If your project requires .NET, go on, but don't forget to make yourself some time to learn good-old Win32 / C++ programming.
Please give some more details about the question Dalze->
is there any requirement about using managed controls? or not using them?
What's your prof want you to learn from this exercise (and is how to use stack overflow to do your homework one of them)?
There's several ways to skin this cat.
If you are supposed to or want to used managed code:
DataGrid mentioned is a good simple database tool link text
An sql database could also hold all the information and allows sorting on the various sub elements.
If you choose not to use managed code you can build a few simple objects to carry the information you need, then add some sort functions for each of the variables of interest.