Search Tools Links Login

Real Windows XP Controls in Windows XP / VB6 without images or custom controls


Visual Basic 6, or VB Classic

Ever wanted your VB6 apps to fit in with Windows XP? Now you can do just that. There are other samples on this site that accomplish this, but they use user controls or images - which means that the controls are slow and may not be resizable - and they're large. Want a better solution? This is it. Real Windows XP controls on Windows XP that match the user's visual style (i.e. theme), without user controls or images, with only one API call. You can even use the standard Visual Basic controls (buttons, scrollbars, checkboxes, etc.) and it will work - all with the speed of a native application. Because it is a native application, using Windows to draw the controls.

Original Author: Brian Cairns

Code

Windows XP user?

So am I. But I didn't want to buy VB.NET. VB6 works just fine, thank you - except for one thing: "Visual Styles". How do you get your controls to have the new look and feel of Windows XP? Images or custom controls work, but the're big, hard to use, slow, and they usually don't support Windows XP visual styles (themes) - let alone large fonts or any of the other features in true Windows XP controls. So how do we make these "true" controls. It's easier than you might imagine.


Step 1: Create a new project. Add your controls, just like you would normally. Add your code. It is recommended that you add the themed controls last because it is a simple procedure that can be applied once your entire project is done. There is no need to use custom controls, or to add special source. All nececary source is added when you theme your project (only about 10 lines)


Step 2: Compile (make) your application into an EXE file.
If you open the application now it will have the "classic" visual style. This is for a reason. Your application is using the old Windows Common controls. How do we change this? With a MANIFEST file.


If you're not using Windows XP, stop here. MANIFEST files work only under Windows XP. You can add one without ill effects under other Windows operating systems, but you won't get the new controls if you don't have Windows XP. For Windows-XP like controls without Windows XP, this is the wrong place.


What is a MANIFEST file? A MANIFEST file is a text file with the same name as your EXE but with .MANIFEST on the end. For example, the MANIFEST file for "test.exe" would be "test.exe.MANIFEST". The ".MANIFEST" must be in all capitol letters.


Step 3: Create a new text file with the same name as your EXE, except with ".MANIFEST" on the end. ".MANIFEST" must be in all caps. For example, for "test.exe", you would make a text file named "test.exe.MANIFEST". Notepad will suffice for creating the file.


Step 4: Add the following text to your MANIFEST file:



<?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="prjThemed" type="win32" />

<dependency>

<dependentAssembly>

  <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df" language="*" />

</dependentAssembly>

</dependency>

</assembly>





Step 5: Add the following code to your project in the startup form:



Private Type INITCOMMONCONTROLSEX_TYPE

dwSize As Long

dwICC As Long

End Type

Private Declare Function InitCommonControlsEx Lib "comctl32.dll" (lpInitCtrls As _
INITCOMMONCONTROLSEX_TYPE) As Long

Private Const ICC_INTERNET_CLASSES = &H800



Step 6: Add the following code to the Form_Load procedure of your starup form:



Dim comctls As INITCOMMONCONTROLSEX_TYPE ' identifies the control to register

Dim retval As Long ' generic return value

With comctls

.dwSize = Len(comctls)

.dwICC = ICC_INTERNET_CLASSES

End With

retval = InitCommonControlsEx(comctls)




Step 7: Recompile (make) your EXE, using the same EXE name as before (and the same name as your MANIFEST file, minus the ".MANIFEST"). Execute your EXE file.


That's it! You can add controls to your project just like a normal VB project!


You can download a sample project and MANIFEST file below. Just right click on the project file and choose "compile" to compile the sample (you can also compile it from within the VB IDE). The project is just a simple demonstration of some of the Windows common controls.

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 399 times

Categories

Visual Basic 6

Attachments

Real_Windo46901172002.zip
Posted: 9/3/2020 3:45:00 PM
Size: 3,218 bytes


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.