View Full Version : [Tut] Beginner Windows Programming in C++
That Asian Guy
27th December 2007, 02:43
I havent noticed many tuts on windowed programming, so I decided to make one :P
Tools Needed:
Microsoft Visual C++ 2005 or 2008 (http://www.mpcforum.com/showthread.php?t=214809) (Im using 2005 in this tut, download here (http://www.microsoft.com/Australia/msdn/vs2005/express.mspx).)
Experience:
Little or no programming experience required, we are only modifying control properties, which I shall teach.
Tut:
Install Microsoft Visual C++ Express as stated in the tutorial, and lets get started...
When u first run VC++, u should see the start page (http://img297.imageshack.us/img297/5084/vsstartpagehc1.jpg). Click Create->Project, as circled in the picture above.
A "New Project" window should pop up. Select "Windows Form Application" from the listview, and name it. For this tut, I named mine "Tutorial App". Click create.
pic (http://img181.imageshack.us/img181/2945/vsnewprojrc3.jpg)
Fortunately, VC++ quickly generates alot of code for u, as well as a plain windows form. Just for fun, lets right-click the form and select "View Code", like this (http://img181.imageshack.us/img181/4145/vsviewcodevs3.jpg). As you can see, the VC++ has generated TONS of code for you. Thank god! :P
Now, let check if our build environment suits our needs.
Locate the properties window (http://img404.imageshack.us/img404/3084/vspropertiesdu6.jpg). If you cant find it, click View-> Property Manager from the menu.
Next, locate your toolbox. If you cant find it, click View->Toolbox from the menu once again.
Now, lets get down to some programming ... :P
From your toolbox, select a label. Draw it onto your form. Select a button from the toolbar, and draw it onto your form. It should now look something like this (http://img181.imageshack.us/img181/8733/vsform1fs8.jpg).
The first thing I do when I create controls is modify the design name. Although this program only contans two controls, advanced ones can have thousands. So, click once on the label, and go over to the properties window. You can sort the properties window alphabetically by clicking the "azdownarrow" button at the top of the window, which I prefer. Now, select (Name) property and rename it to "label_message" like this (http://img404.imageshack.us/img404/5566/vslabelrenameqa7.jpg). Do the same thing with the button, naming it to "button_hideMessage".
As you can see, my naming convention is <control type>_<controlFunction>. Different people have different naming conventions, but I highly prefer this one. If you choose one of your own, make sure its understandable and convenient.
Now, lets change the font and text of the label. Select the label again and click "Font" under the properties window. Click the little button that appears, and a font selection window will pop up. Now, select size 28 and hit OK. Now, change the "Text" property of the label to "You suck!" (Youll see why later).
Select the button, and change the "Text" property to "Hide this message =("
Your program will now look like this (http://img404.imageshack.us/img404/7209/vsform1aftertl4.jpg). For now, press CTRL+S to save your project. Then, CTRL+F5 to build and run the application.
After it builds, click the button.
ZOMG NOTHING HAPPENS :dead: SCAMMER!!!
Hold on there, we must add events to the program in order for it to know what to do when an event happens :P.
Select the button, and click the little lightning bolt at the top of the properties window. An entire list of available events will appear. Double click the "Click" event, and it will take you to the code with the following generated:
private: System::Void button_hideMessage_Click(System::Object^ sender, System::EventArgs^ e) {
}
In order to change the properties of a control, we must use the "<controlName>-><property> = <whatever>
The arrow syntax "->" represents a pointer to the object, but since this is beginner I wont get too much into it.
So, make the left brace"{" move to the next line by hitting enter, and enter the following code:
label_message->Visible = false;
Fortunately, Microsoft's IntelliSense database will appear after you type "->" with a list of possible commands. For now, well just mess with the visibility.
Your code section should now look like this:
private: System::Void button_hideMessage_Click(System::Object^ sender, System::EventArgs^ e)
{
label_message->Visible = false;
}
Now, run the program.
YAY!!!
The message disappeared when you clicked the button! :P :byewhore:
As you can see, I simply modifyed the "Visible" property of the label. If you select the label and look under the properties window, you will see a "Visible" property. You can apply this knowledge to modify any property in the properties window.
If you want to learn more regarding a certain property, check out the MSDN library, its godly. http://msdn2.microsoft.com/en-us/library/k50ex0x9(VS.80).aspx
Thats it!
Hope you learned alot and had some fun :P
CioNide
27th December 2007, 03:42
Great tutorial, thanks ;).
wcbrilman
27th December 2007, 16:23
http://img297.imageshack.us/img297/5084/vsstartpagehc1.jpg is dead :|
CioNide
28th December 2007, 00:34
http://img297.imageshack.us/img297/5084/vsstartpagehc1.jpg is dead :|
Image is back up.
wcbrilman
28th December 2007, 11:32
Oh, I see.
That Asian Guy
28th December 2007, 23:11
I guess there was a temporary server disorder :\
xTc-Droop
31st December 2007, 17:15
Uhh, for some reason I have express edition is there any direct link to what program you downloaded?
penutball
1st January 2008, 01:55
Uhh, for some reason I have express edition is there any direct link to what program you downloaded?
no real difference. Express is just a free programming client and the code compiling is no different from Visual Studio :)
BTW Excellent tutorial! Helps C++ noobs like me get the basics.
That Asian Guy
3rd January 2008, 01:58
i have visual studio professional, but im not allowed to discuss how i got it here.
as stated above, express should get u the same results
xTc-Droop
4th January 2008, 14:00
i have visual studio professional, but im not allowed to discuss how i got it here.
as stated above, express should get u the same results
Well that kinda gave it away crackzzz lol :P as long as u arnt giving them away
xhavox
11th February 2008, 23:18
thank you this was a nice tutorial =D
XxOsirisxX
12th February 2008, 04:01
Well done Asian Guy ^^
I would like to see stuffs like this sticky sooner :P
Great Job. ^^
That Asian Guy
12th February 2008, 23:58
thanks :P
Hallzoc13
26th February 2008, 01:48
It didn't work for me. I get to the last step, add that command in, and try to run it. It says it failed and when I click the button
"You suck!" doesn't disappear.
That Asian Guy
26th February 2008, 02:09
O.O
if u got compiler errors then u typed the code wrong, and the program wont even run
if the message just didnt disappear, then that means u forgot to add the eventhandler
report back
Hallzoc13
26th February 2008, 02:35
Edit-Nevermind. I got it! Thanks!
Edit- I know this is nub but I tricked around and instead of hide message I made it appear
=] I'm trying I guess
Do I put the code at A, B, C, or D?
http://img247.imageshack.us/my.php?image=84585237ii9.png
Because when I run it, everything comes up but the "You Suck!" doesn't disappear
That Asian Guy
27th February 2008, 01:25
A deals with the wrong event, u must be working with button_click event
Therefore, D (make sure its before the brace("}"))
Hallzoc13
27th February 2008, 01:44
Yea what I did was I didn't realize all I had to do was click enter and put in the code. It works now
Gu4rdi4n
28th February 2008, 03:03
Lol, Funny thanks for the Tut
soemaal
28th February 2008, 05:05
ty for the tut, i will try it tomorrow =)
Hallzoc13
28th February 2008, 06:00
If you want to make the message appear (incase they want to know, and I want to share =p)
1. Make the button & label
2. Click on the label and click properties
3. Set visibility to false
4. Select your button and go to properties
5. Click events (the lightning bolt) and double click the option click
6. Now hit enter and type in (with no "s) "label_message->visible = true;"
7. Now compile and click the button. Your text in the label should appear now
Hope this helps broaden your learning a little
+_Chain_+
9th March 2008, 05:01
Lol this is awesomely easy. Thanks and noice.
teamlkakash1
21st March 2008, 04:12
If you want to make the message appear (incase they want to know, and I want to share =p)
1. Make the button & label
2. Click on the label and click properties
3. Set visibility to false
4. Select your button and go to properties
5. Click events (the lightning bolt) and double click the option click
6. Now hit enter and type in (with no "s) "label_message->visible = true;"
7. Now compile and click the button. Your text in the label should appear now
Hope this helps broaden your learning a little
what do u mean by compile?
"7. Now compile and click the button. Your text in the label should appear now"
nvm,just figured out what i was doing wrong, i was using visual basics instead of C++ -_-
double edit: how do u save it so other computers can open it?
-=Coool=-
21st March 2008, 09:38
Thanks for the tutorial it really helped me out.
Tha playah
21st March 2008, 14:37
Ew. I wouldn't reccommend using Visual Studio from Microsoft.
It's a crappy IDE, but the debugger is a nice one though.
I would reccommend you all using code::blocks, which is a cross platform (For all linux freaks including me :) ), open source IDE. Hook minGW up on it, and you're ready to go.
Give it a try at codeblocks.org. :)
Nice tutorial though, I'm sure many will learn from it.
Eh520
22nd March 2008, 14:29
um.. this question isnt about C++ but its abit related
well i tried Visual Basic 6 and the express edition, and they're abit diff in some coding.
like eg
msgbox " hi " <-- VB6
msgbox ("hi") <--- express edition will force you to put bracket around it to reach the same effect as VB6
and earlier this thread said that C++ and the express edition is no difference, but is there any difference on little things like this?
That Asian Guy
22nd March 2008, 20:55
what do u mean by compile?
"7. Now compile and click the button. Your text in the label should appear now"
nvm,just figured out what i was doing wrong, i was using visual basics instead of C++ -_-
double edit: how do u save it so other computers can open it?
compile is basically build. For some reason, C++ programs u build wont run on other computers. Use C# instead. You can easily switch to C# by replacing "->" and "::" with "."
Also, there are no "^" in C#.
Ew. I wouldn't reccommend using Visual Studio from Microsoft.
It's a crappy IDE, but the debugger is a nice one though.
I would reccommend you all using code::blocks, which is a cross platform (For all linux freaks including me :) ), open source IDE. Hook minGW up on it, and you're ready to go.
Give it a try at codeblocks.org. :)
Nice tutorial though, I'm sure many will learn from it.
thanks. personally i prefer visual studio because of the amount of support there is. microsoft forums offer tons of help, along with msdn. also, visual studio is the most commonly used environment, and u can easily obtain source code and projects written in it.
um.. this question isnt about C++ but its abit related
well i tried Visual Basic 6 and the express edition, and they're abit diff in some coding.
like eg
msgbox " hi " <-- VB6
msgbox ("hi") <--- express edition will force you to put bracket around it to reach the same effect as VB6
and earlier this thread said that C++ and the express edition is no difference, but is there any difference on little things like this?
the express edition lacks some features compared to enterprise or pro. About the VB stuff, VB is different from VB.NET. VB6 is just the old VB, while anything after VS2003 is VB.NET. Microsoft just changed some syntax, which they do alot of the time. Recently, a .NET framework update made my old program using a dataGridView malfunction.
Alright, hope all this helps :P
oharat0010336
24th March 2008, 00:23
great tut :bunny::bunny: but do you have a link or something that could go into a little more detail.... ive used the search thing but i couldn't find one and the library thing i find isn't all that helpful...
That Asian Guy
24th March 2008, 04:20
great tut :bunny::bunny: but do you have a link or something that could go into a little more detail.... ive used the search thing but i couldn't find one and the library thing i find isn't all that helpful...
thanks :)
elaborate on what u need :P
a book? further explanations on a certain topic?
oharat0010336
24th March 2008, 05:24
well i have vc++ 2008 express and im looking for a list of somesort that can give me a little more info on how to use the different events like if im using a checkbox to do what you did how would i make the text reappear when the checkbox isn't clicked or like can you have this doe something simple like press certain keys? stuff like that... just to elaborate a little more on what i can do with the different events so im not stuck with the visibility and i can hopefully move to making a trainer so i don't have to leech and i know this is much more advanced but also like how would i use addresses from a ct with my trainer or even if i could.
thx a bunch
That Asian Guy
24th March 2008, 05:36
oh
definitely the microsoft developer network (MSDN) library
start from here: http://msdn2.microsoft.com/en-ca/library/k50ex0x9(en-us).aspx
oharat0010336
24th March 2008, 06:47
ok thx for the link but how do i use the syntax stuff? do i have to type it in manually or is there a button or something i click in vc? i guess i misworded my earlier post cuz thats the link i followed and i got to that but i guess im really just misunderstanding what its trying to tell me... XD sorry... so yea what would i do then with the syntax stuff that it gives me if im not using just the code editor thing but im using the visual part? and like the checkbox example is if i wanted to make the text disappear when it is checked and appear when its not where would i put the visibility stuff?
That Asian Guy
24th March 2008, 17:53
to be honest, I never look at the declarations at the top, since VS has an intellisense feature which automatically pops that up. scroll down and ull find the examples section (in most pages) which has code samples complete with comments
oharat0010336
25th March 2008, 03:29
ok so i get to the checkedstatechanged event and it doesn't give me an example and i can't figure out how to use it in my script and if it does give me an example it always talks about some threestate crap and i can't decipher how to use the code from that example. Also for like keypress in the example it says how to make it count the keys but it doesn't say how to make it hit like just z or something like that, or if it does its hidden fairly well and probably in plain sight.
That Asian Guy
25th March 2008, 03:53
uh for a checkbox u do this:
private: void checkBox_checkedstatechanged (Object^ sender, EventArgs^ e)
{
if (checkBox->Checked == true)
{
// Do whatever u want when the checkbox is checked
}
else
{
// Do something when its not checked
}
}
oharat0010336
25th March 2008, 04:13
ok so that works for the checkboxes but how would i use addresses for hacks in my scripts... like if i wanted to have something that turns dEM on and off what would i put? also if im trying to use the keypress function so i could have an auto something how would i make it hit a specific key? I know this is way above my level but from all the trainers ive leeched it looked like they only needed something to turn the hacks on and off and autolooters so im guessing im getting the right things for that, but if im not then can you tell me if you know cuz if i make a trainer i won't have to leech other peoples and i can just update it to go around the patches...... thx a bunch for putting up with my constant questioning
Eh520
25th March 2008, 08:39
for the programs made by C++ (like the MFC applications), do they really only work in the computer you create it with? cuz like arnt some trainers made using C++ too?
scruie
25th March 2008, 15:25
for the programs made by C++ (like the MFC applications), do they really only work in the computer you create it with? cuz like arnt some trainers made using C++ too?
Don't know where this rumour of making something in C++ will only work on your PC and not on others. There might be badly coded stuff out there that does this, but that's bad coding nothing more.
That Asian Guy
25th March 2008, 22:16
Don't know where this rumour of making something in C++ will only work on your PC and not on others. There might be badly coded stuff out there that does this, but that's bad coding nothing more.
this error occurs on VC++.NET 2005 ONLY
no clue why
Eh520
26th March 2008, 09:36
um.. and just wondering about the book C++ for dummies, it says that it includes Dev C..
well is that same as visual C++? like are all C++ codes the same? if i learn everything in that book, and use the Visual C++ express edition program, will i get the same things?
scruie
26th March 2008, 15:48
this error occurs on VC++.NET 2005 ONLY
no clue why
Ah, you have to make sure ppl install the .NET libraries on their machines. Thus, it is always wise to tell them to install all .NET from version 1 through to 3.5; as .NET is not backward compatible.
The reasoning behind this was for all .NET creations to be smaller because the user(s) would have the necessary .NET files on their machines.
That Asian Guy
28th March 2008, 03:27
unfortunately, applications I make in VC# 2005 work while applications I make in VC++ 2005 do not work, tested on the same machine. an example was my asian web browser, made in VC++. Noone with the .net framework could run it.
To try this out (I was disappointed when i discovered this) I installed VS 2005 on both my laptop and desktop. When I built a program in VC++ 2005 on my laptop and transferred it to my desktop, it would not run. The same thing happened vice versa
:(
cruSher333
28th March 2008, 15:49
great tut!
so i can make small app. and save it in VC 2008 and it will work on other pc's?
hellodeteeddie
29th March 2008, 02:24
I have a Question. How do i make the program run something like maplestory. Cnexon\maplestory\maplestory.exe
And is there any how i can see or figure those codes out. or do i have to make em by myself? Like ur "label_message->Visible = false;" Kinda confusing for me:S
"Btw, when i try CTRL + F5 Then an error pops and says there is not EXE file or sumtin?-.-"---> worked when downloaded 2008V
That Asian Guy
30th March 2008, 04:45
great tut!
so i can make small app. and save it in VC 2008 and it will work on other pc's?
ive experienced no such problems on VC 2008, so the answer is yes
I have a Question. How do i make the program run something like maplestory. Cnexon\maplestory\maplestory.exe
And is there any how i can see or figure those codes out. or do i have to make em by myself? Like ur "label_message->Visible = false;" Kinda confusing for me:S
"Btw, when i try CTRL + F5 Then an error pops and says there is not EXE file or sumtin?-.-"---> worked when downloaded 2008V
U can run programs by : System:: Dianostics:: Process::Start("filepath");
u can figure out codes by referring to msdn library (http://www.msdn.com)
explain the last one a bit more i dont get wht u mean :\
hellodeteeddie
2nd April 2008, 19:01
U can run programs by : System:: Dianostics:: Process::Start("filepath");
So i should type this in C:\:: Nexon:: Maplestory::Start("MapleStory.exe");??
salzazar
2nd April 2008, 19:20
So i should type this in C:\:: Nexon:: Maplestory::Start("MapleStory.exe");??
haha good one :D
oh nvm it wasn't a joke.. You should write the whole filepath where it says filepath for example.
System::Diagnostics::Process::Start("C:\Nexon\Maplestory.exe");
hellodeteeddie
2nd April 2008, 19:47
Hahah. :P
Thx <3
That Asian Guy
3rd April 2008, 02:26
haha good one :D
oh nvm it wasn't a joke.. You should write the whole filepath where it says filepath for example.
System::Diagnostics::Process::Start("C:\\Nexon\\Maplestory.exe");
fixed :)
salzazar
3rd April 2008, 18:51
ive experienced no such problems on VC 2008, so the answer is yes
U can run programs by : System:: Dianostics:: Process::Start("filepath");
u can figure out codes by referring to msdn library (http://www.msdn.com)
explain the last one a bit more i dont get wht u mean :\
Thought it was diagnostics not dianostics
That Asian Guy
4th April 2008, 02:44
yes, youre right :P
hellodeteeddie
4th April 2008, 18:19
System::Diagnostics::Process::Start("C:\Nexon\Maplestory.exe");
Dosent Work :O?? When i try click on the button just an error appers:'(
EDIT: Worked when i putted 2x \
salzazar
4th April 2008, 19:39
fixed :)
I mix up all the .net languages codex with each other xD
RamboIV
8th April 2008, 19:00
May I suggest a better compiler? DevC++
If people are insisting on making trainers I believe it would be best to compile the program in DevC++ considering it will get rid of the fact that the user may require to install .Net Framework 3+ (if they haven't already got it).
That Asian Guy
10th April 2008, 02:45
System::Diagnostics::Process::Start("C:\Nexon\Maplestory.exe");
Dosent Work :O?? When i try click on the button just an error appers:'(
EDIT: Worked when i putted 2x \
uh like i mentioned before you will need "\\" instead of "\"
May I suggest a better compiler? DevC++
If people are insisting on making trainers I believe it would be best to compile the program in DevC++ considering it will get rid of the fact that the user may require to install .Net Framework 3+ (if they haven't already got it).
No way. VC++ has much more support, and the IDE of visual studio is much better. Besides, .NET only takes a few minutes to install
Assassin53
13th April 2008, 10:34
I get how to make the program and everything but I'm not sure how to run it as a program and not as a C++ document. Please help me on this subject.:D
wcbrilman
13th April 2008, 20:47
Uhm, try to compile it?
Assassin53
13th April 2008, 22:17
Um Ok could i get a description about what that is im very new to this C++ stuff. Please and Thank you
firekiller
13th April 2008, 23:19
thanks alot i learned somthing from this tutorial, and i did it all on my first try ty ty.
btw, yeah how do you compile? is it in the C++?
Sezabi
13th April 2008, 23:35
Click the build menu up?
firekiller
14th April 2008, 01:14
Click the build menu up?
umm thats not what im talking bout im talking bout compiling it to make it an actually program so that it opens without C++ documentation...
Sezabi
14th April 2008, 22:01
Click then Build > Batch build and select release. Or CRTL + f7 (not sure which F-key... either F7 or F9)
Assassin53
14th April 2008, 23:20
thank you this help me out but I only have one last question. How do you change the icon. Sorry if is a noob question
That Asian Guy
15th April 2008, 02:38
F5- start debugging
Ctrl+F5- Run without debugging
F7- Build
salzazar
15th April 2008, 21:41
thank you this help me out but I only have one last question. How do you change the icon. Sorry if is a noob question
Haven't read any previous posts but do you mean the icon when the application is running or the icon on the desktop?:\
That Asian Guy
18th April 2008, 05:17
this is a slight downside of VC++, it doesnt have the property page unlike VB or C#
delete "app.ico" from ur project folder, copy the icon u want in, rename it to "app.ico", rebuild
salzazar
19th April 2008, 19:52
this is a slight downside of VC++, it doesnt have the property page unlike VB or C#
delete "app.ico" from ur project folder, copy the icon u want in, rename it to "app.ico", rebuild
I think he wants to change the icon of the .exe
That Asian Guy
19th April 2008, 23:30
I think he wants to change the icon of the .exe
thats what im talking about... :x
tjfordz
21st April 2008, 03:07
Wow, thanks very much! Great tutorial
timmyeo
25th August 2008, 03:17
yay! this is best tutorial EVER!
here is my program:http://www.mediafire.com/?cb1ylz2tj4y
i added a button which was show what it hid=)
That Asian Guy
27th August 2008, 04:07
Good :). Once you get to know properties and events, start calling methods and you'll soon have many useful programs.
vBulletin® v3.7.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.