Simple window basics
| gsingh2011 (24) | |||
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... | |||
| Duoas (1449) | |||
| Yes and yes. 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...) Hope this helps. | |||
| gsingh2011 (24) | |||
| So is it registered automatically? and the code that I pasted about !RegisterClassEx is only used if theres a problem? | |||
| Duoas (1449) | |||
| 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. | |||
| gsingh2011 (24) | |||
| Ok, see my C++ isn't amazing yet so I don't see when RegisterClassEx is called... "if (!RegisterClassEx(&wc))" I can see that that checks if the function failed, but does it call it too? Sorry if thats a nooby question... | |||
| Duoas (1449) | |||
| Oh, I understand your confusion. 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:
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. Hope this helps. | |||
This topic is archived - New replies not allowed.
