Thread: Beginner in VC++, A simple "Hello world" progarm.

  1. #1
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    531

    Thumbs up Beginner in VC++, A simple "Hello world" progarm.

    Hi,
    Can anyone help me to start a simple program with MS VC++.

    Enter your name: xyz
    Enter 1st number : 10
    Enter 2nd Number: 23

    Hello XYZ, Sum of those numbers is: 33

    Zahid
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  2. #2
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    Well first I would do this on a dialog. Have a static text called Name: followed by a edit control with a member variable called m_Name. Then on the next line have another static text called First Number: followed by another edit control with a member variable called m_First. (Do the same for Second, and Total).

    Then have a button labeld Get Total. And on the OnGetTotal() fuction declare 3 variables of type int for your First, Second and Total and one variable of type CString Name.

    Use m_First.GetWindowText(First);
    Use the same for Second and Name.

    Then Total = First + Second.

    <edit:>
    m_Total.SetWindowText("Hello "+Name+" your total is "+Total);
    </edit>

    And call UpdateData(FALSE);
    Last edited by ski6ski; 12-11-2001 at 08:54 AM.
    C++ Is Powerful
    I use C++
    There fore I am Powerful

  3. #3
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    531

    Smile Step by step..

    Hi ski6ski,
    Actually I do program in C. VC++ is very new to me. So, can you help me little more.. Just tell me step by step from
    Starting VC++
    Click File from Menu
    Select New
    Select Win32 Application, put a project name, Press OK
    .. .. ... ..
    .. .. ... ..

    This is the first time, I'm sure next time I will do better.

    Zahid
    Last edited by zahid; 12-11-2001 at 10:01 PM.
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    You are asking a lot there zahid.

    Try a search on 'callback', 'winmain'

    Look for links to Petzold's web site. He wrote the "Programming Windows" books, one of the best learning guides for WIN32 API programming.
    "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

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    In this thread...

    http://www.cprogramming.com/cboard/s...&threadid=6452

    ... towards the end, I gave this guy a step by step walk through to get his code to link, have a look at it. The message start "I did this, try the same...". Of course, if you want your own application, you can't use his source and header, but the basic steps are there for creating a Windows program.

    Are you sure you want to write a windows program yet. A "Hello World" is normally done in a console.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    Sorry I was using AppWizard. If you want to do it the hard way (code everything) then you will have to do it the way that Adrian or novacain suggested.
    C++ Is Powerful
    I use C++
    There fore I am Powerful

  7. #7
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    531

    Arrow

    Hello adrian,
    I have tried your code, I compiled it, found no error, but it is not displaying anything.
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  8. #8
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Well, as I said, if you want your program to something specific, you'll have to code that up. Looking at his code, I would agree, it doesn't look like it is doing anything, he simply wanted a step by step guide to building an app with VC++, that is what you asked for!
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  9. #9
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    531
    Yeah.. but I wanted
    Enter your name: xyz
    Enter 1st number : 10
    Enter 2nd Number: 23

    Hello XYZ, Sum of those numbers is: 33

    This minimum functionality. Anyway.. I guess I have to study little more. Though I have tried, may be I have to try more to find the starting point.
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  10. #10
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Well, as I said before...

    >>>
    Are you sure you want to write a windows program yet. A "Hello World" is normally done in a console.
    <<<

    ... I do not believe you need to write a Windows program to do this. As you have seen from the other guys code, even the simplest Windows program involves a lot before it actually does anything.

    To do what you want in a console would take probably less than 20 lines of code.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  11. #11
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    adrianxw has given you the window. If you MUST have a non console then ....

    You need controls to get the input / display the output.

    Look at CreateWindow()
    Remember to cast the HMENU as the ID of the control ie
    #define IDC_USERNAME 10001 //unique int ID code
    then in the CreateWindow use (HMENU)IDC_USERNAME

    Capture msg's to these controls in the callback with another switch for WM_COMMAND

    ie
    Code:
    case WM_COMMAND:
    idControl = GET_WM_COMMAND_ID( wParam, lParam) ;
    switch(idControl)
    {
         case IDC_USERNAME:
         //do your validation here / capture input here
         break;
    That is the next step.
    "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

  12. #12
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    531
    I don't know am I finding windows programming difficult? I guess I'm missing proper guide line.

    Can anyone suggest me the easiest reknown book for windows programming?
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  13. #13
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    As I said above

    >>Look for links to Petzold's web site. He wrote the "Programming Windows" books, one of the best learning guides for WIN32 API programming.
    "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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  2. Simple stupid question from a beginner
    By oyerth in forum C++ Programming
    Replies: 1
    Last Post: 04-07-2002, 06:32 PM
  3. A simple c++ question..Im a beginner
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-04-2001, 04:25 PM
  4. C++ Beginner Simple Calculator
    By mom in forum C++ Programming
    Replies: 3
    Last Post: 10-19-2001, 12:51 AM
  5. Major Beginner looking for simple pointers
    By dlkchic in forum C++ Programming
    Replies: 4
    Last Post: 09-05-2001, 12:27 PM