Hi every one,

I'm working in a code from 1 mounth, and now I finaly finished, it work, but there is the old problem in C++ language, the interface, once that I wan't to do a program that will be used for anothers users, I wanna to make the program more friendly to the user.

I'm search a lot of plataforms and tutorials to make the GUI interface, and I choose the wxDEV - C++ program(looks like wxWidgets), once I develop the program in dev-c++. But I have a big problem to integrate my code to the plataform(create butons,forms,windows I know).

Basically, my program are doing this:

1 - Read data from text file
2 - Put the data from file to a stristream
3 - Tokenize the stringstream e transform into a vector.
4 - Make calcs with this vectors.
5 - Output the vectors in texts files.

And I wanna to create some dialog boxes(to imput the name of the file for example), another boxes that show some results of the calcs, and if possible, create a grapich with the values of the vectors.

Anyone can help me?

Ps.: I don't post the code because he have 1300 lines =].

Recommended Answers

All 16 Replies

Unfortunately, it's a pain (but not impossible by any stretch) to retrofit a complete piece of code to a GUI.

How comfortable are you with the GUI toolkit already? (like have you made a "Hello, GUI" with buttons or are you able to display a text file in a textbox? Those are the kinds of fundamentals that you'll need to get up to speed on first before trying to figure out where to place your existing code. With those ideas in place, you should start to see how things can be parceled up.

Since most GUI libraries are OOP based, in my opinion it is slightly easier to use objects with them. IIRC, your code that you were writing was more procedural, so I don't know how viable an option it is to do that.

Try it out, and see what specific problems you run into.

Hi, I'm capable to do the basics, the problem is: my program uses about 30 vectors, and all this vectors are relacionated... So, what i wanna to now is how a value digited in a dialogbox is put into my original variable from the code.

And how i run the program in "background", once i just have to digited 2 values(name of the file, number of target "scan"), and the program run and gave to me some values, this values I'll put into another boxes. If you look close, the program is very simple.

a value digited in a dialogbox is put into my original variable from the code.

Well, if it was a textbox (and I don't know anything about wxWidgets, so I'll speak in generalities) it's likely a string of some sort. If the user types a number in that box, you'll have to access the string, turn it into a number, and then add it into your vector.

//inventing my own GUI toolkit with a JSTextBox object
std::vector<float> fv;
std::string textboxval = JSTextBox1->Text;
std::stringstream ss(textboxval);  //other ways to do this
float tempvalue;
ss >> tempvalue;
fv.push_back(tempvalue); //so instead of adding to your vector directly in the code, you have to parse the value from the textbox

run the program in "background"

You'll place the code for that stage of processing in a button handler, so that when you click the button, that code is executed.

Well if you intend to use wxWidgets .

will help you get the path for the file you intend to open up.

A simple text box can be used in order to hold the number , or there are other implementations such as wxSpinCtrl
can be used.

Then a wxButton to make a submit button can be specified.
Declare the event list and define the submit button to trigger a function call.

In that function call you might be interested in getting values from the File Dialog and The Spin Control and sending it to a function that does the background work.

Maybe show the status in Status Bar implementation of WxWidgets.

What i wan't to do is this:

1. Make a box(I don't know what type), that the user inputs the diretory/name of the file that will be open.
2. Make a button that executes my entire program.
3. Make another boxes that shows some informations gerated by the program(these informations are in vectors).
4. Put images in the window.

I can work in any plataform, windows aplication, wxDev, but i have to know how i make the linkage betwen my program and this program, like jonsca said



JSTextBox was just an imaginary construct to prove my point. :) SkyDiploma is giving you the actual information for wxWidgets.

I think if you spend a bit more time learning about the GUI, it will become more evident to you how your code needs to be split up.

I understand jonsca, that is just a example, but i really need examples to know how the basic programig in wxDEV works. For than make a "conversion" from the code to the GUI language(once there is totally diferent).

When I start this program I don't know how open a file, make stringstream, put into vectors, etc. And with help(get in threads like this) I made a 1400 lines program. And I pretend to do this again, but now creating a GUI program.

wxWidgets provide the necessary widgets as well as data structure.
There is wxTextFile for dealing with files, wxStringTokenizer for dealing with tokens wxArrayString wxArrayInt for dealing with arrays plus a lot of things. You can well use C++ data type also, no limitation. Check wxWidgets Manua and zetcode.com for tutorial

Also there is wxWidgets builder (RAD) in wxDev, check wxDev section of wxWidgets forum. You can use also wxFormBuilder too

Hi, well I know the wxWidgets provides all the tool, but I yet have a program run with c++ language, I just wanna to make 2 actions integrating the code with the wxWidgets.

My code is this:

//read the name of the file
    std::cout << endl << "Enter the name of an existing text file: "; // Here I wanna to make a box for write the information
    std::getline(std::cin, line); // Here I get what is writed in the box
    inputFile.open (line.c_str()); //open the file

Do that, I wanna to run the program normaly, and after, the program give me some values, like:

std::cout << "Correct Angle TH Det 1:  " << CorrectAngleTHDet1[0] << endl;
std::cout << "Correct Angle TH Det 2:  " << CorrectAngleTHDet2[0] << endl;
std::cout << "Correct Angle TH Det 4:  " << CorrectAngleTHDet4[0] << endl;
std::cout << "Correct Angle TH Det 5:  " << CorrectAngleTHDet5[0] << endl;

In the position of the cout, i want to make a box who show that information. Is just this, and after i make a interface with logos,options, etc.

wxWidgets is event driven just like other GUIs. So here I suggest you make a text Control and then bind it to ana event handler (Class Method) and do all stuffs there
Here is simple code to Make a text ctrl

wxTextCtrl* myTextHolder = new wxTextCtrl(pointer_to_widget_parent, wxID_ANY);
wxButton* myTextHolderButton = new wxButton(pointer_to_widget_parent, wxID_ANY, wxT("Click Me!"));
Connect(myTextHolderButton->GetId(), wxEVT_BUTTON_CLICKED, wxCommandEventHandler(MyClass::MyFunction), NULL, this);

void MyClass::MyFunction(wxCommandEvent& e){
    //handle your stuff here when the button is clicked!

Ok, thanks for your help, i'm a kind of dummy, i tried to do the code like you said but I don't make it work.

Can you explain to me how works when i make a text box, and i input a text on then, how i get this text and put into a string?

And how I get a value of a vector, like Myvector[0], and put this value into a text box?

Basically if I can do this, my program works!

And how I get a value of a vector, like Myvector[0], and put this value into a text box?

wxWidget textbox has built in functions that allow you to directly put in a value into the box. ( SetValue() )
I would suggest you do some homework learning the basics of wxWidgets and then inturn build your application.

Can you explain to me how works when i make a text box, and i input a text on then, how i get this text and put into a string?

In turn the function GetValue() will allow you to get a WxString form of the value present in the textbox which you could convert into a string very easily.

to convert a string into int is as easy as

long fromText;
int theIntValue;
wxString str = textBox->GetValue();
theIntValue = (int)fromText;

I would concur on learning wxWidgets.
http://zetcode.com s best place to begin. Check also wiki for documentation and first place should be manual and samples

Look if you really want to bother with a GUI at all just make one yourself the most basic way possible.

The most basic way possible meaning machine language and microfabrication. Start some where if you want to actually do some thing yourself, as rude and dumb as this may sound I'm actually trying to help you succeed beyond "the box."

Hi everyone, thanks for the help. I read what you write.

I'm studying very hard to do this. I'm starting to know how this part of language works, and making progress, but I'm still having difficults.

I'm tinking how my programs will looks like, and I make a list of all functions that I'll have to develop, and in my opinion is not so hard to do this, but like I said, miss to me the especific aknowledge. And this is why I'm here.

I'm trying to start with the most basic function in my program, open a file, I'm see in differents tutorials much ways to do this, and see my actual code I choose to make the user imput the directory/name of the file in a textbox, and getch this string to imput in the function "inputFile.open(string.c_str());" of my original c++ code. But I can't getch what is imput in the text box and put into a string.

For better visualization I'll post my original code with I wan't to do:

//declare variables
std::ifstream inputFile;
std::string line; 
//read the name of the file
std::cout << endl << "Enter the name of an existing text file: ";
std::getline(std::cin, line);
inputFile.open (line.c_str()); //open the file

In this code I print on the console "enter the name..." and I use the function getline to getch what the user writes and put this in the string "line" , so I use the "inputFile" function to open what is in string "line". What i wan't to do is substitute this "cout" to a box, and getch what in this box and put in "line" string, for after use the inputFile function.

Can you explain to me how I do this, and if possible post a code for better look and study.

Thanks Again.

wxWidgets have its own classes for managing file streams. Check then and they are not that hard
I guess they are wxFil

exxxxx check the manual for anything starting wit
h wxFilexxx
also google for bruce perens open source series and he have free PDF of the official wxWidgets book.
You can get its hard copy at amazon. Also check samples in wxwidgets/samples which shows how tgings work

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.