PDA

Click to See Complete Forum and Search --> : Learning VC++


Jul 18th, 2000, 01:22 PM
I have a pretty good grasp of the C/C++ language, but I have MSVC++ 6.0 and I have absolutely NO IDEA how to use it....
how do you make a form or whatever its called in VC++?

and how do you add code to buttons?
and how do they make games in C++?
it doesnt look like it would be easy to make a game,
where would you store the pictures?
etc.. etc...
what I really need is something that explains the compiler basicly from the ground up,
I have a book called "Visual C++ 6 from the ground up"
but its not really from the ground up, they expect you to know the basics of the MSVC++ compiler, and I dont know the basics....

Thank you.

Jul 18th, 2000, 03:48 PM
You add code and Button's just like you would in VB. Click on the ToolBar and drag the Control on. To add code, double click on the Control and it brings you to the source file. You can also add code by selecting the File tab and then selecting which file you want to open.
How do they make gams in C++? well that is really self explanatory. (You can use DirectX in C++ too)
All picture's are stored in a Resource file (can be viewed by selecting the Resource tab).
If you're looking for a good book, try Teach Yourself Visual C++ In 21 days.




[Edited by Megatron on 07-18-2000 at 04:50 PM]

Jul 18th, 2000, 04:25 PM
take a look at this screenshot,
http://www.geocities.com/sfprogrammers/cppscreenshot.gif
you may have to enter that manually into your browser because geocities doesnt allow outside linking...

thats what happens when I double click a button or whatever..

and what i mean by how do you make games,
well the interface stuff doesnt look too good in VC++, do you just write the code and the images just appear on the screen? or do you have to have some background, like the form thing? ?????

I am not really looking for a good book on C++ because I dont have any money right now, but as soon as I get money, I will definetly get that book.



and I know HOW to add code, but how do I add code to a BUTTON?
like when you double click a button in VB.

Jul 18th, 2000, 05:08 PM
It's the same in C++, you double click on the Button. But before the actual part where you add code comes up, there should be a dialog that says OnYourButtonName. (Like the Screenshot) Click Ok and then it should bring to some code similar to the one below.


void CCalculatorDlg::OnMyButton()
{
// TODO: Add your control notification handler code here

}


For extended events of the Button, go into the Clas Wizard (Pres Ctrl+W), select your Button under the Object ID's box and then there should be 2 messages that appear in the Messages box (to the left of the Object ID's). They should be BN_CLICKED and BN_DOUBLECLICKED. These events will trigger when the Button is clicked or double clicked.

To make gams, it's a good idea to use DirectX, and you would use something like DirectDraw to draw your images.

Jul 18th, 2000, 05:28 PM
Originally posted by Megatron
It's the same in C++, you double click on the Button. But before the actual part where you add code comes up, there should be a dialog that says OnYourButtonName. (Like the Screenshot) Click Ok and then it should bring to some code similar to the one below.



there is no OK button, and nothing happens when I push ctrl + W
I have MicroSoft Visual C++ Enterprise Edition

Jul 18th, 2000, 05:49 PM
Ahhhh I see,
when I start a new MFC AppWizard(EXE)
I can add code,
but when I just make a regular win32 application, the box comes up like on the screen shot.....

why is this???

Jul 18th, 2000, 06:10 PM
It's much better to use MFC. When you create a regular Win32 App, a lot of code is not automatically created for you. You would have to create all of the Window's yourself, so it's much easier just to use MFC.

Regarding the Button's: In the screen shot, that was the property Window. You probably Right-clicked it. Try double clicking it again and see if you get a different Dialog. If so, hit the Enter key and you should be brought up to the source file.

Jul 18th, 2000, 06:13 PM
nope, tried that, I double clicked, and the property window appeared, I tried pushing enter, and the dialog went away, but thats it....

Jul 18th, 2000, 07:00 PM
Try using the ClassWizard from the Menu. Go to View > Class Wizard, then follow the instructions I gave earlier.

If there are any problem's let me know.

Jul 19th, 2000, 11:30 AM
Thank you for all the help megatron :)

Jul 19th, 2000, 11:37 AM
oh, I also want to know



* How to make a message box appear*
* How to show/hide a Dialog(Form)*
* How to change a command buttons caption*
* Do I have to delcare the API Calls in a *.h file? or are they already there?*



* Thanks for all the Help,


*Dennis Wrenn*

parksie
Jul 19th, 2000, 01:44 PM
MFC
---

Message boxes: MessageBox(text, caption = NULL, type = MB_OK);
Button caption: SetWindowText(text)

API
---
Message boxes: MessageBox(hWnd, text, caption = NULL, type = MB_OK);
Button caption: SetWindowText(hWnd, text)

=============================

All the API functions are defined for you, and are in windows.h

Jul 19th, 2000, 01:52 PM
How do I know the hWnd of the button to set its caption?

