winAPI questions


From my book:

---------------------------------------------------------
RegisterClassEx(&WindowClass);

Easy, isn’t it? The address of the struct is passed to the function, and Windows extracts and squirrels away all the values that you have set in the structure members. This process is called registering the window class. Just to remind you, the term class here is used in the sense of classification and is not the same as the idea of a class in C++, so don’t confuse the two. Each instance of the application must make sure that it registers the window classes that it needs."
---------------------------------------------------------

What does it mean in a sense of classification?

------

From my book:

---------------------------------------------------------
Initializing the Program Window

After calling ShowWindow(), the window appears on-screen but still has no application content, so you need to get your program to draw in the client area of the window. You could just put together some code to do this directly in the WinMain() function, but this would be most unsatisfactory: in this case, the contents of the client area would not be permanent — if you want the client area contents to be retained, you can’t just output what you want and forget about it. Any action on the part of the user that modifies the window in some way, such as dragging a border or dragging the whole window, typically requires that the window and its client area are redrawn. Any action on the part of the user that modifies the window in some way, such as dragging a border or dragging the whole window, typically requires that the window and its client area are redrawn.
---------------------------------------------------------

Doesn't windows redraw the window itself? As well as the client area background? So you wouldn't necessarily need to redraw these yourself in the WindowsProc function right?


------

MSDN and my book say:

----------------------------------------------------------------------------------

"CW_USEDEFAULT is valid only for overlapped windows; if it is specified for a pop-up or child window, the x and y parameters are set to zero."

----------------------------------------------------------------------------------

Why is it only valid for overlapped windows? By overlapped windows it means windows that their can be two of right or what I am confused.


Thanks for anyone who answers any of my questions!
Last edited on
What does it mean in a sense of classification?

Not sure how to give a suscinct answer, so I'll attempt an example: dogs are comonly classified (i.e. grouped, I suppose) by breed, into Cocker Spanials, Red Setters, Dalmations, Corgis, etc.

In the same way, windows can be classified by class as BUTTON, EDIT, etc (control window classes), #32770 (the "atom" for the Dialog window class, etc. Or an application defined windows. The window's class name or "atom" works in the same was as the breed of dog.

(An atom is a unique ID for the windows class. You get one as the return of RegisterClassEx if it's successful, elsewise zero. It can be used to identify the class rather than the name. And some classes, like the one for the standard systme dialog window, have no name.)

Doesn't windows redraw the window itself?

Not in the case of normal windows. It's up to the app to draw (or paint) itself in response to a WM_PAINT message from the system. And erase it's background when sent a WM_ERASEBKGND message (these are the common messages; there others, for example, to do with custom drawing of controls.)

Control (button, scrollbar, etc) and dialogs are drawn by the system.

Why is it only valid for overlapped windows?

See...

Window Features / Overlapped Windows
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632599%28v=vs.85%29.aspx#overlapped

Andy
Last edited on
@andywestken

Oh ok that makes sense.

Still confused on the second part lol, I read through it but I dont see the exact explanation for why it is only valid for overlapped windows?

Because the CreateWindowsEx function does not accept it (CW_USEDEFAULT) for other types of windows (than overlapped windows.)

A window has to be either a normal (top level) window, a popup (like a dialog box), or a child (controls and similar).

If you create a popup or a child window, you cannot use CW_USEDEFAULT.

I guess they (the Microsoft lot) decided to do this because:
- the layout of dialogs is carefully designed with the controls ncely laid out, so need to be a particular size
- controls are only ever used as children, so will always be sized by their parents

Andy
Last edited on
But why doesn't it accept it, what could go wrong?

Should I just accept thats how it works?
You have to accept that that's the way Microsoft decided it would work.

But you don't just have to accept it, you could try it and see what happens.

(It still creates the window, but it's position is (0, 0) and so is it's size. It doesn't set the position and size to an actual -- non-zero -- default value.)

Andy
Last edited on
So microsoft just doesn't want it like that? Well ok, and if I do the size and position is zero so it really cant be seen on screen?

Well thanks!
Also by window I meant the borders and stuff, not the client area cause that is drawn by the application. But isn't the background of the client area done by the system?
Last edited on
Topic archived. No new replies allowed.