How to create a gui from pre written and working c++ code

Hi All,

I have posted one of my codes below.

Here I'm trying to create a GUI for this code which takes the input values from user using GUI and displays results again back in GUI.

Can anyone help me out with this.

Thanks in Advance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include <conio.h>
#include <math.h>
using namespace std;

int main()
{
    
/*Grid Point declarations*/
    int x,y;
    double left,right,top,bottom;
    double phi[100][100],uphi[100][100];
        
    cout<<"Enter no. of grid points"<<endl<<"x:";
    cin>>x;
    cout<<"y:";
    cin>>y;
    
    
/*Read & Define Boundary Conditions*/ 
 
cout<<endl<<endl<<"Enter value for left:";
cin>>left;
cout<<endl<<"Enter value for right:";
cin>>right;
cout<<endl<<"Enter value for top:";
cin>>top;
cout<<endl<<"Enter value for right:";
cin>>bottom;

int nit;
cout<<"Enter required iterations: ";
cin>>nit;
cout<<'\n';

    for (int i=0;i<=x-1;i++)
    {
        phi[0][i]=left;
    }
    for (int i=0;i<=x-1;i++)
    {
        phi[x-1][i]=right;
    }
    for (int i=0;i<=x-1;i++)
    {
        phi[i][y-1]=top;
    }
    for (int i=0;i<=x-1;i++)
    {
        phi[i][0]=bottom;
    } 
  
cout<<'\n';
cout<<"First Iteration values"<<endl<<'\n';   
    
/*First Guess it=1*/   

for (int i=1;i<=x-2;i++)
{
    for(int j=1;j<=y-2;j++)
    {
            phi[i][j]=(left+right+top+bottom)/4;
            cout<<"1"<<'\t'<<phi[i][j]<<endl;
    }
} 
cout<<'\n';

/*    for (int i=0;i<=x-1;i++)
    {
        for (int j=0;j<=y-1;j++)
        {
            cout<<i<<'\t'<<j<<'\t'<<phi[i][j]<<endl;
        }
    }*/


/*Iteration from it=2*/   


                            
       for (int it=2;it<=nit;it++)
       {
           for (int i=1;i<=x-2;i++)
               {
                    for(int j=1;j<=y-2;j++)
                    {
                           uphi[i][j]=phi[i][j];
                           phi[i][j]=(phi[i+1][j]+phi[i-1][j]+phi[i][j+1]+phi[i][j-1])/4;
                           cout<<it<<'\t'<<phi[i][j]<<'\t'/*<<uphi[i][j]*/<<endl;     
                           if((uphi[i][j]-phi[i][j])<=0.001&&(uphi[i][j]-phi[i][j])>0)
                           {
                                                                                     
                           goto last;                                                           
                           }                                        
                    }
               }
               cout<<'\n';
       }  
   
   last:
        cout<<endl<<"Solution is Converged";                    
    getch();
}
http://www.ultimatepp.org/
its relatively easy to use ultimate++ for cross platform gui development than any other
Can I create a GUI design separate and my code separate and create a link between this.

I don't want to modify code again.

Is there any easiest way
There's also wxwidgets and qt. Just google them. They all have a designer. So that's not the problem.


I don't want to modify code again.
That's unlikely. Everything cin/cout will be replaced by the gui
I don't want to modify code again.

I'm with coder777 here. You'll have to replace all the console i/o code. :-(

But not the calculations! :-)

(Unless you want to write a "pseudo GUI" which acts just like the console, providing cout and cin replacements which work with the GUI library. But then you'd end up with a boring UI as you wouldn't be able to exploit the features of the underlying library, and might as well just have used the console...)

Andy
Last edited on
can you give me an example.

How to replace cout and cin with my code displayed above
Last edited on
can you give me an example.

That is quite a big ask.

The problem is that there are a number of different GUI toolkits, and each offer more than one way to solve the problem.

If you code using Windows native Win32 GDI API, then text is output using functions like OutText and DrawText, e.g. (where hdc is the handle to a display device context, x and y are the coordinants where you want the text to be drawn at, and text is a string object.)

TextOut(hdc,x,y,text.c_str(), text.length());

But you could also use a control, such as a static control or an edit control. In this case (where hwndCtrl is the window handle to the control window.)

SendMessage(hwndCtrl, WM_SETTEXT, 0, text.c_str());

To read text in you would generally use an edit control, but could handle key presses and then display the output yourself.

All GUI toolkits have corresponding functionality and components, but with different names.

Andy
Last edited on
Topic archived. No new replies allowed.