tags:

views:

27

answers:

2

When I create a child window for the second time,

if (!::RegisterClass(&hwClass))
{
    throw std::runtime_error("RegisterClass failed!");
}

It throws an exception that the class already exists. but the child window class was deleted when the child window was destroyed at:

WM_DESTROY:
{
   delete this;  //destroy child class
}

It works if I comment the expection error. does that mean I don't need to register a class again?

+1  A: 

Yes, you should not register the class again.

This is from MSDN:

All window classes that an application registers are unregistered when it terminates.

Update: This makes sense because many windows can be created based on a window class and a window class exist before creating any window.

mmonem
+1  A: 

From the UnregisterClass documentation, which states:

Before calling this function, an application must destroy all windows created with the specified class.

Indicates that destroying the windows doesn't unregister the class.

ChrisF