Thread: Visual C++

  1. #1
    Deleted Account
    Join Date
    Mar 2005
    Posts
    57

    Visual C++

    I am creating a calculator, i had a previous thread but i got another question. In visual c++, what is the command for exiting the program you create. I got a menu system, with exit and i want to make it able to exit when clicked.

    One last thing, i got a part where validating the data for the input numbers that you type. Say for input 1, you type asdas3123... and input 2 you have 242, where one of the inputs is not valid, i have a message box appear. wondering after the message, how do you make it then stop calculating the sum...as it still continues..

    Note: the inputs are done through text boxes, and converted to ints.....and then calculation is done...

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    To close an app look at WM_CLOSE (MFC OnClose )

    where you call DestroyWindow()

    >>you type asdas3123.

    have you looked at the edit style ES_NUMBER then you can't have a decimal point.

    Otherwise you write a handler. Used as the text is input (best)(EN_CHANGE , WM_COMMAND) or when the input is validated (easier)

    Look at the input and test each character,

    if (not number or the first . )
    don't allow input

    isdigit()
    ispunct()
    ect
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    to have it stop, tell it to return;

    so.

    Code:
    if(!valid)
    {
          MessageBox("I said input a number, idiot", "Input Error", MB_OK);
          return;
    }
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Quote Originally Posted by UnclePunker
    to have it stop, tell it to return;
    That depends where you place the return statement. If you return from your main function or return to main with a return value which main uses to decide to return then the program will exit.
    In a program with a window WM_CLOSE is realy the best option because you can also place other cleanup code in your WM_DESTROY handler.
    If you don't have a window (a console app) then do something like this:
    In your main() function
    Code:
    if (Display_menu())
       return 0; //if menu returned none-zero we return from main exiting the program
    And in a display_menu() function
    Code:
    case QuitProgram:
       return 1;
    Last edited by Quantum1024; 04-22-2005 at 01:09 PM.

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    If you application is a dialog that was created with one of the DialogBoxXXXX() functions, you should close it by calling EndDialog() in your WM_CLOSE handler.

  6. #6
    Deleted Account
    Join Date
    Mar 2005
    Posts
    57
    thanks ppl..but i'm not 100% understanding this as we have been working on c++ mainly and then suddenly they wanted us to do a gui calculator (convert from the c++ calculator to visual c++) and all they taught was how to convert b/w strings and doubles...grrrr


    Since i'm at home now..i'll post the code to clarify things...

    Sorry but if i'm repeating things, it means i don't understand it....

    1. --> For the exit, i have a menu called File, and when you click on menu i want it to be able to exit.

    i.e this is the code generated after creating it...

    private: System::Void menuItem10_Click(System::Object * sender, System::EventArgs * e) { }
    am i suppose to put return between braces?

    2.. --> I got my decimal to binary working...but when i try to do another conversion, the conversions get's muddled up...that is the previous contents are joined together..how do i fix it..

    int decimal; String *conresultstore; if(rbDecBin->Checked) //decimal to binary code was partially modified from 1'st C++ Lab Assignment //for it to be fully functional in this assignment { decimal = Convert::ToInt32(txtConInput->Text); for(i = 0; i <= 16; i++) //increment by 1 throughout the specified numrange values { binary[i] = decimal % 2; decimal = decimal / 2; counter ++; } for(j = counter - 1; j >= 0; j--) //reverses the order of the numbers { String *conresult = Convert::ToString(binary[j]); conresultstore = String::Concat(conresultstore, conresult); } // concat[] is used to append the previous values with the new values side by side. } txtConResult->Text=conresultstore;
    3.--> I changed partially of my old project for binary to decimal to work with this visual ++...it works partially that is, if the binary consists of 1's, it works properly, but with zero's the calculation is zero...i'll paste it here...i commented the part that will make the calulation work properly in c++, but not in visual...

    // int bit; // char readBinary; int decimal; String *binary = txtConInput->Text; for(int i=0; i<=binary->Length; i++) { //readBinary = binary[i]; // if(readBinary == '0') // bit = 0; //else decimal = decimal + ((pow(2, (binary->Length - i - 1)))); } txtConResult->Text= Convert::ToString(decimal);
    4.--> And lastly, i still do not understand the validation process, do you u guys could maybe explain it more simply, as i only started using visual last wk...

    this is my validation so far for addition...i couldn't get the isdigit() working, u guys think u could clarify more clearly in direct to my code? thanks alot

    num01 = Convert::ToDouble(txtNum01->Text); //convert the user's string input into a double if(num01 < 2.2e-300 || num01 > 2.2e300) //data validation - to check if number is within the double range { num01 = 0; MessageBox::Show("Input for number 1 is invalid. Please re-enter!"); //if not within range, error message will be displayed } num02 = Convert::ToDouble(txtNum02->Text); if(num02 < 2.2e-300 || num02 > 2.2e300) { num02 = 0; MessageBox::Show("Input for number 2 is invalid. Please re-enter!"); } result = num01 + num02; if(result >= 2.2e-308 && num01 <= 2.2e-308) { result = 0; MessageBox::Show("Calculation for both sums are out of range. Re-enter the two number so calculation result is between 2.2e308 and 2.2e-308"); } txtResult->Text=Convert::ToString(result); //convert the final results to string so that it can be displayed in textbox (textbox accepts string's only)
    And one thing, once the message box appears, how do u make it stop continuing onwards, i can't use break for it, and i also want to clear the boxes, but i can't find anywhere on how to ...

    thanks..sorri for all the questions, but i'm only still trying to take a grasp of the concepts.cheers!

  7. #7
    Deleted Account
    Join Date
    Mar 2005
    Posts
    57
    hey guys again..i just realized the code didn't get pasted properly..i'm sorri but u guys can still read it properly without the indentation and stuff..

  8. #8
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    but u guys can still read it properly without the indentation and stuff..
    no, fix it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM