viksoe.dk

atlwinsuper.h


This article was submitted .


These are classes that adds global superclassing capabilities to the ATL 3 windowing templates.

Superclassing (also known as class cloning) creates a new window class. The new window class uses the window procedure from an existing class to give the new class the functionality of the existing class. The superclass is based on some other window class, known as the base class. Frequently the base class is a Windows-supplied control class, but it can be any window class.

Global superclassing is not supported with the current ATL implementation, since it relies on some tricky thunking stub deep down in the window procedure implementation.
This is a pity, because if you really want to change the appearance of the user interface (turning all buttons into flat buttons, for instance) subclassing each and every control is tedious.

Creating one flat button control class and automatically turn evey window created with the standard BUTTON class into a flat button is what superclassing is all about... so here are some classes to make global superclassing in ATL possible.

How to use them

They can be a bit tricky to set up, so follow this guide closely.

Add the includes to the stdafx.h file.

  #include <atlbase.h>
  #include <atlapp.h>
  #include "atlwinsuperbase.h"
  extern CAppModule2 _Module;
  #include <atlwin.h>
  #include "atlwinsuper.h"
Derive from CAppModule2 instead of CComModule. If you are using the WTL 3.1 library, then you should still derive from CAppModule2.
Remember to change the main implementation file where the _Module object is instantiated and change the class to CAppModule2 as well.

Create some control classes. Derive from the window template CSuperWindowT. The class takes two template arguments: the parent class and the control you wish to superclass.

  class CFlatButton : 
    public CSuperWindowT< CFlatButton, CButton >
  {
    BEGIN_MSG_MAP(CFlatButton)
       MESSAGE_HANDLER(WM_CREATE, OnCreate)
    END_MSG_MAP()
    ...
  };
The control will have the same methods available as if it was derived directly from a CWindow class.

Now before you launch any window or dialog, make sure to register the superclass window. To do so, create an instance of the control.

    CFlatButton fb;
    fb.Register();
    ...
    CMainDlg dlgMain;
    nRet = dlgMain.DoModal();
    ...
You may only superclass a window class once.

Source Code Dependencies

Microsoft ATL Library

Download Files

DownloadSource Code (4 Kb)

To the top