Thread: Console C++ to full Windows

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    2

    Console C++ to full Windows

    Console C++ to full Windows

    Alright heres the situation: I have made a console based calculator and I need to move it all into windows program. The following code is what I have so far in Windows code.

    Code:
    // First Windows Program
    // This program is intended to display a Windows XP themed interface
    // and use some basic Windows program functions
    
    #define STRICT
    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    #include <iostream>
    #include <string>
    
    int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow) {
    using namespace std;
    MessageBox(NULL, "Would you like to do some math?", "Calculator",
    MB_OK|MB_ICONINFORMATION|MB_SETFOREGROUND);
    
    return 0;
    }
    
    This is my calculator code:
    
    // Calculator
    
    // Include files below
    
    #include <iostream>
    #include <string>
    #include <math.h>
    #include <cstdlib>
    using namespace std;
    
    //Beginning of calulator
    
    int main()
    {
    //Mathematical operators' corresponding number
    //Done = 5;
    //Subtraction = 4;
    //Addition = 3;
    //Multiplication = 2;
    //Division = 1;
    
    int answer;
    
    //Answer must be initialized to be used
    
    cout << "What basic mathematical operator shall I perform ?" << endl;
    cout << "Please answer with: Division(1), Multiplication(2), Addition(3), Subtraction(4)" << endl;
    cout << "Square Root(5), Sine(6), Cosine(7), Tangent(8), Exponetial(9) or End Program(10)" << endl;
    cout << "Want a operator not seen here? More operators can be added at your request!" << endl;
    cin >> answer;
    
    while(answer!=10) // This begins a loop that will only end when answer is equal to 10
    {
    
    if (answer == 1) //Division section of the calculator
    { 
    // Long double is the type of variable that can have up to 15 digits
    // Again variables must be initialized before using them.
    // However because of the braces around this section the variables
    // are local and can be initialized/used in other sections again
    
    long double value1;
    long double value2; 
    
    // This asks for values and then inputs the values into the variables
    
    cout << "Input value to be divided: ";
    cin >> value1;
    cout << "Input the dividend: ";
    cin >> value2;
    
    //Dividing the values and storing the answer to value1
    
    value1 /= value2;
    cout << "Answer: "<< value1 << endl <<endl;
    cout << "Please input the next operation number you would like to preform." << endl;
    cin >> answer;
    
    }
    
    if (answer == 2) //Multiplication section of the calculator
    { 
    
    long double value1;
    long double value2; 
    
    cout << "Input first number: ";
    cin >> value1;
    cout << "Input the second number: ";
    cin >> value2;
    
    value1*=value2;
    cout << "Answer: "<< value1 << endl <<endl;
    cout << "Please input the next operation number you would like to preform." << endl;
    cin >> answer;
    }
    if (answer == 3) //Addition section of the calculator
    { 
    
    long double value1;
    long double value2;
    
    cout << "Input the first number : ";
    cin >> value1;
    cout << "Input the second number: ";
    cin >> value2;
    
    value1+=value2;
    cout << "Answer: "<< value1 << endl <<endl;
    cout << "Please input the next operation number you would like to preform." << endl;
    cin >> answer;
    }
    if (answer == 4) //Subtraction section of the calculator
    { 
    
    long double value1;
    long double value2;
    
    cout << "Input value to be subtracted from: ";
    cin >> value1;
    cout << "Input the number to subtract from the first: ";
    cin >> value2;
    
    value1-=value2;
    cout << "Answer: "<< value1 << endl <<endl;
    cout << "Please input the next operation number you would like to preform." << endl;
    cin >> answer;
    }
    if (answer == 5) //root section of the calculator
    { 
    
    long double value1;
    long double value2;
    
    cout << "Input value to be square rooted: ";
    cin >> value1;
    
    value2 = sqrt (value1);
    cout << "Answer: "<< value2 << endl <<endl;
    cout << "Please input the next operation number you would like to preform." << endl;
    cin >> answer;
    }
    if (answer == 6) //sine section of the calculator
    { 
    
    long double value1;
    long double value2;
    
    cout << "Input value to get the sine for: ";
    cin >> value1;
    
    value2 = sin (value1);
    cout << "Answer: "<< value2 << endl <<endl;
    cout << "Please input the next operation number you would like to preform." << endl;
    cin >> answer;
    }
    if (answer == 7) //cosine section of the calculator
    { 
    
    long double value1;
    long double value2;
    
    cout << "Input value to get the cosine for: ";
    cin >> value1;
    
    value2 = cos (value1);
    cout << "Answer: "<< value2 << endl <<endl;
    cout << "Please input the next operation number you would like to preform." << endl;
    cin >> answer;
    }
    if (answer == 8) //tangent section of the calculator
    { 
    
    long double value1;
    long double value2;
    
    cout << "Input value to get the tangent for: ";
    cin >> value1;
    
    value2 = tan (value1);
    cout << "Answer: " << value2 << endl <<endl;
    cout << "Please input the next operation number you would like to preform." << endl;
    cin >> answer;
    }
    if (answer == 9) //exponetial section of the calculator
    { 
    
    long double value1;
    long double value2;
    
    cout << "Input value to raise exponentially: ";
    cin >> value1;
    cout << "Input exponet: ";
    cin >> value2;
    
    cout << "Answer: "<< pow (value1,value2)<< endl <<endl;
    cout << "Please input the next operation number you would like to preform." << endl;
    cin >> answer;
    }
    else
    {
    cout << "Please input a correct number" << endl;
    cin >> answer;
    }
    // Braces are needed at each level of abstraction
    }
    // Return value shows that program executed as expected and then ends the program
    return 0;
    }


    http://domain-name5.blogspot.com/200...n-limited.html
    Last edited by foxon177; 05-07-2008 at 02:20 AM.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Before you start converting your existing application, perhaps you should start by using the Windows GDI API a little bit.

    Many things in your code will have to change:
    1. You can't use cout and cin in Windows apps. (You CAN use iostream functionality, but not for the "console"). You will need to find a different way to deal with input, either as direct events or by using some sort of dialog input.

    2. Your application will need to be event-driven, rather than directly input driven.

    3. Your menu probably should be changed to a more GUI-like approach.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I'd say finding a good framework to base your further GUI programming on might be the first task, seeing as pure Win32 is very daunting. There are lots of alternatives out there, some free, some commercial, some C, some C++.
    There's WTL, MFC, GTK, and more.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    137
    You don't need any framework for a so simple application.
    And with the Dlg Editor, it's done in 5 minutes !

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I wouldn't be so sure. Pure win32 is not that easy.
    It's better to get acquainted with a framework right away, because you're going to need to use it later.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    May 2008
    Posts
    2

    Thanks for your suggestion!

    Thanks for your suggestion! Thanks very much!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Full screen console
    By eletron in forum C Programming
    Replies: 1
    Last Post: 02-25-2005, 04:04 PM
  2. FlashWindowEx not declared?
    By Aidman in forum Windows Programming
    Replies: 3
    Last Post: 05-17-2003, 02:58 AM
  3. windows console probs
    By henroid815 in forum C++ Programming
    Replies: 3
    Last Post: 05-05-2003, 03:36 AM
  4. windows console code probs
    By henroid815 in forum C++ Programming
    Replies: 1
    Last Post: 05-04-2003, 05:53 PM
  5. windows dos console
    By dune911 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-16-2002, 11:30 PM

Tags for this Thread