|
-
Feb 24th, 2001, 01:11 AM
#1
Thread Starter
Hyperactive Member
Hello
I am new to VC++, but i am quite interested in programming. I did a few examples from books, butnthey always made me use the MFC, and they did not explaint to me how to make functions, sub, and then call them. If some one could explain that to me, that would be great, and also how to write a c++ program that is blank(like a new project in VB), but that does not run as a console, but as a usual windows program. thanx a lot
P.S.: I only use VC++
Amon Ra
The Power of Learning.
-
Feb 24th, 2001, 02:04 AM
#2
Addicted Member
http://newdata.box.sk/bx/c/
I sugest you start with the console. At least to you get the hang of functions & loops in C.
Functions are done like this
Code:
void vFunction(int pram1,int pram2)// like a sub returns nothing
{
}
int iFunction(int pram1) // function returns value
{
return(pram1);
}
void main()// always required
{
int a;
vFunction(1,2);
a = iFunction(1);
iFunction(4);
}
-
Feb 24th, 2001, 06:50 AM
#3
Frenzied Member
If youj are a begginer don't start with windows programming. Learn C++ good first by experimrnting with console apps.
Thare are no subs in C++. Subs are really void functions (which don't return a value).
void mysub()
{//do something}
//no value is returned]
With out MFC you can't draw controls on a dialog. You need to create them using CreateWindowEx API Function.
Actually you can draw controls if you are using resources.
Here is a sample of how to make a window using raw API.
Code:
1. open visual c++
2. File > New
3. Click Projects tab
4. click Win32 Application and give it a name
5. click finish
6. click the File View Tab on TreeView
7. go to File > New
8. in the first tab Click C++ Source File and name it
9. Copy and paste the code in the new file
10. right click the Header folder and add Windows.h
11. click execute
#include <windows.h>
LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);
char szWinNamw[] = "MyWin";
int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,
LPSTR kposzArgs, int nWinMode)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wcl;
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hInstance = hThisInst;
wcl.lpszClassName = "My Window";
wcl.lpfnWndProc = WindowFunc;
wcl.style = 0;
wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcl.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
wcl.lpszMenuName = NULL;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;
wcl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
if(!RegisterClassEx(&wcl)) return 0;
hwnd = CreateWindow(
"My Window",
"Skeleton Window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
HWND_DESKTOP,
NULL,
hThisInst,
NULL
);
ShowWindow(hwnd, nWinMode);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch(message) {
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
-
Feb 24th, 2001, 10:29 AM
#4
Here is a simple DOS i/o program. I used stdio functions instead of iostream.
Code:
// File that contains the standard i/o features. You can
// use the file iostream.h, (which will be a little easier,)
#include "stdio.h"
void main()
{
// Declare a string variable (used to hold our name)
char* cName;
// Print a message to the console window using printf()
printf("Hello, what is your name? ");
// Recieve input from the user using scanf()
// we are storing it in the variable called cName
scanf("%s",cName);
// Output our data to the console window. %s tells us that
// the variable cName should be in its place. \n simply tells
// the compiler to go to a new line
printf("\nHello %s\n", cName);
}
-
Feb 24th, 2001, 10:41 AM
#5
Frenzied Member
stdio is a system header. It should be in angle brackets.
PHP Code:
#include <stdio.h>
-
Feb 24th, 2001, 11:27 AM
#6
Monday Morning Lunatic
Also, you need to allocate a buffer rather than just a random pointer.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 24th, 2001, 11:43 AM
#7
Thread Starter
Hyperactive Member
Help
Thanks guys, i will try that. thanx for helping
Amon Ra
The Power of Learning.
-
Feb 24th, 2001, 12:05 PM
#8
Thread Starter
Hyperactive Member
LOL :)
How do i start a console in VC++?? Which option do i select?
Amon Ra
The Power of Learning.
-
Feb 24th, 2001, 12:06 PM
#9
Monday Morning Lunatic
Win32 Console Application.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 24th, 2001, 12:11 PM
#10
Thread Starter
Hyperactive Member
OK
ok, thanx a lot
Amon Ra
The Power of Learning.
-
Feb 24th, 2001, 12:17 PM
#11
Thread Starter
Hyperactive Member
-
Feb 24th, 2001, 12:18 PM
#12
Monday Morning Lunatic
Add a new .cpp file, and add the following code:
Code:
#include <iostream.h> // Allows you to use input/output
void main() { // All console programs must have this function
cout << "Hello World!" << endl;
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 24th, 2001, 12:30 PM
#13
Thread Starter
Hyperactive Member
-
Feb 24th, 2001, 12:32 PM
#14
Monday Morning Lunatic
To declare a variable you just use:
...as in:
Code:
char mychar; // 1 byte
short myshort; // 2 bytes
int myint; // 4 bytes
long mylong; // Also 4 bytes
float myfloat; // Same as a VB single
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 24th, 2001, 12:33 PM
#15
Thread Starter
Hyperactive Member
Thx
Cool! Hmmm, do you have an idea of what i could try to do as practice?
Amon Ra
The Power of Learning.
-
Feb 24th, 2001, 12:36 PM
#16
Thread Starter
Hyperactive Member
?
Where do i declare the variables? is there a public or private declaration?
Amon Ra
The Power of Learning.
-
Feb 24th, 2001, 01:38 PM
#17
Monday Morning Lunatic
You can declare them anywhere 
There's no public/private as such. For example:
Code:
void MyFunction() {
int x;
}
void Other() {
x = x + 1;
}
This is not allowed, since x is out of scope, because it's in a different set of braces. However, this would work:
Code:
int x;
void MyFunction() {
x = x + 2;
}
void Other() {
x = x + 1;
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 24th, 2001, 01:50 PM
#18
Thread Starter
Hyperactive Member
k
OK thanx! 
Hmmm, so u can declare anywhere. cool. Btw, what are the operators?
Amon Ra
The Power of Learning.
-
Feb 24th, 2001, 01:53 PM
#19
Monday Morning Lunatic
+, -, (), *, /, % (Mod), ^ (Xor), & (And), | (Or)
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 24th, 2001, 02:10 PM
#20
Thread Starter
Hyperactive Member
Amon Ra
The Power of Learning.
-
Feb 25th, 2001, 02:24 AM
#21
Addicted Member
Amon,
It might be easier for you to start with File|New, then select the Files tab, and then select C++ Source File. It will take you to the IDE with a blank page for you to type in codes. When you are ready to build, the program will ask you to set up a default project workplace. All you have to do is to type in a name with the cpp extension, and voila.
This might be less confusing to you than doing the File|New|Projects.
Hope this helps.
substring.
-
Feb 25th, 2001, 11:49 AM
#22
Thread Starter
Hyperactive Member
Great
Thanx for the tip. You ar eright, it might be easier like that.
Amon Ra
The Power of Learning.
-
Feb 26th, 2001, 12:59 PM
#23
Monday Morning Lunatic
Re: Now that I have got it, Can I ask some questions.
Originally posted by Wak
What does this bit mean?????
LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);
char szWinNamw[] = "MyWin";
I understand it a little
And that's it. Thanx
WindowFunc is a prototype for your event handler's function, and the other is just a definition of a string array.
To make it a grey background you need to specify the correct brush when you populate your WNDCLASSEX structure. What are you using at the moment?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 27th, 2001, 05:10 AM
#24
Hyperactive Member
OK THEN, HOW BOUT THIS?
I know that if I put GRAY_BRUSH in there, it'll make the form gray, but how would I go about making it the standard colour, according to the settings, that each person has?? You know.. the convetional way. I'm retarded. Thanx
Visual Basic 6.0 Enterprise
Visual C++ 6.0 Professional
Wak 
-
Feb 27th, 2001, 06:17 AM
#25
Monday Morning Lunatic
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 28th, 2001, 06:17 AM
#26
Hyperactive Member
thanx
I figured out from your post that I could use COLOR_APPWORKSPACE. thant again
Visual Basic 6.0 Enterprise
Visual C++ 6.0 Professional
Wak 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|