Results 1 to 8 of 8

Thread: Best way to add XP style to your controls

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    14

    Cool Best way to add XP style to your controls

    Let's Start (without introduction)

    Design your form and put your necessary controls in it (e.g. Form1)

    Change "Startup Object" to Sub Main

    Add a module and insert in it this code

    VB Code:
    1. Private Type tagInitCommonControlsEx
    2.    lngSize As Long
    3.    lngICC As Long
    4. End Type
    5. Private Declare Function InitCommonControlsEx Lib "comctl32.dll" _
    6.    (iccex As tagInitCommonControlsEx) As Boolean
    7. Private Const ICC_USEREX_CLASSES = &H200
    8.  
    9. Public Function InitCommonControlsVB() As Boolean
    10.    On Error Resume Next
    11.    Dim iccex As tagInitCommonControlsEx
    12.    ' Ensure CC available:
    13.    With iccex
    14.        .lngSize = LenB(iccex)
    15.        .lngICC = ICC_USEREX_CLASSES
    16.    End With
    17.    InitCommonControlsEx iccex
    18.    InitCommonControlsVB = (Err.Number = 0)
    19. End Function
    20.  
    21. Public Sub Main()
    22. InitCommonControlsVB
    23.  
    24. ' Start your Application here ( e.g. Form1.Show )
    25. Form1.Show
    26. End Sub

    Now Build EXE Program ( for example test.exe )

    Open Notepad and type

    HTML Code:
    <?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>
    Save it in the directory you saved test.exe in it with name (test.exe.manifest)

    Finally, execute your program (test.exe) you will see all comon controls with XP Styles...

  2. #2
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Best way to add XP style to your controls

    Nice Code, but it should be in the codebank
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  3. #3
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Best way to add XP style to your controls

    Now if I was being cynical, I'd say you'd just lifted that from vbAccelerator

    There's also an example there of having the manifest file as a resource, so it'll get compiled into the exe and you don't need to distribute it.

    It should be noted that this will provide XP styles to Microsoft Windows Common Controls 5.0 not 6.0, as comctl32.ocx (ocx for v5) is dependant on comctl32.dll whereas mscomctl.ocx (ocx for v6) is not.

  4. #4
    Lively Member
    Join Date
    Jul 2006
    Posts
    110

    Re: Best way to add XP style to your controls

    I use this and i have a problem with the buttons. The last character of the caption get's put on a new line. Why is this and how can i fix it?

  5. #5
    New Member
    Join Date
    Jul 2006
    Posts
    1

    Re: Best way to add XP style to your controls

    Warning!
    Visual Basic 6.0 Does Not Support Windows XP Themes or Visual Styles
    http://support.microsoft.com/?id=309366

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Best way to add XP style to your controls

    Yes, but there have been workarounds for most of its limitations and bugs. Like using an option button in a frame will make it display as all black but if you place the option button in a picturebox inside the frame then it will draw correctly etc.

    Not to mention that the code will not apply XP Themes UNLESS you are running Windows XP.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Member
    Join Date
    Jul 2006
    Posts
    53

    Re: Best way to add XP style to your controls

    Tested it on XP...

    and it works fine without having the code in the module and the sub-main, just the manifest...

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Best way to add XP style to your controls

    Quote Originally Posted by vbaccelerator.com
    Ensuring Your Application Links to ComCtl32.dll

    If you provide a manifest, but your application does not link to ComCtl32.dll, then it will fail to load - sometimes with no error message!. You need to call at least InitCommonControls before any visual elements are displayed. Sometimes, you don't need to do anything because your application may already link to ComCtl32.dll (for example, if it includes any of the Windows Common Controls provided with Visual Basic), however, to be certain it works it is best to call InitCommonControls prior to displaying any forms.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width