parksie
Jul 19th, 2000, 02:06 PM
Platform SDK to the rescue...

Microsoft says:

HWND GetDlgItem(
HWND hDlg, // handle to dialog box
int nIDDlgItem // control identifier
);


So you would have:

hWnd = CreateDialogBox(...);
hWnd_button = GetDlgItem(hWnd, IDC_BUTTON);


You'd need to #include "resource.h" to do this, but I would assume that's already been done.

Jul 19th, 2000, 02:10 PM
To Change the Button's Caption

First we must create a Member Variable for the Button. Follow these sets to create it.


Go to View > Class Wizard (Or press Ctrl + W)
Go to the Member Variables tab.
There should be a list of your Control ID's. Select your Control and press the Ad Variable button on the right.
Enter the name m_bButton. (make sure that the Catagory is Control and the Variable type is CButton). Click OK.
Go back to your Dialog and double click the button. If it is your first time going into the code of the button, you should be prompted with a MessageBox. Just click ok and accept the default settings.
Now you should be in the source window where you can see all of your code. Fill in the following code as follows

void CNotepadDlg::OnButton10()
{

// Declare a string named MyString and give it the value of "Hello"
CString MyString = "Hello";
// Change the Button's text to MyString
m_bButton.SetWindowText(MyString);

}

parksie
Jul 19th, 2000, 02:11 PM
Also, you can use this function:

BOOL SetDlgItemText(
HWND hDlg, // handle to dialog box
int nIDDlgItem, // control identifier
LPCTSTR lpString // text to set
);

Bit of a time saver really:

SetDlgItemText(hWnd_MyWindow, IDC_BUTTON, "New caption");

Jul 19th, 2000, 03:17 PM
Thanks, Both of you :)


but how do I show/hide a dialog(form)??
Thanks again...
Dennis Wrenn

Jul 19th, 2000, 04:07 PM
ok, I found windows.h and added it to my workspace, but isnt that yellow tooltip text supposed to show up? like in VB, or when I Type MessageBox( ???

and are you sure ALL of the api functions are in windows.h?
like findwindow, and getasynckeystate?

parksie
Jul 19th, 2000, 04:32 PM
Never add the system include files to your workspace. Simply #include <windows.h> in your source file. (note the angle brackets). All the API functions are there somehow, although if you look in windows.h, then there are instructions embedded in it as to how to remove parts you don't want.
For showing / hiding windows...

BOOL SetWindowPos(
HWND hWnd, // handle to window
HWND hWndInsertAfter, // placement-order handle
int X, // horizontal position
int Y, // vertical position
int cx, // width
int cy, // height
UINT uFlags // window-positioning options
);

...is the function you need.

SetWindowPos(hWnd_MainWindow, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER | SWP_HIDEWINDOW);

...will hide a window. Use SWP_SHOWWINDOW instead of SWP_HIDEWINDOW to show the window instead.

And no, it's not supposed to pop the tooltip up, you don't get that in VC! (Although it would be useful, cos some of those API functions are EVIL in length)

Jul 19th, 2000, 04:47 PM
ok gotcha, why shouldnt I add the system include files to my workspace?
and thank you for all the help :)

parksie
Jul 19th, 2000, 05:02 PM
Don't add the system files to your workspace because that's only for project files. If you reference them with angle brackets it searches its include file path (go Tools->Options->Directories) for them. It also helps it to get the dependency information sorted properly, and avoids reconfiguring things that shouldn't be changed.

PS: I've just read your email - thanks!

Jul 19th, 2000, 05:03 PM
Because it's easier just to include them with the #include statement. Plus, it will protect the original file incase of damage or modification.

Jul 19th, 2000, 05:30 PM
Oh, OK Thanks to both of you again :)

Jul 22nd, 2000, 10:11 PM
Parksie:

turns out in VC++ version 6 you do have the tooltip text, but I was used to VB automaticly capitalizing everything for me :o and C++ is case sensitive, so the tooltip text does not appear unless you use proper cases, a small price to pay for such a great feature :)

also, another question, where is "main()" in MFC apps?
I cant find it.....
or is there none?

if there is not one, where do I add all my functions?

parksie
Jul 23rd, 2000, 04:29 AM
All windows programs have a WinMain function, which MFC replaces with its own (called something like _tWinMain for Unicode compatibility). main() is only for DOS programs.

Jul 23rd, 2000, 04:55 AM
Thank you!

so, what makes winmain fire?
when the form loads(sorry I am used to VB)??

parksie
Jul 23rd, 2000, 05:16 AM
When a console program runs, the OS looks for main() and runs it. When a Windows program runs, it's the same procedure, but WinMain is called instead. It's analogous to Visual Basic's Sub Main() (as in called before anything is done).

Jul 23rd, 2000, 06:32 AM
Thank You Very Much!

if it wasnt for you, I would be even more lost than I currently am ;)