Reputation:
I have written a C++ application, which I built using g++.
For the purposes of demonstrating this code I want to create a simple GUI, under Windows, I thought it would be a relatively simple task to create this using Visual Studio's GUI builder.
With some stress I have got to the point where I can build and run the C++ app through a Visual Studio 2010 workspace.
So I add a new class, I choose "Windows Form", it gives me a form that I can drag stuff onto, great. How the hell do I integrate this?
Can I not just create an instance of this class in my main function?
How do I even get the form to show when I run the program?
I really have no idea where to start, my experience is in using C and Java, I don't have much experience with C++ and I have absolutely no idea about Visual Studio.
All I want is a GUI class to handle user input and right now it seems impossibly difficult.
Any guidance would be very much appreciated, I'll come back to this when my blood pressure returns to a safe level.
Upvotes: 4
Views: 11590
Reputation: 4838
one problem i have always had with c++ is that unlike java, there are no standard gui libraries provided with the language. in summary if you want gui's in c++ you have to choose a library and there are many choices-
win32 api, mfc, winforms, and lately wfp(for .net developers). I wont say any more about these.
There is also qt which is provided by nokia. Personally i have tried win32 and mfc and qt and i prefer qt. To create your simple gui
ui.myLineEdit->setText("Hello world");
Gui development is wide. I hope this helps if you are in a hurry.
For a quick video introduction, you could also try ics video tutorials
Upvotes: 4
Reputation: 43
I'm not sure, if I understand you correctly but I think the easiest way to make c++ code useful in any Visual Studio project is to compile your c++ code into dll and add dll reference to the project. Then you have access to all of methods in library (other possibility is using COM object, if dll is COM visible).
If your dll can't be added this way you can just write a binding to it, to make possible using it from managed code. Here is example of how prepare such binding: http://www.codeproject.com/KB/mcpp/usingcppdll.aspx
Upvotes: 2
Reputation: 53850
You are going about it backwards. You need to call your program from the GUI. You can't instantiate a "GUI class" from your main.
If you are just doing a proof of concept, why not create a gui app that shells out and calls your program from the command line. You wouldn't even need to use c++, you could do it in c#.
Otherwise you will need to refactor your program to be able to be called programatically from your gui app.
Upvotes: 1