Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get XP-style controls with VB6 7

Status
Not open for further replies.

Punchinello

Programmer
Apr 25, 2003
116
US
I am writing a small app with Visual Studio 6.0 Enterprise but most of the controls that I use (textbox, combobox, option button, command button) will not display with the Windows XP-style. Do I need a more recent version of VB or to find third-party controls for VB6?

Thanks
 
Search Google for how to create a manifest file for your exe.
 
Thanks, DrJavaJoe, the link was helpful and I'm on my way.
 
Interesting... thanks Doc

[fish] No Dolphins were harmed in the posting of this message... Dolphin Friendly Tuna!
 
Just a couple of notes if you place a manifest in your vb6.exe directory called vb6.exe.manifest, you will see your application in the ide with the xp styles. Also controls placed in a option box do not get the styles, but to get around this you can place a picture box in the option box first then put the control on the picture box.
 
DrJoeJava,
Since you seem to know alot about this, maybe you have one more answer on the subject. I've implemented the manifest and added the resource file (downloaded from the referenced site) to the project and voila...brilliant. The only down-side is that when the mouse moves over the form (running independently of the VB environment) there is a subtle, but disturbing, flashing effect among all labels and textboxes. The only event programmed for each control is their GotFocus and no programming is attached to any of the controls' containers so I don't think the flashing is a result of my code. Any ideas?
 
Hi,

I downloaded this code and I've not noticed a flashing effect, at least not to the extent that you describe. I do get a slight ripple effect when moving the mouse between Option 1 and it's container frame (for example) but it's barely noticable. It looks almost like the entire frame is refreshing / redrawing.

I've tried the program toggling the ClipControl property and it has no effect.

Puzzled...



- Andy
__________________________________
"On a clear disk you can seek forever"
 
Thanks Doc...One more note about my experience with this. I see that you mentioned that controls in an option box do not get the styles. I had a few option buttons in a frame and they(like the site said), didn't get drawn correctly. I put them in a picturebox and thy worked fine, except I couldn't set the forecolor property for them. What I had to do was to make the option buttons only the width of the circle, then put labels beside them for the titles. If anyone knows why I had to do this, I would be interested.
 
Are these controls in a frame control, if so try placing them in a picture box first, then place the picture box inside the frame control.
 
Its often annoying to carry the .manifest file with your application's exe file otherwise the application does not adapt these visual styles.

A better alternate is to embed the manifest in your application in the form of resource. This is the preffered way and also indicated in the second last para of the article pointed by DrJavaJoe.

Unfortunately VB's resource editor does not support RT_MANIFEST resource and thus it is not possible to embed the resource data into the exe file using VB's resource support.

Below is a VB code that opens a compiled VB exe file and adds the manifest data in the resource.

Preparations
1 - If your app starts with sub main than Call InitCommonControls in Sub Main otherwise call it in the Initialize event of the startup form
[tt]
Private Declare Sub InitCommonControls Lib "comctl32" ()
Public Sub Main()
InitCommonControls
End Sub
[/tt]
-OR-
[tt]
Private Declare Sub InitCommonControls Lib "comctl32" ()
Private Sub Form_Initialize()
InitCommonControls
End Sub[/tt]

2 - Compile the program to create exe.
3 - Place the application.exe.manifest in the applications directory. The manifest file must contain the XML content as described in the article.
4 - Now execute the program to check if the manifest is working properly and the XP visual styles are enabled.
5 - Execute the following program. It will add the content of the .manifest file in the application in the form of RT_MANIFEST resource.
___

___
After the resource is added to the application, you don't need to carry the .manifest file in your application directory. The application will adapt visual styles without the presence of .manifest file.
 
Here is the code that I forget to paste above after step 5.
Haste makes waste...[smile]
___
Option Explicit
Private Declare Function EndUpdateResource Lib "kernel32" Alias "EndUpdateResourceA" (ByVal hUpdate As Long, ByVal fDiscard As Long) As Long
Private Declare Function UpdateResource Lib "kernel32" Alias "UpdateResourceA" (ByVal hUpdate As Long, ByVal lpType As Long, ByVal lpName As Long, ByVal wLanguage As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Private Declare Function BeginUpdateResource Lib "kernel32" Alias "BeginUpdateResourceA" (ByVal pFileName As String, ByVal bDeleteExistingResources As Long) As Long
Const RT_MANIFEST = 24
Const CREATEPROCESS_MANIFEST_RESOURCE_ID = 1
Private Sub Form_Load()
AddManifestResource "D:\MyApp\Myapp.exe"
End
End Sub

Public Sub AddManifestResource(ExeFile As String)
'Read the manifest data from the .manifest file.
Dim Manifest As String
Open ExeFile & ".manifest" For Binary As #1
Manifest = Space$(LOF(1))
Get #1, , Manifest
Close

'Update(add) the manifest resource into the exe file.
Dim hRes As Long
hRes = BeginUpdateResource(ExeFile, 0)
UpdateResource hRes, RT_MANIFEST, _
CREATEPROCESS_MANIFEST_RESOURCE_ID, _
0, ByVal Manifest, Len(Manifest)
EndUpdateResource hRes, 0
End Sub
 
I actually do have the controls in a frame and the frame in a picturebox. I need the picture box because it is nested in another picturebox with scroll bars to create a scrolling region. Each user control implements a GotFocus to perform an autoscroll to make/keep them visible without having to mouse around (just tab key). Inside the inner picturebox, data is separated into 3 visual areas -- frames in this case -- but I'll remove the frames and place their controls directly on the picturebox and report back on the outcome.

Thanks for all the help.
 
Removing the frame also removed the flickering...maybe I'll use a round rect for visual grouping instead. Thanks, guys and doc, for the help. One question I forgot to ask: will this still run under Win98 Second Edition?
 
doc, are you saying this will not run at all under XP, or just that the XP style will not show up when not using XP?
 
Now I'm confused. Doc, are you saying that the same program will run fine under Win98 consistent with the Win98 interface AND it will run fine under XP with the XP interface? Without distributing two versions?
 
I don't think that's the case...

[fish] No Dolphins were harmed in the posting of this message... Dolphin Friendly Tuna!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top