[LTR]
This tutorial is about enabling XP styles for the VB standard controls only, also will not work for the Frame control
Since VB6 is an old language (in comparison with last windows version) it does not support drawing the XP styles on its controls and because Microsoft no more support VB6 we should not except a direct solution for this issue.
إقتباس(Steve McMahon)
The New XP Styles
The Windows XP Visual Styles are provided by ComCtl32.dll version 6 or later. (In fact, anyone who is as old as me and remembers back to Visual Basic 3 may find this familiar, since the exciting 3D control look which was provided with Windows 95 was also implemented in the same way). Note that unlike previous versions of this DLL, version 6 is not redistributable - which sadly means you can only use the visual styles on an operating system that has this version installed. At the time of writing this means XP only.
ComCtl32 does not apply the latest styles to the client area of an application by default. In order to enable it, you need to ensure that your application is linked to ComCtl32.dll (by calling the ComCtl InitCommonControls API call) and then you need to provide a Manifest which specifies that the new version of the control styles should be used.
The Windows XP Visual Styles are provided by ComCtl32.dll version 6 or later. (In fact, anyone who is as old as me and remembers back to Visual Basic 3 may find this familiar, since the exciting 3D control look which was provided with Windows 95 was also implemented in the same way). Note that unlike previous versions of this DLL, version 6 is not redistributable - which sadly means you can only use the visual styles on an operating system that has this version installed. At the time of writing this means XP only.
ComCtl32 does not apply the latest styles to the client area of an application by default. In order to enable it, you need to ensure that your application is linked to ComCtl32.dll (by calling the ComCtl InitCommonControls API call) and then you need to provide a Manifest which specifies that the new version of the control styles should be used.
To show XP styles in our VB6 products we need to do 3 steps :
1-Including a special manifest file with our project.
2-Initialize the common controls by calling the InitCommonControlsEx API (supported by comctl32.dll).
3-Protect our application from possible GPF (General Protection Fault) while closing the application.
1-The manifest file should be in the same directory (folder) of our application this file should be named as follow :
If our application name (including the extension) is Test.exe the manifest file should be Test.exe.manifest.
Contents of the 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="*"
type="win32"
/>
<description>XP Styles</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="X86"
name="*"
type="win32"
/>
<description>XP Styles</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
2-Initialize the common controls : do this once at the start of your application :
كود
'APIs declarations:
Private Type tagInitCommonControlsEx
lngSize As Long
lngICC As Long
End Type
Private Declare Function InitCommonControlsEx Lib "comctl32.dll" (iccex As tagInitCommonControlsEx) As Boolean
Private Const ICC_USEREX_CLASSES = &H200
Private Type tagInitCommonControlsEx
lngSize As Long
lngICC As Long
End Type
Private Declare Function InitCommonControlsEx Lib "comctl32.dll" (iccex As tagInitCommonControlsEx) As Boolean
Private Const ICC_USEREX_CLASSES = &H200
Now we just need to call the following function :
كود
Private Function InitCommonControlsVB() As Boolean
On Error Resume Next
Dim iccex As tagInitCommonControlsEx
With iccex
.lngSize = LenB(iccex)
.lngICC = ICC_USEREX_CLASSES
End With
InitCommonControlsEx iccex
InitCommonControlsVB = (Err.Number = 0)
On Error GoTo 0
End Function
On Error Resume Next
Dim iccex As tagInitCommonControlsEx
With iccex
.lngSize = LenB(iccex)
.lngICC = ICC_USEREX_CLASSES
End With
InitCommonControlsEx iccex
InitCommonControlsVB = (Err.Number = 0)
On Error GoTo 0
End Function
Warning : Including the manifest file without initializing the common controls will result in the following error :

3-After using the previous method to give your application XP styles it mau crash when you close it (GPF) hence we should prevent this , this can be done by calling the SetErrorMode API (supported by kernel32.dll) & set the mode to SEM_NOGPFAULTERRORBOX
كود
'APIs declarations:
Public Const SEM_NOGPFAULTERRORBOX = &H2
Public Declare Function SetErrorMode Lib "kernel32" (ByVal wMode As Long) As Long
Public Const SEM_NOGPFAULTERRORBOX = &H2
Public Declare Function SetErrorMode Lib "kernel32" (ByVal wMode As Long) As Long
then we can just call it :
كود
SetErrorMode SEM_NOGPFAULTERRORBOX
but this should be carried out just outside the IDE (Integrated Development Environment) =outside the VB design environment = as EXE
To detect if we are in the IDE or not we can use a simple method (by Steve McMahon) :
كود
'In the General part of the declarations area:
Public m_bInIDE As Boolean
Public m_bInIDE As Boolean
كود
Public Property Get InIDE() As Boolean
Debug.Assert (IsInIDE())
InIDE = m_bInIDE
End Property
Private Function IsInIDE() As Boolean
m_bInIDE = True
IsInIDE = m_bInIDE
End Function
Debug.Assert (IsInIDE())
InIDE = m_bInIDE
End Property
Private Function IsInIDE() As Boolean
m_bInIDE = True
IsInIDE = m_bInIDE
End Function
Now we can use the property InIDE to detect if we are in the IDE or not (Returns true if we are in the IDE & False if not).
So we can call the SetErrorMode as follow :
كود
If Not InIDE() Then
SetErrorMode SEM_NOGPFAULTERRORBOX
End If
SetErrorMode SEM_NOGPFAULTERRORBOX
End If
GPF snapshots :


-----------------------------------------------------------------
Standard VB Frame problems with XP styles :
The lack of hDC property for the VB frame cause 3 problems :
- It does not show XP syles even with the above code.
- It flicker with mouse movement.
- Controls on it appear in a weird manner (see the following snapshot) , this mainly occur to the Option buttons and command buttons borders but with some themes it occur to other controls

The 3rd problem can be resolved by using another container (ex.: a border-less Picture-Box)over the frame to hold (contain) the controls instead of the frame itself.
The only available way to avoid all these problems is to use another frame control , here is a free , open sourced & efficient frame :
Replacent Frame Control for XP
-----------------------------------------------------------------
Other controls that show XP styles with no effort (All by VB & All are open sourced) :
LaVolpe Buttons
dcButton ActiveX Control
McToolBar 2.3
XTab
Candy Button
vbAccelerator Toolbar and CoolMenu Control v3.5
vbAccelerator Progress Bar Control
Media Progress Bar
vbAccelerator Explorer Bar Control
vbAccelerator No Status Bar Control
vbAccelerator TabStrip Control
vbAccelerator Visual Studio Style Tab Control
vbAccelerator MDITabs Control
-----------------------------------------------------------------
For easier and faster XP styles addition I made a project that can be added to your VB projects templates
كود
<Program Files path>Microsoft Visual StudioVB98TemplateProjects
Click here to download a self extracting file contain that project
This will add 4 files :
- frmMain.frm
- MainMod.bas
- Standard EXE with XP Styles.vbp
- Standard EXE with XP Styles.vbw
Select it and you will have a project with a form (frmMain) and module (MainMod).
When you select to save your project VB will not ask you to save the module , I have no solution for this problem but you can save it manually or make any change in that module then undo it then the VB will ask you to save it with the rest of the project.




الشفرة التي وضعتها