| Manifestly Xtra Pretty Forms | |||||||||||||
| Adding the XP Style to Forms and Controls in VB 6 and VB .NET | |||||||||||||
![]() Windows XP ushered in a host of improvements. One of them is a whole new window (small 'w') style that you can use in most Visual Basic environments. The illustration shows you what this new style looks like for a standard button component. In this article, we'll show you how to implement this style, and a little 'About' why it works, too! |
|||||||||||||
Under the "Life is short! Eat dessert first!" principle, here's the basic "magic formula" for the whole technique. You can find this documented on a lot of web sites and it's pretty much the same everywhere. Create a text file with this content (you can cut and paste this into Notepad): Save the file into the directory for the application that you wish to add XP styling into using the file name: AppName.exe.manifest ... where your application name replaces AppName. For example, for a default VB .NET Windows application, the filename would be WindowsApplication1.exe.manifest and you would save it in the bin directory for your application. In addition, you must change the FlatStyle property from Standard to System for each component that you want to have the new XP style. This gives you the ability to create really ugly forms where the two styles are mixed if you really want to. See the example at the left side. Since this is a capability provided by Windows, rather than VB .NET, you can apply these styles to VB 6 as well as VB .NET basically the same way. Microsoft won't support it, however. In a Knowledge Base article they state it quite clearly: Although you can enable a Windows XP theme or visual style in Visual Basic 6.0 ... Microsoft does not support this feature. If you enable a Windows XP theme in Visual Basic 6.0, you may encounter unexpected behavior. A lot of programmers will testify that it seems to work fine if you do it right, however. In VB 6, you also need to initialize the correct version of the DLL that actually does the work, Comctl32.dll. To accomplish that, put this code in the Initialize event for the form where you want the new style used. You ALSO have to have a manifest file in the directory where .EXE of the VB 6 program is installed. The reason the manifest file must be present is interesting. Microsoft placed both the old (version 5) and the new (version 6) functionality in version 6 of Comctl32.dll, but they made version 5 the default. The manifest file simply specifies that the version 6 style be used instead. In other words, it changes the default. In VB 6, you can also avoid placing the manifest in the directory with the VB 6 compiled .EXE by using a VB 6 Resource File. The Microsoft web site mentioned in the next paragraph tells you exactly how. I'm a big fan of learning VB .NET through a process of understanding how the code has changed from VB 6. Studying the way XP visual styles are applied between the two is one of the best learning experiences of this type. And rather than simply repeat it all here, I'm going to refer you to "the bottom line" on how to do this. Microsoft wrote a very complete explanation: Using Windows XP Visual Styles. Microsoft also notes that ... You cannot view visual styles when you run the compiled executable from the Visual Basic 6.0 Integrated Development Environment (IDE). Wrong again, megabuck breath. You can do that! Simply place the manifest file in the folder where your VB 6 IDE is (probably, C:\Program Files\Microsoft Visual Studio\VB98) and name it vb6.exe.manifest. The proof is at the left. Actually, I don't recommend doing that, however. First ... it's just a matter of visual style and I don't think you're application is going to live or die because of the shape of the boxes. Second, if Microsoft tells us that there are hidden gotcha's, I think we ought to believe them. Even if it works 99.9 percent of the time. Third, if you REALLY want this style, move up to VB .NET !! |
|||||||||||||


