How do I program a select folder dialogue in C++? - c++

I've been searching extensively but all of the resources are somewhat confusing as I'm very novice in programming and trying to learn. When I copy their source code over, it often has errors.
I looked on the microsoft website and found http://msdn.microsoft.com/en-us/library/system.windows.forms.folderbrowserdialog.aspx
But it was even more confusing and I"m terribly lost now. I'm open to pretty much any method, thanks!

You probably want SHBrowseForFolder:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762115(v=vs.85).aspx

First of all: walk before running.
Try to learn language appropriately step by step with some online tutorial like this:
http://www.learncpp.com
Graphical user interface is harder than basic programming. Once you know a language then select a GUI toolkit. Win32 and MFC are the classic c++ windows toolkits, but are not my favorites. As a novice perhaps you should try Java o C# before C++.
wxWidgets, GTKmm and Qt are better C++ GUI frameworks in my opinion. Each has its own hurdles. Try to learn the language and your IDE (Visual Studio, Codelite,Code::Blocks,e tc) configuration and usage to program effectively.

I suggest you look at Qt at http://www.qt.io/ and Qt Creator at http://www.qt.io/ide/. This toolkit is pretty powerful, you have a good IDE (Qt Creator), you can do zillions of things, there is a default file/folder selection dialog you can customize, and it's rather easy to port Qt applications to other operating systems like Linux or MacOS. If you want to design a GUI application, this is worth a close look. Besides, you can even integrate OpenGL graphics into your windows ...

Related

Creating many native GUI frontends for a cross-platform application

