Daniel
2010-07-08 01:01:26
[Hands on] Hello World Application
with Visual Studio C++ 2010 by Dan's The Man
with Visual Studio C++ 2010 by Dan's The Man
Welcome to a hands-on tutorial of how to create a simple Hello World application using Visual Studio C++ 2010.
- Click on File,
- Hover over/click on New,
- Click on Project from the sub-menu. A new dialog should open.
- Click on Visual C++ item from the tree-list pane on the left.
- Click on Windows Forms Application from the list box in the centre.
- Give your project a suitable name.
- Once you like your chosen name, click the Ok button to continue.
- Open your Toolbox pane.
- Click on Common Controls to expand the category.
- Click on Button.
- Click anywhere on the visible form to place the button at that location. If you are unhappy where you placed the button, click and drag the button to your desired location.
- Make sure the button is the only selected component (you can achieve a selection by single-clicking on the form component).
- Scroll down until you find the property Text.
- Change the Text property to something else. An example of such would be "Click Here".
- Double-click on the button to automatically create an event.
- Enter the text in the red square above word-for-word, symbol-for-symbol. Entering the text above will change the title/caption of the form.
- At the toolbar at the top of Visual Studio 2010, make sure the option Debug is chosen from the drop-down list.
- Click on the Run (green right-arrow) button to compile and execute your application.
- Once your application has compiled and launched, look at the title/caption bar of your application. Now click on the button and then look at the title/caption bar. It has changed: Hello World!. NOTICE that when you click on the button again, the title/caption bar doesn't change! This is because you're telling it to change to the same value, and since a computer is fast in this instance, you won't notice the tiniest flicker of change. We're going to change the program's code a little bit so the title/caption bar changes each time we click the button!
- If you accidentally reverted to Design view and you cannot get back, then follow the steps below:
- Open the View menu.
- Click on the Code menu item.
- Enter the if..then conditional statement above. Is not equal to is the English-equivalent of the != operator you see above. If you haven't already, make sure there is a new line separating the conditional statement and change-of-form-title statement.
- Indent the beginning of the line by pressing the TAB key if one is not present.
- Enter the text you see in the red square marked 3. from the image above following the ; on the same line as the first line of code you entered into this program. Match it above if necessary.
- On a new line, enter the text in the red square marked 4. above. DESPITE adding the necessary code to change the form's title/caption bar on the button click, this section also introduces you into C++ Coding Standards. Several benefits of having coding standards include:
- Easier to read and understand code.
- And with the above, makes it easier to find and spot errors, as-well as significantly reducing the chance of inducing an error.
- Run your newly-modified program. If you are at a loss at how to compile and execute, please refer to step 8. NOW, as your program is open, no matter how many times you click the button, your form title will change accordingly.









Okay, well, that's all for now folks.
Continue playing around and adding to this program and then join me next week where I'll show you how to browse for and display an image on your application!