Adam Caudill

Security Leader, Researcher, Developer, Writer, & Photographer

XP-Style Controls In Visual Basic 6

This post was imported from an old blog archive, and predates the creation of AdamCaudill.com.

This is a quick and dirty overview of how to get those ever so coveted XP controls in your application. There is a lot of detail I’m leaving out, but you should get the point, if you want more detail a google search or two should give you plenty of info.

Let’s get started….

First you need to make a manifest file, this is just a plain text file that tells Windows how to treat you program. Paste the following into Notepad and save it in the same folder that your program is in, with the name <appname>.exe.manifest (where <appname>.exe is the name of your program, i.e. the manifest for MyGame.exe would be MyGame.exe.manifest).

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <assemblyIdentity 
        version="1.0.0.0" 
        processorArchitecture="X86" 
        name="CompanyName.ProductName.YourAppName" 
        type="win32" />
    <description>Your application description here</description>
    <dependency>
        <dependentAssembly>
            <assemblyIdentity 
                type="win32" 
                name="Microsoft.Windows.Common-Controls" 
                version="6.0.0.0" 
                processorArchitecture="X86" 
                publicKeyToken="6595b64144ccf1df" 
                language="*" />
        </dependentAssembly>
    </dependency>
</assembly>

Now, you’re almost done already! The next step is to bind your program to ComCtl32.dll, if it doesn’t you won’t get the pretty controls. Paste the following code somewhere in your program and call it as soon as your program starts (i.e. in Sub Main), this will ensure that your program actually links to the ConCtl32.dll file before any controls are drawn.

Private Declare Function InitCommonControlsEx Lib "comctl32.dll" ( _
    iccex As tagInitCommonControlsEx _
    ) As Boolean

Private Type tagInitCommonControlsEx
    lngSize As Long
    lngICC As Long
End Type

Private Const ICC_USEREX_CLASSES = &H200

Public Function InitCommonControlsVB() As Boolean
Dim iccex As tagInitCommonControlsEx

    With iccex
        .lngSize = LenB(iccex)
        .lngICC = ICC_USEREX_CLASSES
    End With
    InitCommonControlsEx iccex
    InitCommonControlsVB = (Err.Number = 0)
End Function

And your done! Enjoy your new fancy controls :p (Note, some controls don’t draw right on there own, if you have a control that doesn’t look right, add a Picture box to your form and move the offending control onto the Picture Box.)

Adam Caudill


Related Posts

  • CloseApp

    This post was imported from an old blog archive, and predates the creation of AdamCaudill.com. This is a useful function to close a program based on a windows caption, this should work for any top-level window. Paste all this into a standard module, save it. Then call CloseApp("Notepad") or whatever the name of the window is, it’s nice & simple and should close the program instantly. This requires Windows 2000 plus, for older versions of Windows a different method is required, that isn’t covered here, seeing as Windows 2000 and better require special privileges to forcefully close a program.

  • Back From New York

    This post was imported from an old blog archive, and predates the creation of AdamCaudill.com. Wow, the summer’s over and I’m finally home! After spending the last five months in New York (quite a difference from my native Florida), I’ve finally made it back home. Much has happened while I’ve been away, not the least of which is the death of Imspire and a few related projects. While giving up on these dreams has been difficult, I believe the result will be for the best.

  • APISettings

    This post was imported from an old blog archive, and predates the creation of AdamCaudill.com. Visual Basic provides a less than elegant method of saving data in the Windows registry, the GetSetting & SaveSetting functions. These functions store setting in HKEY_CURRENT_USER\Software\VB and VBA Program Settings\<AppName>\<Section> not very pretty is it? The APISettings module is a drop-in replacement using pure Win32 API for its processing power and increased stability. The reason for developing this and for making it drop-in compatible is to all those new to the Win32 API to add its functionality with minimal difficulty.

  • Conexant (formerly Rockwell) Softmodem HSF Modem

    This post was imported from an old blog archive, and predates the creation of AdamCaudill.com. I was actually rather lucky to have this brand of WinModem, as the good people over at Linuxant.com offer a very high quality driver that makes installation a breeze! But, they have recently changed their marketing methods and charge $15 for the driver, so these really lives no viable, free alternative (a rarity to say the least for linux).