Determine COMCTL32 version

. You can also read a related article in MSDN at
http://www.microsoft.com/msdn/sdk/inetsdk/help/inet1560.htm

Here's what Roger had to say:

Just followed the link on that page to the MSDN Inet article about COMCTL32. It looks like a good way also of telling the version.

This article shows another method of testing - also I make use of a static so that the test only needs to be done once for efficiency.

The new windows common controls live in a system DLL called COMCTL32.DLL

The original Windows 95 included a version of COMCTL32.DLL which gave us most of the nice common control, like list views and tree controls.

With Internet Explorer 3, Microsoft introduced some new controls along with enhancements to the existing controls. These include features like flat toolbars, hover mode in list views, and new controls like the date picker.

Internet Explorer 4 adds support for new flat scroll bars. However, it also changes the behaviour of the toolbar control and makes existing MFC applications display toolbars incorrectly (because MFC CToolBar has hardcoded numbers for the size of seperators - but that is another story :-).

In order for your application to work with these different version, and to take advantage of the new features if they are available, one needs to be able to detect the version of COMCTL32 you are using.

The following addition to your CWinApp class will give you this ability.

Step 1:

In your application .h file add the following just before the definition of your CWinApp-derived application class...
enum COMCTL32VERSION {
     COMCTL32_UNKNOWN, COMCTL32_400, COMCTL32_470, COMCTL32_471
};

This enumeration has values for the origina Win95 COMCTL32 (v4), the IE3 COMCTL32 (v4.7) and the IE4 COMCTL32 (v4.71)

Step 2:

Add the following to your CWinApp-derived class in your application .h file...
class CMyWinApp : public CWinApp {
     ...
     // COMCTL32 detection
private:
     static COMCTL32VERSION c_nComCtl32Version;
public:
     static COMCTL32VERSION ComCtl32Version();
     ...
};

Step 3:

Add the following to your application .cpp file...
COMCTL32VERSION CMyWinApp::c_nComCtl32Version = COMCTL32_UNKNOWN;

COMCTL32VERSION CMyWinApp::ComCtl32Version() {
     // if we don't already know which version, try to find out
     if (c_nComCtl32Version == COMCTL32_UNKNOWN) {
          // have we loaded COMCTL32 yet?
          HMODULE theModule = ::GetModuleHandle("COMCTL32");
          // if so, then we can check for the version
          if (theModule) {
               // InitCommonControlsEx is unique to 4.7 and later
               FARPROC theProc = ::GetProcAddress(theModule, "InitCommonControlsEx");
               if (! theProc) {
                    // not found, must be 4.00
                    c_nComCtl32Version = COMCTL32_400;
               } else {
                    // The following symbol are unique to 4.71
                    //   DllInstall
                    //   FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos
                    //   FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo
                    //   FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange
                    //   FlatSB_ShowScrollBar
                    //   _DrawIndirectImageList _DuplicateImageList
                    //   InitializeFlatSB
                    //   UninitializeFlatSB
                    // we could check for any of these - I chose DllInstall
                    FARPROC theProc = ::GetProcAddress(theModule, "DllInstall");
                    if (! theProc) {
                         // not found, must be 4.70
                         c_nComCtl32Version = COMCTL32_470;
                    } else {
                         // found, must be 4.71
                         c_nComCtl32Version = COMCTL32_471;
                    }
               }
          }
     }
     return c_nComCtl32Version;
}

This function gets a handle to COMCTL32 and then looks for what functions exist within it. By looking for functions which are known NOT to be in a given version (and only in later versions), we can tell what version we actually have.

By using a static to keep the result, we do not need to keep redoing the detection logic, as once we know, the COMCTL32 cannot change from underneath us - it will stay loaded until our application terminates.

Step 4:

When using a feature that relies on a given version, you can use code like
     if (CMyWinApp::ComCtl32Version() > COMCTL_400) {
          // use a feature only in IE3 version or later
          // like flat tool bars
     }

Of course, what I do is have my own standard enhanced CWinApp-derived class which has these additions (and others) in it. The I derive each application from this enhanced class.



