If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

some questions about Window Class (WNDCLASS)

I read chapter 19 for Chalres Petzold Book (Windows Programming)..
This chapter explain how to create Multi Document interface (MDI)..

But after reading this chapter I was confused for Window Class ...
I will expalin in simple words ..
for MDI we have to create two windows
first Window is : Frame Window (= Main window of program)
second Window: Child Window

Petzold in his book Created only one window Class Say = WndClass
He Used This class one time to Prepare Frame Window ; Second time He Used the same class to prepare Child Window

Q1:
should the application have only one Window Class ?? and this will be used for all windows of the program,

Or I can Use many Window Classes in the same Program ?? and Why...

Q2:
and here , Petzold used the same Window class , How I can store the data two times .. I stored the data for wndclass when I create Frame Window
and Again I store the new data for the same Class when I create The Child Window!!!?? or something is not clear with Me??

Re: some questions about Window Class (WNDCLASS)

Originally Posted by mecheil.edwar

Can I use many window Classes for one Application and Why one class , or many classes??

Yes, you can use many window Classes for one Application. And usually you do it: Windows has already registered a lot of window classes for you, such as button, static, edit, listbox, SysListView32, and so on.

Re: some questions about Window Class (WNDCLASS)

Thanks Victor for your effective answers...
Now I have some notes after understanding this issue , I would like to add here to be useful for others..

Note 1: the first window should be created outside the wndProc Function Why...
Beacause if you want WndProc to do any action for the application .. first thing you have to inform wndProc is HWND.. the handle of the window..
if we look to windproc format it is:
WndProc(hwnd,...,....,...)
So , in this case if we want to create the first window from wndproc sure , the program will not run..

So, We have to create the first window outside wndProc

Example 1:
WinMain(...........)
{
...........
...........
CreateWindow (....) /// this should be the first window of application
}

Some users create the first window outside the winmain function also it is correct , but it should be outside windproc///

Note 2: After creating first window , we can create any window inside wndProc..and we can use same window class ..
the program in this case will run as following
1. After creating the window_1 .. Now this window has a handle say HWND = 0x002 as example
2. from window_1 when we send a message to create new window the wndProc will recive this message as following :

WndProc( hwnd = 0x002///Note the value of handle = the handle of window that we sent the message from it ,...,..)

...................
/// Say we will handle the message as following
Case New_Window:
HWND hwnd2 // now we will create object hwnd2 which will recieve the return value from function CreatWindow
hwnd2= CreateWindow(.....)
ShowWindow(hwnd2)
UpdateWindow(hwnd2)
Break;
..................
................
}

Re: some questions about Window Class (WNDCLASS)

Originally Posted by mecheil.edwar

Why one class , or many classes??

A window class is directly associated with its window procedure that you provide during registration. So creating window of the class implies creating a window with this specific behavior (which window procedure implements).

Now, if you need your app to implement some complex behavior, you distribute the whole functionality among particular windows with predefined behavior corresponding to their window classes, for example, edit controls process user keyboard input, buttons send specific commands, dialog implements command and control data processing logic, and at the same time all the windows handle their visual attributes, self drawing, mouse cursor shapes, etc. The more versatile/complex behavior you're after, the more window classes you need.

One more axis of flexibility: the class generic behavior can be tweaked a bit by subclassing window procedure. This way you obtain some specialized instance of the same class, for example, implementing a specific reaction to a specific message(s) only.

Re: some questions about Window Class (WNDCLASS)

Note 1: the first window should be created outside the wndProc Function Why...
Beacause if you want WndProc to do any action for the application .. first thing you have to inform wndProc is HWND.. the handle of the window..

Wrong. WndProc is called by Windows only. Therefore, to make WndProc to start being called by Windows you have to create the window first. And there is no other way to do that for the very first window in a thread but creating outside any window procedure.

Even more than that. To let messages reach your window procedure, the message pump must be spinned first providing message dispatching for the thread the window was created in.