Version 6.0 of the common controls (comctl32.dll) implements a new approach for subclassing controls that is not available on older versions of Windows. What is the best way to implement subclassing so that it works on systems that support either version of the common controls library?
Version 6.0 of the common controls (comctl32.dll) implements a new approach for subclassing controls
Share
First, there is an article on MSDN that discusses the changes that occured in subclassing controls between version 6.0 and prior that you should be familiar with.
The best way to maintain backwards compatibility is to create wrapper functions for subclassing controls. This will require you to dynamically load the functions that are required for subclassing controls on version 6 of comctl32.dll. Here is a rough example of how it can be done.
The only other example can be found in OpenJDK. The one disadvantage to it is that it uses the the WindowProc as the subclass ID which crashes if you are subclassing more than one control on a dialog with the same WindowProc function. In the example above, we allocate a new memory structure called SubclassStruct and pass it’s address as the subclass ID which guarantees that each instance of the control you subclass will have a unique subclass ID.
If you are using the subclassing functions in multiple applications, some that use comctl32.dll < 6 and some that use comctl32.dll >= 6, you could detect which version of the common control library was loaded by getting comctl32.dll’s file version information. This can be done through the use of
GetModuleFileNameandGetFileVersionInfo.In addition, if you use SetWindowWord/GetWindowWord in the subclass callbacks with comctl32.dll 6.0, such as in the following Dr. Dobbs article on
Writing Windows Custom Controls, then you will need to use those code blocks conditionally when comctl32.dll < 6, because they will not work on version 6 or greater and will cause your application to crash.