Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Where to put C++ code from console programs...

The SharKThe SharK Member Posts: 4
Hey, I'm new to MFC, and I'm curious to know
where do you put your code (which file),
from i.e. your old console programs, so you
can view the output in a nice dialog og window.
I'm using VS2008 ;-)


regards,

The SharK

Comments

  • zibadianzibadian Member Posts: 6,349
    : Hey, I'm new to MFC, and I'm curious to know
    : where do you put your code (which file),
    : from i.e. your old console programs, so you
    : can view the output in a nice dialog og window.
    : I'm using VS2008 ;-)
    :
    :
    : regards,
    :
    : The SharK
    :
    It is not possible for anyone to answer your question. The output of a console program can be in any file, or in several files, or even all files. The easiest way to tackle this is to locate all output statements and alter them to produce the output into a window.
  • The SharKThe SharK Member Posts: 4
    : : Hey, I'm new to MFC, and I'm curious to know
    : : where do you put your code (which file),
    : : from i.e. your old console programs, so you
    : : can view the output in a nice dialog og window.
    : : I'm using VS2008 ;-)
    : :
    : :
    : : regards,
    : :
    : : The SharK
    : :
    : It is not possible for anyone to answer your question. The output of
    : a console program can be in any file, or in several files, or even
    : all files. The easiest way to tackle this is to locate all output
    : statements and alter them to produce the output into a window.

    You're right, I have to be more specific, so here goes:

    If you want this code to be executed, and then displayed in a
    window, how would you go about it using MFC ?

    [code]#include

    using namespace std;

    int main()
    {
    cout << "This is a program that displays the ASCII" << endl;
    cout << "CHARACTERS of the DECIMAL values from 0 - 255." << endl;

    int C = 1; // C is the Character to be printed.
    int N = 1; // N is the Number.

    for (C = 1; C < 256; ++C)
    {
    cout << N << "= " << (char)C << " " << endl;
    ++N;
    }

    cin.get();
    return 0;

    }[/code]

  • zibadianzibadian Member Posts: 6,349
    : : : Hey, I'm new to MFC, and I'm curious to know
    : : : where do you put your code (which file),
    : : : from i.e. your old console programs, so you
    : : : can view the output in a nice dialog og window.
    : : : I'm using VS2008 ;-)
    : : :
    : : :
    : : : regards,
    : : :
    : : : The SharK
    : : :
    : : It is not possible for anyone to answer your question. The output of
    : : a console program can be in any file, or in several files, or even
    : : all files. The easiest way to tackle this is to locate all output
    : : statements and alter them to produce the output into a window.
    :
    : You're right, I have to be more specific, so here goes:
    :
    : If you want this code to be executed, and then displayed in a
    : window, how would you go about it using MFC ?
    :
    : [code]: #include
    :
    : using namespace std;
    :
    : int main()
    : {
    : cout << "This is a program that displays the ASCII" << endl;
    : cout << "CHARACTERS of the DECIMAL values from 0 - 255." << endl;
    :
    : int C = 1; // C is the Character to be printed.
    : int N = 1; // N is the Number.
    :
    : for (C = 1; C < 256; ++C)
    : {
    : cout << N << "= " << (char)C << " " << endl;
    : ++N;
    : }
    :
    : cin.get();
    : return 0;
    :
    : }[/code]:
    :
    :
    I'm not a C++ coder, but what you should do is make a string, which will hold your output. Then you can replace all the cout statements with statements, which append the output to that string.
    Finally you can show a window, which displays that string.
    In pseudo-C code:
    [code]
    int main()
    {
    PChar output;
    output = output + "This is a program that displays the ASCII" + endl;
    output = output + "CHARACTERS of the DECIMAL values from 0 - 255." + endl;
    int C = 1; // C is the Character to be printed.
    int N = 1; // N is the Number.

    for (C = 1; C < 256; ++C)
    {
    output = output + N + "= " + (char)C + " " + endl;
    ++N;
    }

    // Make a window and show output

    return 0;
    }
    [/code]
    I'm not sure about the string declaration, appending of the substrings, and type-casting of the integer. I also don't know how to make a window, but the idea should be simple enough to follow.
  • The SharKThe SharK Member Posts: 4
    : : : : Hey, I'm new to MFC, and I'm curious to know
    : : : : where do you put your code (which file),
    : : : : from i.e. your old console programs, so you
    : : : : can view the output in a nice dialog og window.
    : : : : I'm using VS2008 ;-)
    : : : :
    : : : :
    : : : : regards,
    : : : :
    : : : : The SharK
    : : : :
    : : : It is not possible for anyone to answer your question. The output of
    : : : a console program can be in any file, or in several files, or even
    : : : all files. The easiest way to tackle this is to locate all output
    : : : statements and alter them to produce the output into a window.
    : :
    : : You're right, I have to be more specific, so here goes:
    : :
    : : If you want this code to be executed, and then displayed in a
    : : window, how would you go about it using MFC ?
    : :
    : : [code]: : #include
    : :
    : : using namespace std;
    : :
    : : int main()
    : : {
    : : cout << "This is a program that displays the ASCII" << endl;
    : : cout << "CHARACTERS of the DECIMAL values from 0 - 255." << endl;
    : :
    : : int C = 1; // C is the Character to be printed.
    : : int N = 1; // N is the Number.
    : :
    : : for (C = 1; C < 256; ++C)
    : : {
    : : cout << N << "= " << (char)C << " " << endl;
    : : ++N;
    : : }
    : :
    : : cin.get();
    : : return 0;
    : :
    : : }[/code]: :
    : :
    : :
    : I'm not a C++ coder, but what you should do is make a string, which
    : will hold your output. Then you can replace all the cout statements
    : with statements, which append the output to that string.
    : Finally you can show a window, which displays that string.
    : In pseudo-C code:
    : [code]:
    : int main()
    : {
    : PChar output;
    : output = output + "This is a program that displays the ASCII" + endl;
    : output = output + "CHARACTERS of the DECIMAL values from 0 - 255." + endl;
    : int C = 1; // C is the Character to be printed.
    : int N = 1; // N is the Number.
    :
    : for (C = 1; C < 256; ++C)
    : {
    : output = output + N + "= " + (char)C + " " + endl;
    : ++N;
    : }
    :
    : // Make a window and show output
    :
    : return 0;
    : }
    : [/code]:
    : I'm not sure about the string declaration, appending of the
    : substrings, and type-casting of the integer. I also don't know how
    : to make a window, but the idea should be simple enough to follow.

    hmm...
    I can see what you mean about some output window in the end,
    but where do I put all the rest of the code, the workhorse
    if you like ;-)
    Can you give me some example of where you place your code "C++",
    in an MFC application ;-)
  • zibadianzibadian Member Posts: 6,349

    : : I'm not a C++ coder, but what you should do is make a string, which
    : : will hold your output. Then you can replace all the cout statements
    : : with statements, which append the output to that string.
    : : Finally you can show a window, which displays that string.
    : : In pseudo-C code:
    : : [code]: :
    : : int main()
    : : {
    : : PChar output;
    : : output = output + "This is a program that displays the ASCII" + endl;
    : : output = output + "CHARACTERS of the DECIMAL values from 0 - 255." + endl;
    : : int C = 1; // C is the Character to be printed.
    : : int N = 1; // N is the Number.
    : :
    : : for (C = 1; C < 256; ++C)
    : : {
    : : output = output + N + "= " + (char)C + " " + endl;
    : : ++N;
    : : }
    : :
    : : // Make a window and show output
    : :
    : : return 0;
    : : }
    : : [/code]: :
    : : I'm not sure about the string declaration, appending of the
    : : substrings, and type-casting of the integer. I also don't know how
    : : to make a window, but the idea should be simple enough to follow.
    :
    : hmm...
    : I can see what you mean about some output window in the end,
    : but where do I put all the rest of the code, the workhorse
    : if you like ;-)
    : Can you give me some example of where you place your code "C++",
    : in an MFC application ;-)
    :
    The method I usually choose (in Delphi/Java) is the constructor of the window.
    Based on a tutorial code I would say in the red line:
    [code]
    #include

    class MFC_Tutorial_Window :public CFrameWnd
    {
    public:
    MFC_Tutorial_Window()
    {
    [red]Generate output here[/red]
    Create(NULL,[blue]output[/blue]);
    }
    };

    class MyApp :public CWinApp
    {
    MFC_Tutorial_Window *wnd;
    public:
    BOOL InitInstance()
    {
    wnd = new MFC_Tutorial_Window();
    m_pMainWnd = wnd;
    m_pMainWnd->ShowWindow(1);
    return 1;
    }
    };

    MyApp theApp;
    [/code]
    Source: http://www.codersource.net/mfc_tutorial_Part1.html

    This code places the output as the window caption (definitely not the best place), but since I'm not a C-coder and never produced an MFC application, this was my best idea.
  • The SharKThe SharK Member Posts: 4
    :
    : : : I'm not a C++ coder, but what you should do is make a string, which
    : : : will hold your output. Then you can replace all the cout statements
    : : : with statements, which append the output to that string.
    : : : Finally you can show a window, which displays that string.
    : : : In pseudo-C code:
    : : : [code]: : :
    : : : int main()
    : : : {
    : : : PChar output;
    : : : output = output + "This is a program that displays the ASCII" + endl;
    : : : output = output + "CHARACTERS of the DECIMAL values from 0 - 255." + endl;
    : : : int C = 1; // C is the Character to be printed.
    : : : int N = 1; // N is the Number.
    : : :
    : : : for (C = 1; C < 256; ++C)
    : : : {
    : : : output = output + N + "= " + (char)C + " " + endl;
    : : : ++N;
    : : : }
    : : :
    : : : // Make a window and show output
    : : :
    : : : return 0;
    : : : }
    : : : [/code]: : :
    : : : I'm not sure about the string declaration, appending of the
    : : : substrings, and type-casting of the integer. I also don't know how
    : : : to make a window, but the idea should be simple enough to follow.
    : :
    : : hmm...
    : : I can see what you mean about some output window in the end,
    : : but where do I put all the rest of the code, the workhorse
    : : if you like ;-)
    : : Can you give me some example of where you place your code "C++",
    : : in an MFC application ;-)
    : :
    : The method I usually choose (in Delphi/Java) is the constructor of
    : the window.
    : Based on a tutorial code I would say in the red line:
    : [code]:
    : #include
    :
    : class MFC_Tutorial_Window :public CFrameWnd
    : {
    : public:
    : MFC_Tutorial_Window()
    : {
    : [red]Generate output here[/red]
    : Create(NULL,[blue]output[/blue]);
    : }
    : };
    :
    : class MyApp :public CWinApp
    : {
    : MFC_Tutorial_Window *wnd;
    : public:
    : BOOL InitInstance()
    : {
    : wnd = new MFC_Tutorial_Window();
    : m_pMainWnd = wnd;
    : m_pMainWnd->ShowWindow(1);
    : return 1;
    : }
    : };
    :
    : MyApp theApp;
    : [/code]:
    : Source: http://www.codersource.net/mfc_tutorial_Part1.html
    :
    : This code places the output as the window caption (definitely not
    : the best place), but since I'm not a C-coder and never produced an
    : MFC application, this was my best idea.

    Thanks zibadian ;-)
Sign In or Register to comment.