Click to See Complete Forum and Search --> : Wrapping CreateWindow[EX]


potatoCode
February 25th, 2009, 06:59 AM
Hello all :)

I'm new to windows programming and I'd like to hear some advice.
For my practice applications,
I always wrap (by putting it in a class) this API for simplicity and control.
But I'm begining to wonder if it is necessary.
In professional development, is this API always wrapped?

Thank you.

_Superman_
February 25th, 2009, 10:14 AM
Most definitely.
In MFC, all classes derived from CWnd like CButton, CEdit etc. call into CreateWindowEx.

potatoCode
February 27th, 2009, 02:03 AM
Most definitely.
In MFC, all classes derived from CWnd like CButton, CEdit etc. call into CreateWindowEx.
Hi _Superman
I see.
What about WNDCLASS?
Do you think it's better to wrap it by inheritance or put it inside the class?
I've tried both but I'm not too sure which way is better.

Thanks.

_Superman_
February 27th, 2009, 02:44 AM
I would put it as a private member of the class.

potatoCode
February 27th, 2009, 04:27 AM
I would put it as a private member of the class.
Okay.
can you please share with me why, if any, you prefer that over the other? :)

_Superman_
February 27th, 2009, 04:42 AM
WNDCLASS is an internal data structure required by a Window.
So naturally it becomes a private data member of you window class.

potatoCode
February 27th, 2009, 05:08 AM
How silly of me, you're right.
Thanks :thumb:

JohnCz
March 10th, 2009, 11:19 PM
In professional development, is this API always wrapped?
Most definitely.
Well, I think a right answer is most definitely [b]NOT[/]. They are not always wrapped; this is not necessary and rather a choice of architectural design.
There are programs written using only Windows API. MFC does for CWnd class. CreateWindowEx is wrapped by CWnd member CreateEx that is mainly used for popup/top-level or OLE windows. Child windows are created using Create member.
I do not see any reason for storing WNDCLASS or WNDCLASSEX. This structure is used only for registering window class or retrieving window’s class information. What needs to be stored is registered class’ name.

By the MFC is using different overrides of Create, to make easier creating control windows using predefined windows classes.
Look at some Create members for common window controls.