Quick question regarding RegisterClassEx()

Im a little confused on whats happening with this:

// Register the window class
if (!RegisterClassEx(&wndclass))
return 0;

I cant see how we are registering the window class here (even though i know we are). The thing which is confusing me is that this uses an if statement and a "not equal to" operator, could someone explain to me how the compiler is reading this please.

Ive googled around but i havnt found a breakdown of this.
RegisterClassEx is a function that registers a windows window class. If it returns 0 the registering failed. So, you do it within an if statement to immediately check the return value, to see whether you should continue or quit (in this case, the program would just close without an error message. Not very elegant).
ref: http://msdn.microsoft.com/en-us/library/ms633587%28v=vs.85%29.aspx

Return Value

Type: ATOM

If the function succeeds, the return value is a class atom that uniquely identifies the class being registered. This atom can only be used by the CreateWindow, CreateWindowEx, GetClassInfo, GetClassInfoEx, FindWindow, FindWindowEx, and UnregisterClass functions and the IActiveIMMap::FilterClientWindows method.

If the function fails, the return value is zero.


might also need to read:
http://www.cplusplus.com/doc/tutorial/control/ (!)
http://www.cplusplus.com/doc/tutorial/operators/ (if else...)
The reason why im confused with this is that ive always thought of an if statement as a thing which checks a condition and carries out the code in the following braces,and not that it actually performs a function, like:

if (x > b)
{
blah
};

So i cant see how this if statement calls the RegisterClassEx() function because the if statement would read RegisterClassEx() as a condition? :)

Am i right in what im saying?
No, you got that wrong, the if statement does not execute anything here.
it works like that:

if (expression)
do_that

in this case, at the point
if(!RegisterClassEx(&wndclass))

The following things happen (in that order):
1) RegisterClassEx is called.
2) The ! operator is invoked on the return value of RegisterClassEx
3) if checks the truth value of the return value of the ! operator.

You gotta get into your head that if you use a function within an expression, it means "call that function and work with the return value".
Last edited on
Thanks AGAIN hanst99 for all your replies to my threads.
Last edited on
Topic archived. No new replies allowed.