Lorsque vous créez un complément COM pour un programme Microsoft Office (par exemple, Microsoft Visio), l'apparence de ce complément se conforme par défaut à l'apparence Office standard. Toutefois, avec Microsoft Windows XP, vous pouvez choisir parmi plusieurs styles visuels (ou thèmes) pour personnaliser l'apparence d'un programme Microsoft Windows.
À moins que les thèmes Windows ne soient activés explicitement pour un complément COM, l'apparence du complément ne change pas avec ces jeux de couleurs, le complément apparaissant alors démodé ou non synchronisé avec le programme dans lequel il est contenu. Avec les langages Microsoft Visual C++ ou Microsoft Visual Studio .NET, vous pouvez activer votre complément COM afin qu'il utilise les thèmes Windows.
Lorsque vous activez un complément pour les thèmes Windows, ces thèmes affectent uniquement l'apparence du complément. Ses fonctionnalités ne sont pas affectées.
Exclusion de responsabilité
Microsoft fournit des exemples de programmation à des fins d'illustration uniquement, sans garantie explicite ou implicite. Ceci inclut, de manière non limitative, les garanties implicites de qualité marchande ou d'adéquation à un usage particulier. Cet article suppose que vous connaissez le langage de programmation présenté et les outils utilisés pour créer et déboguer des procédures. Les techniciens du support technique Microsoft peuvent vous expliquer les fonctionnalités d'une procédure particulière, mais ils ne peuvent pas modifier les exemples en vue de vous fournir des fonctionnalités supplémentaires ou de créer des procédures répondant à vos besoins spécifiques.
Microsoft Visual Basic 6.0
Visual Basic 6.0 ne prend pas en charge les thèmes. Les compléments ne peuvent pas être associés à des thèmes en utilisant Visual Basic 6.0.
Microsoft Visual C++ 6.0
Pour utiliser Visual C++ 6.0 pour activer un complément COM afin qu'il utilise des thèmes Windows XP, procédez comme suit :
- Créez un fichier manifeste contenant les informations suivantes. Personnalisez ces informations en fonction de votre complément :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<noInherit/>
<assemblyIdentity
processorArchitecture="*"
type="win32"
name="MyOfficeNetAddin"
version="1.0.0.0"/>
<description>My Office Addin built with .Net</description>
<dependency optional="yes">
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.1.0"
publicKeyToken="6595b64144ccf1df"
language="*"
processorArchitecture="*"/>
</dependentAssembly>
</dependency>
</assembly>
- Effectuez l'une des opérations suivantes :
- Incluez les instructions de préprocesseur suivantes :
#define ISOLATION_AWARE_ENABLED
- Compilez avec :
/D ISOLATION_AWARE_ENABLED
- Ajoutez le fichier manifeste au fichier de ressource comme dans l'exemple suivant :
#include "windows.h"
ISOLATIONAWARE_MANIFEST_RESOURCE_ID RT_MANIFEST "mydllname.dl.manifest"
Microsoft Visual Studio .NET et langages gérés
Pour utiliser Visual Studio .NET et .NET Framework pour activer des thèmes Windows XP pour un complément COM, procédez comme suit.
Remarque Dans cet exemple, C# est utilisé pour activer un contexte d'activation à thème sur un formulaire Windows. En outre, pour que les thèmes Windows soient activés pour les boutons, les cases à cocher, les cases d'option et les zones de groupe, la propriété
FlatStyle de ces objets doit être définie sur
System.
- Incluez les informations suivantes dans un fichier .cs. Personnalisez ces informations en fonction de votre complément :
using System.Runtime.InteropServices;
using System;
using System.Security;
using System.Security.Permissions;
using System.Collections;
using System.IO;
using System.Text;
using System.Windows.Forms;
namespace MyOfficeNetAddin
{
/// <devdoc>
/// This class is intended to use with the C# 'using' statement in
/// to activate an activation context for turning on visual theming at
/// the beginning of a scope, and have it automatically deactivated
/// when the scope is exited.
/// </devdoc>
[ SuppressUnmanagedCodeSecurity ]
internal class EnableThemingInScope : IDisposable
{
// Private data
private uint cookie;
private static ACTCTX enableThemingActivationContext;
private static IntPtr hActCtx;
private static bool contextCreationSucceeded = false;
public EnableThemingInScope(bool enable)
{
cookie = 0;
if (enable && OSFeature.Feature.IsPresent(OSFeature.Themes))
{
if (EnsureActivateContextCreated())
{
if (!ActivateActCtx(hActCtx, out cookie))
{
// Be sure cookie always zero if activation failed
cookie = 0;
}
}
}
}
~EnableThemingInScope()
{
Dispose(false);
}
void IDisposable.Dispose()
{
Dispose(true);
}
private void Dispose(bool disposing)
{
if (cookie != 0)
{
if (DeactivateActCtx(0, cookie))
{
// deactivation succeeded...
cookie = 0;
}
}
}
private bool EnsureActivateContextCreated()
{
lock (typeof(EnableThemingInScope))
{
if (!contextCreationSucceeded)
{
// Pull manifest from the .NET Framework install
// directory
string assemblyLoc = null;
FileIOPermission fiop = new FileIOPermission(PermissionState.None);
fiop.AllFiles = FileIOPermissionAccess.PathDiscovery;
fiop.Assert();
try
{
assemblyLoc = typeof(Object).Assembly.Location;
}
finally
{
CodeAccessPermission.RevertAssert();
}
string manifestLoc = null;
string installDir = null;
if (assemblyLoc != null)
{
installDir = Path.GetDirectoryName(assemblyLoc);
const string manifestName = "XPThemes.manifest";
manifestLoc = Path.Combine(installDir, manifestName);
}
if (manifestLoc != null && installDir != null)
{
enableThemingActivationContext = new ACTCTX();
enableThemingActivationContext.cbSize = Marshal.SizeOf(typeof(ACTCTX));
enableThemingActivationContext.lpSource = manifestLoc;
// Set the lpAssemblyDirectory to the install
// directory to prevent Win32 Side by Side from
// looking for comctl32 in the application
// directory, which could cause a bogus dll to be
// placed there and open a security hole.
enableThemingActivationContext.lpAssemblyDirectory = installDir;
enableThemingActivationContext.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
// Note this will fail gracefully if file specified
// by manifestLoc doesn't exist.
hActCtx = CreateActCtx(ref enableThemingActivationContext);
contextCreationSucceeded = (hActCtx != new IntPtr(-1));
}
}
// If we return false, we'll try again on the next call into
// EnsureActivateContextCreated(), which is fine.
return contextCreationSucceeded;
}
}
// All the pinvoke goo...
[DllImport("Kernel32.dll")]
private extern static IntPtr CreateActCtx(ref ACTCTX actctx);
[DllImport("Kernel32.dll")]
private extern static bool ActivateActCtx(IntPtr hActCtx, out uint lpCookie);
[DllImport("Kernel32.dll")]
private extern static bool DeactivateActCtx(uint dwFlags, uint lpCookie);
private const int ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID = 0x004;
private struct ACTCTX
{
public int cbSize;
public uint dwFlags;
public string lpSource;
public ushort wProcessorArchitecture;
public ushort wLangId;
public string lpAssemblyDirectory;
public string lpResourceName;
public string lpApplicationName;
}
}
}
- Créez votre formulaire avec le wrapper suivant. Cette procédure transmet un contexte d'activation à thème avant de créer les contrôles :
using( new EnableThemingInScope( true ) )
{
Form1 form1 = new Form1();
form1.CreateControl();
}
Pour plus d'informations sur l'utilisation des styles visuels (ou thèmes) Windows XP, reportez-vous au site Web MSDN de Microsoft à l'adresse suivante (en anglais):
Numéro d'article: 830033 - Dernière mise à jour: lundi 12 février 2007 - Version: 5.7
Les informations contenues dans cet article s'appliquent au(x) produit(s) suivant(s):
- Microsoft Office Access 2003
- Microsoft Office Excel 2003
- Microsoft Office FrontPage 2003
- Microsoft Office Édition Professionnelle 2003
- Microsoft Office Outlook 2003
- Microsoft Office PowerPoint 2003
- Microsoft Office Project Professional 2003
- Microsoft Office Project Standard 2003
- Microsoft Office Publisher 2003
- Microsoft Office Visio Standard 2003
- Microsoft Office Visio Professional 2003
- Microsoft Office Word 2003
- Microsoft Office Standard Edition 2003
- Microsoft Office Student and Teachers Edition 2003
- Microsoft Office Édition PME 2003
- Microsoft Office Édition Basique 2003
| kbprogramming kbcode kbhowtomaster KB830033 |
L'INFORMATION CONTENUE DANS CE DOCUMENT EST FOURNIE PAR MICROSOFT SANS GARANTIE D'AUCUNE SORTE, EXPLICITE OU IMPLICITE. L'UTILISATEUR ASSUME LE RISQUE DE L'UTILISATION DU CONTENU DE CE DOCUMENT. CE DOCUMENT NE PEUT ETRE REVENDU OU CEDE EN ECHANGE D'UN QUELCONQUE PROFIT.