VC++ simple prog HELP

This is a discussion on VC++ simple prog HELP within the Windows Programming forums, part of the Platform Specific Boards category; hi everyone i'm trying to learn to use visual c++ 6.0 and i'm trying to make a simple application that ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    12

    VC++ simple prog HELP

    hi everyone

    i'm trying to learn to use visual c++ 6.0 and i'm trying to make a simple application that will add two integers and display the result. i found tutorials on how to enter text into a text box and then use a button to display that text in a message box. i can't seem to get to do the same thing to the integers though. does anyone have any links to specific tutorials (couldn't find anything that would help me on the net) or suggestions that i might try. thanx

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    TheForgers tutorial is a pretty good one...

    http://www.winprog.org/tutorial/

    ...or you can post the code you've got and we'll help you get that working.

    Remember, if you post your code, to post any resource files and headers you have made, so we can compile the program and run it in a decent debugger.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    There is no magic to Windows programming. I recommend exploring the deep ocean even if you do not know how to swim. In the end you will become a very good swimmer.

    Kuphryn

  4. #4
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    that was very deep and meaningful kuphryn. but lets help out anyway.

    Okay, its sounds like you know how to create the edit boxes and buttons. what you need to do is capture the message that is sent when the button is clicked, and place your code there.
    That can be done by checking the LOWORD of the wParam when the WM_COMMAND message occurs, to see if it matches the ID of your button. eg:

    Code:
    switch (msg)
    {
    case WM_COMMAND:
      switch (LOWORD(wParam))
      {
      case ID_BUTTON: //Whatever ID you gave it
         //Code here
        return 0;
    The code will have to ensure that there is text in both controls, then convert it to numbers, and add it together. Then convert the sum back to a string and display it. ie:

    Code:
    char *str1=new char[256]; //Allocate strings to retrieve the input
    char *str2=new char[256]; //ditto
    int num1,num2;
    
    GetWindowText(hInput1,str1,255);
    GetWindowText(hInput2,str2,255);
    //The above lines retrieve the text of the edit controls hInput1 and hInput2
    
    num1=atol(str1); //converts string to long int, needs stdlib.h
    num2=atol(str2);
    
    ltoa(num1+num2,str1,10); //convert long int to string. 10 is the radix
    
    SetWindowText(hDisplay,str1); //hDisplay is a control with a caption, ie an edit control
    and thats it. ill post a full proggy in a tic.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  5. #5
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    the attached file is the source file for the proggy. what you should do is create a new win32 application, just an empty project, and add the file to it. it should compile fine. it worked for me.
    Attached Files Attached Files
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    12
    thanx

    i think that should help me for now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help me with my simple Tic tac toe prog
    By maybnxtseasn in forum C Programming
    Replies: 2
    Last Post: 04-04-2009, 06:25 PM
  2. Need help in a fairly simple C prog
    By CodeSlow in forum C Programming
    Replies: 4
    Last Post: 01-04-2008, 01:49 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  4. Help on simple text console prog...
    By Azh321 in forum C++ Programming
    Replies: 2
    Last Post: 11-26-2003, 06:03 AM
  5. unable to get simple program working
    By toom in forum Linux Programming
    Replies: 1
    Last Post: 10-11-2003, 05:05 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21