Thursday, May 3, 2007

Enabling Visual Styles or Themes of XP and Vista in Visual Basic Application

Call the InitCommonControls Function



You must call the InitCommonControls function in the Form_Initialize event:


Private Declare Sub InitCommonControls Lib "comctl32.dll" ()

Private Sub Form_Initialize()
InitCommonControls
End Sub
NOTE: Do not call InitCommonControls in the Form_Load event. When you call InitCommonControls from the Form_Load event, the form cannot load.


Add an Application Manifest File



You must add a file named YourApp.exe.manifest to the same folder as your executable file. For example, if your application is named Generic.exe, include a manifest file that is named Generic.exe.manifest. The application manifest file has Extensible Markup Language (XML) format similar to the following:


<?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.YourApp"
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>


After you place the application manifest file in the same folder as the executable file, you can run the compiled executable file to display the Windows XP visual style in the application.

NOTE: You cannot view visual styles when you run the compiled executable from the Visual Basic 6.0 Integrated Development Environment (IDE).

For more Details Visit http://support.microsoft.com/kb/309366

No comments: