Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7669003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:29:53+00:00 2026-05-31T15:29:53+00:00

Version 6.0 of the common controls (comctl32.dll) implements a new approach for subclassing controls

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:29:55+00:00Added an answer on May 31, 2026 at 3:29 pm

    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.

    typedef BOOL (WINAPI *LPFN_SETWINDOWSUBCLASS)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_PTR);
    typedef LRESULT (WINAPI *LPFN_DEFSUBCLASSPROC)(HWND, UINT, WPARAM, LPARAM);
    typedef BOOL (WINAPI *LPFN_REMOVEWINDOWSUBCLASS)(HWND, SUBCLASSPROC, UINT_PTR);
    typedef BOOL (WINAPI *LPFN_INITCOMMONCONTROLSEX)(LPINITCOMMONCONTROLSEX);
    
    typedef struct SubclassStruct {
        WNDPROC Proc;
    } SubclassStruct;
    
    LPFN_SETWINDOWSUBCLASS      SetWindowSubclassPtr = NULL;
    LPFN_REMOVEWINDOWSUBCLASS   RemoveWindowSubclassPtr = NULL;
    LPFN_DEFSUBCLASSPROC        DefSubclassProcPtr = NULL;
    LPFN_INITCOMMONCONTROLSEX   InitCommonControlsExPtr = NULL;
    
    HMODULE ComCtlModule = NULL;
    
    int Subclasser_Init(void)
    {
        INITCOMMONCONTROLSEX CommonCtrlEx = {0};
    
    
        ComCtlModule = LoadLibrary("comctl32.dll");
        if (ComCtlModule == NULL) 
            return FALSE;
    
        SetWindowSubclassPtr = (LPFN_SETWINDOWSUBCLASS)GetProcAddress(ComCtlModule, "SetWindowSubclass");
        RemoveWindowSubclassPtr = (LPFN_REMOVEWINDOWSUBCLASS)GetProcAddress(ComCtlModule, "RemoveWindowSubclass");
        DefSubclassProcPtr = (LPFN_DEFSUBCLASSPROC)GetProcAddress(ComCtlModule, "DefSubclassProc");
        InitCommonControlsExPtr = (LPFN_INITCOMMONCONTROLSEX)GetProcAddress(ComCtlModule, "InitCommonControlsEx");
    
        if (InitCommonControlsExPtr != NULL)
        {
            CommonCtrlEx.dwSize = sizeof(CommonCtrlEx);
            InitCommonControlsExPtr(&CommonCtrlEx);
        }
    
        return TRUE;
    }
    
    int Subclasser_Uninit(void)
    {
        if (ComCtlModule != NULL)
            FreeLibrary(ComCtlModule);
        return TRUE;
    }
    
    LRESULT CALLBACK Subclasser_SharedSubclassProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam, UINT_PTR SubclassId, DWORD_PTR RefData)
    {
        SubclassStruct *Subclass = (SubclassStruct *)SubclassId;
        return CallWindowProc(Subclass->Proc, hWnd, Message, wParam, lParam);
    }
    
    int Subclasser_SetProc(HWND hWnd, WNDPROC Proc, WNDPROC *OriginalProc, void *Param)
    {
        SubclassStruct *Subclass = NULL;
        int Result = TRUE;
    
    
    
        SetLastError(0);
        if (SetWindowLongPtr(hWnd, GWLP_USERDATA, (__int3264)(UINT_PTR)Param) == 0)
        {
            if (GetLastError() > 0)
                return FALSE;
        }
    
        if (SetWindowSubclassPtr!= NULL) 
        {
            Subclass = (SubclassStruct*)malloc(sizeof(SubclassStruct));
            Subclass->Proc = Proc;
            *OriginalProc = (WNDPROC)Subclass;
            Result = SetWindowSubclassPtr(hWnd, Subclasser_SharedSubclassProc, (UINT_PTR)Subclass, NULL);
        }
        else
        {
            *OriginalProc = (WNDPROC)(void *)GetWindowLongPtr(hWnd, GWLP_WNDPROC);
    
            SetLastError(0);
            if (SetWindowLongPtr(hWnd, GWLP_WNDPROC, (__int3264)(intptr)Proc) == 0)
            {
                if (GetLastError() > 0)
                    Result = FALSE;
            }
        }
    
        if (Result == FALSE)
            return FALSE;
    
        return TRUE;
    }
    
    int Subclasser_UnsetProc(HWND hWnd, WNDPROC Proc, WNDPROC *OriginalProc)
    {
        SubclassStruct *Subclass = NULL;
        int Result = TRUE;
    
    
        if (RemoveWindowSubclassPtr != NULL)
        {
            if (*OriginalProc != NULL)
            {
                Subclass = (SubclassStruct *)*OriginalProc;
                Proc = Subclass->Proc;
            }
    
            Result = RemoveWindowSubclassPtr(hWnd, Subclasser_SharedSubclassProc, (UINT_PTR)Subclass);
            free(Subclass);
        }
        else
        {
            SetLastError(0);
            if (SetWindowLongPtr(hWnd, GWLP_WNDPROC, (__int3264)(UINT_PTR)*OriginalProc) == 0)
            {
                if (GetLastError() > 0)
                    Result = FALSE;
            }
        }
    
        SetLastError(0);
        if (SetWindowLongPtr(hWnd, GWLP_USERDATA, 0) == 0)
        {
            if (GetLastError() > 0)
                Result = FALSE;
        }
    
        *OriginalProc = NULL;
    
        if (Result == FALSE)
            return FALSE;
    
        return TRUE;
    }
    
    LRESULT Subclasser_DefProc(WNDPROC OriginalProc, HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
        if (OriginalProc == NULL)
            return DefWindowProc(hWnd, Message, wParam, lParam);
        if (DefSubclassProcPtr != NULL)
            return DefSubclassProcPtr(hWnd, Message, wParam, lParam);
        return CallWindowProc(OriginalProc, hWnd, Message, wParam, lParam);
    }
    

    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 GetModuleFileName and GetFileVersionInfo.

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class library project that references the version 4.1 Microsoft.Practices.Common dll. I
What's the advantage of saying #pragma comment(linker, /manifestdependency:\type='win32' \ name='Microsoft.Windows.Common-Controls' \ version='6.0.0.0' \ processorArchitecture='x86'
I tried this: #include <windows.h> #pragma comment(linker,/manifestdependency:\type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\) LRESULT CALLBACK
Version Dependent Some of the answers to this question deal with older versions of
In newer versions of the common control library, the listview supports groups. When I
There are two common ways to run mobile version of a website: Detecting the
My new assignment at work is to create a second version of our existing
Okay, so i'm pretty new to C++ & the Windows API and i'm just
We have a number of legacy projects that were recently added to TFS version
I am new to development and version control. My present workflow to make changes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.