This event still destroys the CSubClsApp object,but certain processing must now happenbefore and after the CSubClsApp objectdestruction. Before the class is destroyed, all globally subclassedwindows must be unloaded. This code destroysonlythe globally subclassed windows; destroying any other window wouldcause our application to crash. Because we know what the windowcaptions will contain, it is a simple matter of looping through allthe current windows in the application and only unloading the onesthat have been globally subclassed. We do not want to unload the mainform because it is already in the process of being unloaded. Neitherdo we want to unload the original window because, as I mentionedearlier, we would lose our window handle(m_hwnd) that is needed to release theglobal subclassing.
Instead of performing instance subclassing on each window separately,which would be a lot of work, we have altered the base functionalityof every window to suit our needs. Clicking the Un-Subclass buttonand closing the application will destroy all the created windows andrestore the original lpfnWndProc functionpointer in the form window class.
aa06259810