Although this is a beginner question, I didn't know whether to put it here in the beginner forum, so i just put it here. So I just made a simple window using an online tutorial. I have a few questions about the code.
In this section of code, the tutorials say that you have to add the bit about RegisterClassEx to register it. First of all why do you have to register this class and second of all isn't this checking if it hasn't been registered? Shouldn't there be some code that actually registers it? I'll post the rest of my questions when I'm sure I can't figure them out...
Every window displayed must have a "class". The word "class" is a pretty generic name (hence much confusion about it), but what it really does is define a structure that is used as a template to create windows.
In other words, in order to create a window, Windows needs to know certain things about that window: its owner, its default color, icon, cursor, window procedure, etc.
It is called a "class" because just as in C++, one or more instances of a window may be created from the same class (type/definition/etc).
RegisterClassEx() tells the OS about your window class. It complains if there was a problem doing that. (If there was, there is something catastrophically wrong with the system, and you would need to reboot anyway...)
No and yes (kind of). RegisterClassEx() is what does the registering. The function result just tells you whether or not it succeeded. So you check the result in case something horrible happened.
Yes, every time you have functionname( ... ) you are calling the function. Since a function returns a value, you can place a function call in an expression, like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
usingnamespace std;
// Here is my function. It returns a value of type 'int'.
int add_two( int a, int b )
{
return a + b;
}
int main()
{
// Here is my expression. I am multiplying an int with an int.
int c = add_two( 3, 4 ) * 6;
// The first int is obtained by calling a function. (It is the function's result. In this case, the value 7.)
// The second int is a literal constant -- the value 6.
// I place the product (of my multiplication expression) in the int variable named 'c'. (That is, 'c = 42'.)
}
It might be worth your time to read through the C++ tutorials on this site. You can find them from the upper-right box on the main page. I'm sure a quick read will get you up to speed.