user602095
user602095

Reputation:

Visual Studio: Creating a simple GUI

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

Answers (3)

Dr Deo
Dr Deo

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

  • 1. download qt for visual studio(google search)
  • 2. download the qt visual studio addin.This eases the pain of compiling qt apps in vs[download the addin here][1]
  • 3. create a new qt application from visual studio and use qt designer to add any user interface elements(widgets).
  • 4.Add your methods to the generated class to do your specific logic. If you need to say print some text eg to a line edit called myLineEdit, use some thing like this
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

ShaQ
ShaQ

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

Byron Whitlock
Byron Whitlock

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

Related Questions