Comments

  • Beats by Dre sportslige stilfuldt – men ikke sponsor-brand – hovedtelefoner pÃ¥ spil

    Posted by lidhvn744 on 07/18/2013 12:58am

    Kontakt de mennesker, der får dine ting og give dem konstruktiv klage omkring de spor, de gør. Dette vil få dig beundring, midler og en fremragende popularitet.Overlook sandheden om at skabe tiltalende ord, udvikle vidunderlige spor, samt at blande spor, så de virkelig blande o ‘så perfekt sammen for at hjælpe dig alligevel mærke til de forskellige aspekter af denne blanding. [url=ttp://beatsbydrdredan.ucoz.com/]beats by dre tilbud[/url] Beats By Dr. Dre Beats Wireless har annonceret et trådløst Bluetooth-headset. Dette er udformningen af den populære Solo HD og kan let kobles med en smartphone eller tablet. Den nye model er også udstyret med ControlTalk, med en mikrofon i øret og alle nødvendige kontroller. Beats By Dr. Dre introducerer Beats trådløse Bluetooth hovedtelefoner Beats By Dr. Dre Beats introducerer den trådløse Bluetooth-hovedtelefoner lytteren fuld musikalsk frihed. [url=http://beatsbydretilbud.webspawner.com/]beats by dre[/url] This focus brings a nice clarity to vocal performances. On Bill Callahan’s “Drover,” the vocals are delivered with an extra bit of treble edge that only adds to Callahan’s unique baritone delivery. The vocals also standout nicely on Jay-Z and Kanye West’s “No Church in the Wild”—the mix still features plenty of low-end resonance, but the emphasis on mids and highs helps the vocals shine, rather than get lost by the intense production, which can happen pretty easily with hip hop and electronic tracks on lesser headphones.

    Reply
  • Als men verliest de eigen gevoelens, hij of zij lijken aanvaardbaar Beats by Dr Dre oordopjes

    Posted by mrswanzi on 06/06/2013 07:49pm

    [url=http://koptelefoon-monsterbeats.blogspot.com/]monster beats koptelefoon[/url] de Beats Tour oordopjes zorgen voor een verbazingwekkende driver design. 20hz lijkt een beetje hoger met een oordopje dat verklaringen te ontwikkelen om 'goede reproductie van de dij hop ". meestal de verminderde waarde van zo heel veel van de veel beter de bas. Van know-how 14 Hz kan eventueel worden de optimale waarde. Beats by dre pro rood zwart Zoals geciteerd door de methode van de kwaliteit van de Tour de lijst: ". Grote, high-efficiency automobilisten laat u toe om zeker Crank It Up en voldoening te halen uit hardop uit te houden zonder geluid-wrecking vervorming" Driver dimensie behoort tot een van de meest essentile factoren om uit te checken uit voor bij het krijgen van oordopjes. [url=http://monsterkoptelefoon.npage.de/]beats by dre kopen[/url] De urBeats zijn wederom ontstaan uit een perfecte samenwerking tussen Monster en Dr. Dre. Zodoende zijn ook deze in-ears verschenen onder het Beats By Dr. Dre label, waar al meer succesnummers onder zijn uitgebracht. Deze voorzien allen in unieke audioprestaties en een stijlvol design. Het is ook daarom dat deze urBeats de titel met trots mogen dragen! [url=http://koptelefoon-monsterbeats.webs.com/]beats by dre[/url] Mode zit van oudsher stevig verweven in de Amerikaanse hip hop en rap cultuur. De uitingen die artiesten dragen worden door fans makkelijk geadopteerd. Dr. Dre geldt in deze cultuur nog altijd als een invloedrijk persoon. Door de samenwerking met de Amerikaanse rapper aan te gaan, legde Monster direct het fundament voor een succesvolle introductie van de Beats hoofdtelefoons. Beats Tour concentreren - de oordopjes keuze met behulp van de Beats by Dre producent merchandise lijn

    Reply
  • Nothing

    Posted by Legacy on 04/16/2003 12:00am

    Originally posted by: Rizwan Ali

    Nothingd s sdf ds

    Reply
  • See MSDN

    Posted by Legacy on 03/26/2002 12:00am

    Originally posted by: Andre

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/Shell/programmersguide/versions.asp

    Reply
  • Already supported by MFC

    Posted by Legacy on 10/18/2000 12:00am

    Originally posted by: Thomas Freudenberg

    In the file "..\src\afximpl.h" you may find follwoing lines:
    
    

    // for determining version of COMCTL32.DLL
    #define VERSION_WIN4 MAKELONG(0, 4)
    #define VERSION_IE3 MAKELONG(70, 4)
    #define VERSION_IE4 MAKELONG(71, 4)
    #define VERSION_IE401 MAKELONG(72, 4)
    extern int _afxComCtlVersion;
    DWORD AFXAPI _AfxGetComCtlVersion();


    Therefore, you can write in your code:

    if (_AfxGetComCtlVersion() >= VERSION_IE4)
    {
    // ...
    }

    Reply
  • Why not return the acual version?

    Posted by Legacy on 09/29/2000 12:00am

    Originally posted by: Andy Metcalfe

    Just a thought: if the app requires a newer version thatn that supported by the enumerates you've defined, you'll have to keep adding new ones.

    Instead, why not read the version from the DLL directly?

    That way, you won't have to keep changing your code when you need a newer version than 4.71....

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • "Security" is the number one issue holding business leaders back from the cloud. But does the reality match the perception? Keeping data close to home, on premises, makes business and IT leaders feel inherently more secure. But the truth is, cloud solutions can offer companies real, tangible security advantages. Before you assume that on-site is the only way to keep data safe, it's worth taking a comprehensive approach to evaluating risks. Doing so can lead to big benefits.

  • Live Event Date: August 14, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Data protection has long been considered "overhead" by many organizations in the past, many chalking it up to an insurance policy or an extended warranty you may never use. The realities of today make data protection a must-have, as we live in a data driven society. The digital assets we create, share, and collaborate with others on must be managed and protected for many purposes. Check out this upcoming eSeminar and join eVault Chief Technology …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds