Difference between revisions of "Visual themes"
m (Tidied headers) |
m (Added a link to the Tabbed dialog page) |
||
(16 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
+ | __NOTOC__ | ||
{{VB6}} | {{VB6}} | ||
If you want to make use of the XP look and feel in your applications, you need to use a new feature called application manifests. These instruct windows to load a special version of a particular library that has the XP styled controls in. | If you want to make use of the XP look and feel in your applications, you need to use a new feature called application manifests. These instruct windows to load a special version of a particular library that has the XP styled controls in. | ||
Line 52: | Line 53: | ||
Happy styling. | Happy styling. | ||
− | == | + | == Real common controls == |
− | + | If you want to have XP styled common controls (ListView, TreeView, etc...) then there is another hurdle. | |
+ | |||
+ | You have to be using the VB5 version of the common controls OCX which unfortunately is missing a fair amount of functionality. If you can live without this, go ahead and swap them over. | ||
+ | (Please note that this is NOT version 5 of VB and this will still work fine in VB6) | ||
+ | |||
+ | == Password boxes == | ||
+ | Unfortunatley, there is no practical method of using the XP password character in a VB text box. | ||
+ | |||
+ | There are two recomended methods for standard win32 applications: | ||
+ | * Create the window with the ES_PASSWORD style. Unfortunatley, we have no access to this in VB. | ||
+ | * Send the EM_SETPASSWORDCHAR message. This sounds promising, but as the VB edit box is not a unicode version, trying to set the right character just shows a letter I with a Diaeresis. | ||
== VB.NET 2003 == | == VB.NET 2003 == | ||
Line 60: | Line 71: | ||
Also check out: Application.EnableVisualStyles() as descibed (with its issues) here: http://blogs.msdn.com/rprabhu/archive/2003/09/28/56540.aspx | Also check out: Application.EnableVisualStyles() as descibed (with its issues) here: http://blogs.msdn.com/rprabhu/archive/2003/09/28/56540.aspx | ||
+ | |||
+ | ==See also== | ||
+ | * [[Tabbed dialogs#XP style tabs|Getting an "XP" theme on tabbed dialogs]] | ||
+ | |||
+ | == External Links == | ||
+ | * [http://www.vbaccelerator.com/home/VB/Code/Libraries/XP_Visual_Styles/ vbAccelerator] | ||
+ | * [http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=63469&lngWId=1 Proper XP tab backgrounds] | ||
+ | * [http://msdn2.microsoft.com/en-us/library/ms997646.aspx Using Windows XP Visual Styles in MSDN] |
Latest revision as of 16:37, 7 December 2009
This article is based on Visual Basic 6. Find other Visual Basic 6 articles. |
If you want to make use of the XP look and feel in your applications, you need to use a new feature called application manifests. These instruct windows to load a special version of a particular library that has the XP styled controls in.
A typical application manifest looks like:
<?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="Company.Product" type="win32" /> <description>Product Name</description> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> </dependency> </assembly>
This can either be in the same folder as your executable called appname.exe.manifest or it can be embedded in a resource file with a type of 24 and an ID of 1.
Now, to make these work properly, you need to call the InitCommonControls function before any forms are loaded. This can either be in the startup forms Initialize event or in Sub Main()
Private Declare Sub InitCommonControls Lib "comctl32.dll" () InitCommonControls
Under some circumstances, using the XP styles can cause VB applications to crash on shut down after the last code is executed. This can be worked around by loading the shell32.dll into your applications memory space on startup:
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" ( _ ByVal lpLibFileName As String) As Long LoadLibrary "shell32.dll"
I have these in a single routine that I call on startup:
'This needs to be called in Sub Main or Form_Initialize otherwise it will fail with a manifest Sub XPInitStyle() LoadLibrary "shell32.dll" InitCommonControls End Sub
Happy styling.
Real common controls
If you want to have XP styled common controls (ListView, TreeView, etc...) then there is another hurdle.
You have to be using the VB5 version of the common controls OCX which unfortunately is missing a fair amount of functionality. If you can live without this, go ahead and swap them over. (Please note that this is NOT version 5 of VB and this will still work fine in VB6)
Password boxes
Unfortunatley, there is no practical method of using the XP password character in a VB text box.
There are two recomended methods for standard win32 applications:
- Create the window with the ES_PASSWORD style. Unfortunatley, we have no access to this in VB.
- Send the EM_SETPASSWORDCHAR message. This sounds promising, but as the VB edit box is not a unicode version, trying to set the right character just shows a letter I with a Diaeresis.
VB.NET 2003
Also check out: Application.EnableVisualStyles() as descibed (with its issues) here: http://blogs.msdn.com/rprabhu/archive/2003/09/28/56540.aspx