SRL Archive - C/C++ Help and Tutorials

[Hands On] C++/CLI "Hello World" form application with VS2010!


Daniel

2010-07-08 01:01:26

[Hands on] Hello World Application
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.

    1. Click on File,
    2. Hover over/click on New,
    3. Click on Project from the sub-menu. A new dialog should open.
    NOTICE the keyboard shortcut to the right of Project. So, as an alternative to following the above procedure, you can press the combination of keys on your keyboard to achieve the same outcome.
    1. Click on Visual C++ item from the tree-list pane on the left.
    2. Click on Windows Forms Application from the list box in the centre.
    3. Give your project a suitable name.
    4. Once you like your chosen name, click the Ok button to continue.
    1. Open your Toolbox pane.
    2. Click on Common Controls to expand the category.
    3. Click on Button.
  1. 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.
    1. Make sure the button is the only selected component (you can achieve a selection by single-clicking on the form component).
    2. Scroll down until you find the property Text.
    3. Change the Text property to something else. An example of such would be "Click Here".
    1. Double-click on the button to automatically create an event.
    1. 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.
    1. At the toolbar at the top of Visual Studio 2010, make sure the option Debug is chosen from the drop-down list.
    2. Click on the Run (green right-arrow) button to compile and execute your application.
  2. 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!.
  3. 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!
  4. If you accidentally reverted to Design view and you cannot get back, then follow the steps below:
    1. Open the View menu.
    2. Click on the Code menu item.
    1. Enter the if..then conditional statement above. Is not equal to is the English-equivalent of the != operator you see above.
    2. If you haven't already, make sure there is a new line separating the conditional statement and change-of-form-title statement.
    3. Indent the beginning of the line by pressing the TAB key if one is not present.
    4. 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.
    5. On a new line, enter the text in the red square marked 4. above.
    6. 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.
      NOTICE that I spelt the word Hello wrong in the above image and how Visual Studio is pointing it out to me. As with the Microsoft Office spell-checker, right-click on the incorrect word and select the appropriate correction from the pop-up menu that presents itself.
  5. Run your newly-modified program. If you are at a loss at how to compile and execute, please refer to step 8.
  6. 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!

Wizzup?

2010-07-08 03:37:43

How-to in GNU/Linux:


$ echo '#include "stdio.h"
int main() {
printf("hello, world\n.");
return 0;
}' | gcc -xc - -o /tmp/a.out && /tmp/a.out
hello, world

Daniel

2010-07-08 03:42:50

From: Wizzup?
How-to in GNU/Linux:


$ echo '#include "stdio.h"
int main() {
printf("hello, world\n.");
return 0;
}' | gcc -xc - -o /tmp/a.out && /tmp/a.out
hello, world


Different from above tutorial ^.

Above tutorial is about involving oneself with GUI applications using the Windows forms library.

killhack95

2010-07-10 16:01:13

I don't see the point of this post… Anyone that has at least some programming experience should be able to make a hello world application on visual (insert programming language here) .All the IDE's of visual studio are very easy to overstand.

Daniel

2010-07-10 20:44:15

From: killhack95
I don't see the point of this post… Anyone that has at least some programming experience should be able to make a hello world application on visual (insert programming language here) .All the IDE's of visual studio are very easy to overstand.

That's why most beginner programmers start off learning how to make a Hello World application, despite the fact that it is so simple…

i luffs yeww

2010-07-11 01:20:16

puts "Hello World!"

:3 Ruby wins.

Smartzkid

2010-07-11 03:24:27

C# for GUIs, C++ for heavy lifting.

Good tut, but 'nuff said.

Yakman

2010-07-18 15:19:10

How to do in Linux (with GUI)

echo 'from gtk import *

def hello(widget, data=None):
print "Hello World"

def destroy(widget, data=None):
print "destroy signal occurred"
main_quit()

window = Window(WINDOW_TOPLEVEL)
window.connect("destroy", destroy)
window.set_border_width(10)
button = Button("Hello World")
button.connect("clicked", hello, None)
window.add(button)
button.show()
window.show()
main()' | python

Not exactly the same as yours of course, but very similar.

Emaziz

2010-07-28 06:14:08

If anyone is serious about learning C++, wouldn't it be better starting of in console applications? I mean.. There's no point starting of in big visual applications before you've done some pure C++ and learned how the syntax works and about some of the important standard library functions.. ;)

superuser

2011-08-03 16:40:25

From: Wizzup?
How-to in GNU/Linux:


$ echo '#include "stdio.h"
int main() {
printf("hello, world\n.");
return 0;
}' | gcc -xc - -o /tmp/a.out && /tmp/a.out
hello, world


No need to return 0, it is not mandatory as the standard states ;) Unless this is meant to be C…

Wizzup?

2011-08-03 16:46:13

From: superuser
No need to return 0, it is not mandatory as the standard states ;) Unless this is meant to be C…


Looks like C to me. :)