I've been away from GUI programming for quite some time so please pardon my ignorance.
I would like to attempt the following:
Write a Mac OSX app but still be able to port to Win/Linux (i.e. C++ core with Obj-C GUI)
Avoid Qt/other toolkits on OSX (i.e. talk to Cocoa directly - I feel that many Qt apps I use stick out like sore thumbs compared to the rest of my system)
Not as important, but it would be nice to avoid Visual Studio if it means I can have the freedom to use newer C++ features even on Windows if they help create better code.
I believe this configuration might get me what I'm looking for:
Core C++ Static Library
OSX GUI (Cocoa)
Windows GUI (Qt+MinGW?) OR (no new C++ features, Visual Studio + ManagedC++/C#/????)
Linux GUI (Qt)
Once again, sorry for my ignorance but is this possible? Is this sane? Are there any real-world open source examples accomplish something like this?
There is quite a few OS X applications that have completely custom-designed looks that don't use very many stock controls. iStat Menus comes to mind, but there are many other examples. They still look good, but it's done by manually designing them to look good and to "mesh" with the overall look of OS X applications. Even their preferences pane doesn't use stock buttons.
Thus, you can go quite far using Qt, you just have to pay close attention to what you're doing - similarly to the way other developers are paying close attention even when using Cocoa. You'll find that Qt's controls offer functionality often above and beyond what's offered in Cocoa.
That said, on OS X sometimes you may need to run some native code that expects a CFRunLoop to be present. It's good to know that Qt's event loop already spins a runloop for you, so as long as you have an event loop spinning in a given thread, you can use runloop-based code - the default runloop is provided by Qt's implementation of QEventDispatcher (somewhere in its guts). For non-gui threads, the unmodified QThread does it for you. This is useful for using asynchronous IOKit functionality, for example. Another answer of mine presents some Cocoa mouse event grabbing code. A previous version that used Carbon can be found in the edit history of that answer.
Same goes for Windows: Qt runs a message sink for all top-level windows it owns, and you can integrate native controls/windows using qtwinmigrate. You can also integrate ActiveX controls using the Active Qt framework.
Well I think you should try Qt even on OSX. Qt allows native/custom look of applications (those cases you mentioned are probably bad examples - you probably haven't noticed that lots of other applications also use Qt).
Tools I usually use for multi-platform development:
C++ (now C++11 since all major compilers more or less support it)
Boost
Qt
CMake as build system generator
If you use this tool-set you can choose whichever platform you like for development and still be multi-platform without extensive work on the other platforms.

Mac C++ GUI coding - comparison to Win32

I am struggling to find a good tutorial on how a Mac C++ GUI application is structured. Coming from Windows programming I'm used to message loops and window handles... is it comparable on Macs or totally different?
Any links or examples are welcome, particularly those aimed at transitioning from Win32 rather than assuming I'm a noob to programming in general.
update: I should point out this is for a game-like application so I don't need to access common controls; I essentially just need a window to render in and a message loop. I don't know if that's below the Cocoa/Carbon API level or if one or the other still has to be used.
I once was in the same situation as you. I would suggest checking out the Mac Dev Center and reading their "Getting Started" guide.
I had done a development on Mac OS X with C++. I was forced to use Carbon with it.
Then we used Qt as solution for C++ development with Mac. But I always had to compromise with bugs already present in Qt Framework. But its worth looking into to get few ideas.
Other than that Objective C++ is also nice. Though you will have to follow Cocoa Design Patterns to come with good application.

Your best library for create GUI ( gtk, qt, win32 api, etc )? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
In your opinion, what is the best way to create gui in Windows ? with gtk or win32 api ?
Do you recommend GTK for windows ? Yes ? NO ? Why ?
If you are making the gui only for windows, I would strongly recommend WIN 32 Api. I have Made many applications in GTK+ , pyGtk , FLTK and have learned Qt, MFC and SmartWin++. Believe me , But I like Win32 Api the best. It may have a steep learning curve, but for creating native windows applications , it is the fastest and the BEST. And the more complex youre program gets, the easier Win32 Api is compared to other toolkits. And there are things you can do in Win32 Api, which you can not do in any other toolkit.
TESTED:
starting time (simple gui with menu and buttons):
GTK+ = 7 secs;
Qt = 4 secs;
WxWidgets = 3.32 seconds;
FLTK = 1 second;
Win32 Api = 0.34 seconds;
space taken:
Gtk+ = 132 kb;
Qt = 4.5 mb;
WxWidgets = 4.5 mb;
FLTK = 54 kb;
Win32 Api = 6.5 kb;
Let's see.
Win32 is very low-level, C based, and awkward to use.
MFC is considered obsolete.
C# (or C++) with .NET is probably your primary choice for Windows-specific development.
There are even semi-limited ways to port that code to other platforms (Mono).
Java is great for very platform-independent code that "just runs". Sorry, you said C++.
QT is relatively platform-independent.
GTK+, of course, although I personally don't have much experience with it.
Personally, if I do something Windows-specific, I use .NET - the tools in Visual Studio are very powerful, and it's a great all-encompassing suite.
For platform-independent stuff, I use Java, but that may not be your tool of choice. I've seen QT used a lot for that purpose.
You really have a lot of GUI toolkits/frameworks to choose from: Qt, wxWidgets, GTK+/gtkmm, WinAPI, MFC, .NET WinForms/WPF... and those are only the popular ones.
Since you limit yourself to C++, I'd strike out .NET because C++ on .NET is intended to serve as a connection between the unmanaged and managed world. That doesn't mean you can't use it for other types of development, but given the awkward syntax and countless pitfalls I'd not go with it. Moreover, the WinForms code generator of VS puts the forms' code into the header file.. brrrr
As others have stated, WinAPI is written in C, very fast and powerful, but very low level and not easy to program/learn. MFC would be an option since it's written in C++, easier to use than WinAPI and also very powerful. However, it's pretty much obsolete (due to the presence of .NET, mostly).
I wouldn't recommend GTK+/gtkmm (a C++ wrapper for GTK+) for Windows since you don't get the native windows look, it's rather annoying to set up on your developer machine and it also drags around tons of dependencies that you have to install on the user machine. That's actually a pity because especially gtkmm has a very beautiful class hierarchy and design. Probably one of the best designed GUI libraries :)
That said, what would I recommend? Either Qt or wxWidgets. Both are written in (fairly modern) C++, actively developed, have a good library design, run multi-platform and offer lots of functionality. In any case, play around with a few of the libraries listed in the answers here and see which one lets you do the things you want to do most easily :)
both are for c, but there is a good wrapper for gtk (gtkmm).
gtk has its own look, so theres no skinning of ui elements on the user side(with windows styles). but i like to programm with it more.
win32, mfc, .net are mostly limited to ms visual studio, while gtk is very hard to use with vs.
you should have a look on win32, .net, gtkmm and qt. just try to write and compile a simple hello world program with them
upsides of win32:
native windows code
fast
downsides:
no classes, only c with handles (very crappy)
in my opinion very bad documented
upsides of gtk(mm):
easy to learn/programm
good documented
downsides:
somehow difficult to install the development files
no native windows look
win32 api is too complicated, MFC is too annoying.
I have used MFC, win32api, and Qt in windows. In my opnion, Qt is the best one.
I havent tried GTK, so sorry knowing nothing about it.
Edit 2019: It looks all these options are outdated, how about the cross-platform solutions, react-native windows, electron
If Linux (or Mac) compatibility is your concern, then Qt. Else Win32.
I have used GTK+ in the past for a multi-platform application. I found it relatively simple to learn and use. To my mind the main advantage of GTK+ is that you will be able to port your application to other windowing systems. And the main disadvantage is that it will not look exactly like other windows applications. If you are doing cross platform work or are already very familiar with GTK+ (and don't have time to spend learning a new toolkit), I would recommend it.
Personally I prefer Qt, but it really depends on what kind of user interfaces you want to make.
Against Win32:
low-level, high complexity to accomplish trivial things. You have to do EVERYTHING
if you go this route I would recomment a book like the one from Petzold.
Pro Qt:
Good looking GUIs
Can change the look and feel very easily by creating stylesheets
Signal and slots mechanism notifies you of UI events such as "button clicked" etc.
Nice layout system
Integrated with Visual Studio IDE
Modern object oriented c++ code, easy to understand and use
Qt Assistant (Very good documentation)
Relatively liberal licensing (LGPL)
Qt Designer - WYSIWYG design tool you can use for form design
Comes with a wealth of other c++ functionality including XML, networking, eventloops,
threading, database access, etc
Against Qt:
Intermediary step of using MOC compiler
Pro WPF:
if you want the new WPF capabilities of the new Windows platforms, WPF is the way to go.
You may want to try Winforms or WPF. If you're limited to using C/C++, you can embed .NET code using the /clr option for the compiler to embed .NET code for Winforms or WPF.
Sources:
http://msdn.microsoft.com/en-us/library/k8d11d4s(VS.71).aspx
http://msdn.microsoft.com/en-us/library/ms754130.aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.aspx
Personal experience
For platform independent development, I would recommend Qt instead of the current GTK. GTK2 drawing was very slow compared to Qt as well as Win32. If you love native look feel, wxWidgets is made for you.

Migrating from C# to native windows C++

I want to develop native c++ windows application using windows API.
but i find it being difficult because i am unable to render the window and drag and drop components, change the location etc..
How can i view, drag and drop components like i can do in C# ?
May be there is no way to do. if so, what is the fastest procedure to design the application ?
If you like so much the drag and drop of components (and of course for good reason) why would you need to develop it using C++? You can use PInvoke if you need to call some C++ functions from C# code that are not in the .net framework.
But if you really insist, maybe you could try QT.
Using a library framework such as Qt is really the way you want to go. It makes things very simple and still allows you to write code in std c++ to keep most things very fast.
If you EVER have intentions of porting the code to a different platform than windows (whether it be Mac, Linux or even Android ... yes its possible), qt is definately the way you're going to want to go.
I can get an app up and running... smoothly in a few minutes using Qt but much longer and with more confusion using MFC.
Dragging and dropping 'widgets' to form a gui is very easy and possible with Qt's built-in QtDesigner!!! Check it out!!!
http://qt.nokia.com/downloads
Assuming you are using Visual Studio, if your app can be implemented as a dialog box, then you can use the dialog editor to lay things out. Otherwise, you just have to write code to create the windows and place controls. Look at the MFC examples included with Visual Studio.
Jeff Prosise's PROGRAMMING WINDOWS WITH MFC was one of the better books for learning how to do this, but I think it is out of print, and so could be hard to find.
Charles Petzold's PROGRAMMING WINDOWS is the bible for the Win32 API. Again, may be hard to find these days.
If MFC isn't your cup of tea, you could also look at QT, GTK+, or wxWidgets. There are GUI builders for each of those, but they are all pretty primitive compared to what you can do with C#.
As far as I know there is no ide out there that will let you "drag and drop create" standard win api windows like you would with C#.
Personally for that kind of application I always recommend Borland C++ Builder (Which is now Codegear Rad studio)
Although it is not standard API, it allows you to drag an drop and static linking is very easy, so you dont have to worry about redistributables

Start Windows GUI Application Development With C++

I'm looking into creating a GUI program for Windows in C++, I have a good knowledge of C++ in the command line and also in game creation. But I'm not sure where to start with GUI application development.
I have Visual Studio 2010 and have created new projects with a GUI but these templates are complex and leaves me not understanding whats happening and how to modify it.
So I'm asking where do I start? Preferably good websites that you can recommend or tutorials, rather than books being a poor student :)
Having written Windows code since Win2.0, I have to say: start with C#. It's a very easy language to learn after C++, and many of the new features (like built-in event handling) were put there to make writing GUI applications easier.
Then, once you're used to the basic concepts of window management and messaging, then drop down into C++.
I say this for the same reason that assembly is not a good first language. There is an enormous amount of housekeeping code in a Windows application, and in C++ you see it all. Better to use a language that hides much of it until you're grounded.
I'd personally recommend using Qt instead to develop your GUI.
Use a GUI framework/library that hides the dirt from the low-level GUI api. MFC is not a solution - it is only a thin layer above the WinAPI. I recommend using QT or wxWidgets. If you use Qt use the Qt creator/Qt designer to design interfaces. If you use
wxWidgets use wxFormBuilder.