/** * @file XTPWinThemeWrapper.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ /** @cond */ #if !defined(__XTPWINTHEMEWRAPPER_H__) # define __XTPWINTHEMEWRAPPER_H__ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # define XTP_INTERNAL_UXTHEME_INCLUSION # include "Uxtheme.h" # include "SchemaDef.h" # include "Tmschema.h" # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" BEGIN_TM_CLASS_PARTS(XTP_MENU) TM_PART(1, XTP_MP, MENUITEM) TM_PART(2, XTP_MP, MENUDROPDOWN) TM_PART(3, XTP_MP, MENUBARITEM) TM_PART(4, XTP_MP, MENUBARDROPDOWN) TM_PART(5, XTP_MP, CHEVRON) TM_PART(6, XTP_MP, SEPARATOR) TM_PART(7, XTP_MP, BARBACKGROUND) TM_PART(8, XTP_MP, BARITEM) TM_PART(9, XTP_MP, POPUPBACKGROUND) TM_PART(10, XTP_MP, POPUPBORDERS) TM_PART(11, XTP_MP, POPUPCHECK) TM_PART(12, XTP_MP, POPUPCHECKBACKGROUND) TM_PART(13, XTP_MP, POPUPGUTTER) TM_PART(14, XTP_MP, POPUPITEM) TM_PART(15, XTP_MP, POPUPSEPARATOR) TM_PART(16, XTP_MP, POPUPSUBMENU) TM_PART(17, XTP_MP, SYSTEMCLOSE) TM_PART(18, XTP_MP, SYSTEMMAXIMIZE) TM_PART(19, XTP_MP, SYSTEMMINIMIZE) TM_PART(20, XTP_MP, SYSTEMRESTORE) END_TM_CLASS_PARTS() typedef HANDLE HPAINTBUFFER; // BP_BUFFERFORMAT enum XTP_UX_BUFFERFORMAT { XTP_BPBF_COMPATIBLEBITMAP, // Compatible bitmap XTP_BPBF_DIB, // Device-independent bitmap XTP_BPBF_TOPDOWNDIB, // Top-down device-independent bitmap XTP_BPBF_TOPDOWNMONODIB // Top-down monochrome device-independent bitmap }; // BP_PAINTPARAMS struct XTP_UX_PAINTPARAMS { DWORD cbSize; DWORD dwFlags; // BPPF_ flags const RECT* prcExclude; const BLENDFUNCTION* pBlendFunction; }; struct XTP_UX_DTTOPTS { DWORD dwSize; // size of the struct DWORD dwFlags; // which options have been specified COLORREF crText; // color to use for text fill COLORREF crBorder; // color to use for text outline COLORREF crShadow; // color to use for text shadow int iTextShadowType; // TST_SINGLE or TST_CONTINUOUS POINT ptShadowOffset; // where shadow is drawn (relative to text) int iBorderSize; // Border radius around text int iFontPropId; // Font property to use for the text instead of TMT_FONT int iColorPropId; // Color property to use for the text instead of TMT_TEXTCOLOR int iStateId; // Alternate state id BOOL fApplyOverlay; // Overlay text on top of any text effect? int iGlowSize; // Glow radius around text VOID* pfnDrawTextCallback; // Callback for DrawText LPARAM lParam; // Parameter for callback }; struct _DTBGOPTS; typedef _DTBGOPTS* PDTBGOPTS; # define TYPEDEF_WRAPPER_POINTER(val, type, proc) \ const int xtpWrapper##proc = val; \ const LPCSTR xtpWrapperProc##proc = #proc; \ typedef type(__stdcall* PFN##proc) TYPEDEF_WRAPPER_POINTER(0, HRESULT, DrawThemeBackground) (HTHEME, HDC, int, int, const RECT*, const RECT*); TYPEDEF_WRAPPER_POINTER(1, HRESULT, CloseThemeData)(HTHEME); TYPEDEF_WRAPPER_POINTER(2, HRESULT, SetWindowTheme)(HWND, LPCWSTR, LPCWSTR); TYPEDEF_WRAPPER_POINTER(3, void, SetThemeAppProperties)(DWORD); TYPEDEF_WRAPPER_POINTER(4, HTHEME, OpenThemeData)(HWND, LPCWSTR); TYPEDEF_WRAPPER_POINTER(5, BOOL, IsThemePartDefined)(HTHEME, int, int); TYPEDEF_WRAPPER_POINTER(6, BOOL, IsThemeDialogTextureEnabled)(HWND hWnd); TYPEDEF_WRAPPER_POINTER(7, BOOL, IsThemeBackgroundPartiallyTransparent)(HTHEME, int, int); TYPEDEF_WRAPPER_POINTER(8, BOOL, IsThemeActive)(); TYPEDEF_WRAPPER_POINTER(9, BOOL, IsAppThemed)(); TYPEDEF_WRAPPER_POINTER(10, HRESULT, HitTestThemeBackground) (HTHEME, HDC, int, int, DWORD, const RECT*, HRGN, POINT, WORD*); TYPEDEF_WRAPPER_POINTER(11, HTHEME, GetWindowTheme)(HWND); TYPEDEF_WRAPPER_POINTER(12, HRESULT, GetThemeSysString)(HTHEME, int, LPWSTR, int); TYPEDEF_WRAPPER_POINTER(13, HRESULT, GetThemeTextMetrics)(HTHEME, HDC, int, int, TEXTMETRIC*); TYPEDEF_WRAPPER_POINTER(14, HRESULT, GetThemeTextExtent) (HTHEME, HDC, int, int, LPCWSTR, int, DWORD, const RECT*, RECT*); TYPEDEF_WRAPPER_POINTER(15, int, GetThemeSysSize)(HTHEME, int); TYPEDEF_WRAPPER_POINTER(16, HRESULT, GetThemeSysInt)(HTHEME, int, int*); TYPEDEF_WRAPPER_POINTER(17, HRESULT, GetThemeSysFont)(HTHEME, int, LOGFONT*); TYPEDEF_WRAPPER_POINTER(18, HBRUSH, GetThemeSysColorBrush)(HTHEME, int); TYPEDEF_WRAPPER_POINTER(19, COLORREF, GetThemeSysColor)(HTHEME, int); TYPEDEF_WRAPPER_POINTER(20, BOOL, GetThemeSysBool)(HTHEME, int); TYPEDEF_WRAPPER_POINTER(21, HRESULT, GetThemeString)(HTHEME, int, int, int, LPWSTR, int); TYPEDEF_WRAPPER_POINTER(22, HRESULT, GetThemeRect)(HTHEME, int, int, int, RECT*); TYPEDEF_WRAPPER_POINTER(23, HRESULT, GetThemePropertyOrigin) (HTHEME, int, int, int, PROPERTYORIGIN*); TYPEDEF_WRAPPER_POINTER(24, HRESULT, GetThemePosition)(HTHEME, int, int, int, POINT*); TYPEDEF_WRAPPER_POINTER(25, HRESULT, GetThemePartSize) (HTHEME, HDC, int, int, RECT*, THEMESIZE, SIZE*); TYPEDEF_WRAPPER_POINTER(26, HRESULT, GetThemeMetric)(HTHEME, HDC, int, int, int, int*); TYPEDEF_WRAPPER_POINTER(27, HRESULT, GetThemeMargins)(HTHEME, HDC, int, int, int, RECT*, MARGINS*); TYPEDEF_WRAPPER_POINTER(28, HRESULT, GetThemeIntList)(HTHEME, int, int, int, INTLIST*); TYPEDEF_WRAPPER_POINTER(29, HRESULT, GetThemeInt)(HTHEME, int, int, int, int*); TYPEDEF_WRAPPER_POINTER(30, HRESULT, GetThemeFont)(HTHEME, HDC, int, int, int, LOGFONTW*); TYPEDEF_WRAPPER_POINTER(31, HRESULT, GetThemeFilename)(HTHEME, int, int, int, LPWSTR, int); TYPEDEF_WRAPPER_POINTER(32, HRESULT, GetThemeEnumValue)(HTHEME, int, int, int, int*); TYPEDEF_WRAPPER_POINTER(33, HRESULT, GetThemeDocumentationProperty)(LPCWSTR, LPCWSTR, LPWSTR, int); TYPEDEF_WRAPPER_POINTER(34, HRESULT, GetThemeColor)(HTHEME, int, int, int, COLORREF*); TYPEDEF_WRAPPER_POINTER(35, HRESULT, GetThemeBool)(HTHEME, int, int, int, BOOL*); TYPEDEF_WRAPPER_POINTER(36, HRESULT, GetThemeBackgroundRegion) (HTHEME, HDC, int, int, const RECT*, HRGN*); TYPEDEF_WRAPPER_POINTER(37, HRESULT, GetThemeBackgroundExtent) (HTHEME, HDC, int, int, const RECT*, RECT*); TYPEDEF_WRAPPER_POINTER(38, HRESULT, GetThemeBackgroundContentRect) (HTHEME, HDC, int, int, const RECT*, RECT*); TYPEDEF_WRAPPER_POINTER(39, DWORD, ThemeAppProperties)(); TYPEDEF_WRAPPER_POINTER(40, HRESULT, GetCurrentThemeName)(LPWSTR, int, LPWSTR, int, LPWSTR, int); TYPEDEF_WRAPPER_POINTER(41, HRESULT, EnableTheming)(BOOL); TYPEDEF_WRAPPER_POINTER(42, HRESULT, EnableThemeDialogTexture)(HWND, DWORD); TYPEDEF_WRAPPER_POINTER(43, HRESULT, DrawThemeText) (HTHEME, HDC, int, int, LPCWSTR, int, DWORD, DWORD, const RECT*); TYPEDEF_WRAPPER_POINTER(44, HRESULT, DrawThemeParentBackground)(HWND, HDC, RECT*); TYPEDEF_WRAPPER_POINTER(45, HRESULT, DrawThemeIcon) (HTHEME, HDC, int, int, const RECT*, HIMAGELIST, int); TYPEDEF_WRAPPER_POINTER(46, HRESULT, DrawThemeEdge) (HTHEME, HDC, int, int, const RECT*, UINT, UINT, RECT*); TYPEDEF_WRAPPER_POINTER(47, HRESULT, DrawThemeBackgroundEx) (HTHEME, HDC, int, int, const RECT*, const PDTBGOPTS); TYPEDEF_WRAPPER_POINTER(48, DWORD, GetThemeAppProperties)(); TYPEDEF_WRAPPER_POINTER(49, HPAINTBUFFER, BeginBufferedPaint) (HDC, const RECT*, XTP_UX_BUFFERFORMAT, XTP_UX_PAINTPARAMS*, HDC*); TYPEDEF_WRAPPER_POINTER(50, HRESULT, EndBufferedPaint)(HPAINTBUFFER, BOOL); TYPEDEF_WRAPPER_POINTER(51, HRESULT, DrawThemeTextEx) (HTHEME, HDC, int, int, LPCWSTR, int, DWORD, LPRECT, const XTP_UX_DTTOPTS*); TYPEDEF_WRAPPER_POINTER(52, HRESULT, BufferedPaintSetAlpha)(HPAINTBUFFER, const RECT*, BYTE); # define XTP_UXTHEME_HANDLE (HMODULE)0x21FFFF1 /** @endcond */ /** * @brief * The CXTPWinThemeWrapper class wraps the UxTheme.dll visual theme * API. You can use this class for rendering Windows XP themes for * owner drawn controls. */ class _XTP_EXT_CLASS CXTPWinThemeWrapper { private: /** * @brief * Shared data of wrappers */ class CSharedData { public: /** * @brief * Constructs a CSharedData object. */ CSharedData(); public: LPVOID m_ptrWrappers[53]; /**< Wrapper pointer */ HMODULE m_hThemeDll; /**< Handle to the theme dll. */ DWORD m_dwComCtlVersion; /**< ComCtl version. */ }; public: /** * @brief * Constructs a CXTPWinThemeWrapper object. * @param bUseSkinFramework TRUE to use skinframework. */ CXTPWinThemeWrapper(BOOL bUseSkinFramework = TRUE); /** * @brief * Destroys a CXTPWinThemeWrapper object, handles cleanup and * deallocation. */ virtual ~CXTPWinThemeWrapper(); /** * @brief * Open the theme data for the specified HWND and semi-colon * separated list of class names. OpenThemeData() will try * each class name, one at a time, and use the first matching * theme info found. * @param hWnd Window handle of the control/window to be * themed. * @param pszClassList Class name (or list of names) to match to * theme data section. if the list contains * more than one name, the names are tested one * at a time for a match. If a match is found, * OpenThemeData() returns a theme handle * associated with the matching class. This * param is a list (instead of just a single * class name) to provide the class an * opportunity to get the "best" match between * the class and the current theme. For example, * a button might pass L"OkButton;Button" if its * ID=ID_OK. If the current theme has an entry * for OkButton, that will be used. Otherwise, * we fall back on the normal Button entry. */ void OpenThemeData(HWND hWnd, LPCWSTR pszClassList); /** * @brief * Closes the theme data handle. CXTPWinThemeWrapper will do * this automatically when destroyed or when OpenThemeData is * called. Your window should handle the WM_THEMECHANGED * message when called followed by a call to OpenThemeData. */ void CloseThemeData(); /** * @brief * Draws the theme-specified border and fill for the "iPartId" * and "iStateId". This could be based on a bitmap file, a * border and fill, or other image description. * @param hDC HDC to draw into * @param iPartID Part number to draw * @param iStateID State number (of the part) to draw * @param pRect Defines the size/location of the part * @param pClipRect Optional clipping rect (don't draw outside it) * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT DrawThemeBackground(HDC hDC, int iPartID, int iStateID, const RECT* pRect, const RECT* pClipRect); /** * @brief * Draws the text using the theme-specified color and font for * the "iPartID" and "iStateID". * @param hDC HDC to draw into * @param iPartID Part number to draw * @param iStateID State number (of the part) to draw * @param pszText Actual text to draw * @param iCharCount Number of chars to draw (-1 for all) * @param dwTextFlags Same as DrawText() "uFormat" param * @param dwTextFlags2 Additional drawing options * @param pRect Defines the size/location of the part * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT DrawThemeText(HDC hDC, int iPartID, int iStateID, LPCWSTR pszText, int iCharCount, DWORD dwTextFlags, DWORD dwTextFlags2, const RECT* pRect); /** * @brief * Gets the size of the content for the theme-defined * background. This is usually the area inside the borders or * Margins. * @param hDC (optional) device content to be used for * drawing * @param iPartID Part number to draw * @param iStateID State number (of the part) to draw * @param pBoundingRect The outer RECT of the part being drawn * @param pContentRect RECT to receive the content area * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemeBackgroundContentRect(HDC hDC, int iPartID, int iStateID, const RECT* pBoundingRect, RECT* pContentRect); /** * @brief * Calculates the size/location of the theme-specified * background based on the "pContentRect". * @param hDC (optional) device content to be used for * drawing * @param iPartID Part number to draw * @param iStateID State number (of the part) to draw * @param pContentRect RECT that defines the content area * @param pExtentRect RECT to receive the overall size/location of * part * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemeBackgroundExtent(HDC hDC, int iPartID, int iStateID, const RECT* pContentRect, RECT* pExtentRect); /** * @brief * Draws the theme-specified border and fill for the "iPartId" * and "iStateId". This could be based on a bitmap file, a * border and fill, or other image description. * @param hDC HDC to draw into * @param iPartID Part number to draw * @param iStateID State number (of the part) to draw * @param pRect Defines the size/location of the part * @param pOptions Pointer to optional parameters. * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT DrawThemeBackgroundEx(HDC hDC, int iPartID, int iStateID, const RECT* pRect, const PDTBGOPTS pOptions); /** * @brief * Similar to the DrawEdge() API, but uses part colors and is * high-DPI aware * @param hDC HDC to draw into * @param iPartID Part number to draw. * @param iStateID State number of part * @param pDestRect The RECT used to draw the line(s) * @param uEdge Same as DrawEdge() API * @param uFlags Same as DrawEdge() API * @param pContentRect Receives the interior rect if (uFlags & * BF_ADJUST) * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT DrawThemeEdge(HDC hDC, int iPartID, int iStateID, const RECT* pDestRect, UINT uEdge, UINT uFlags, RECT* pContentRect); /** * @brief * Draws an image within an imagelist based on a (possible) * theme-defined effect. * @param hDC HDC to draw into * @param iPartID Part number to draw. * @param iStateID State number of part * @param pRect The RECT to draw the image within * @param himl Handle to IMAGELIST * @param iImageIndex Index into IMAGELIST (which icon to draw) * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT DrawThemeIcon(HDC hDC, int iPartID, int iStateID, const RECT* pRect, HIMAGELIST himl, int iImageIndex); /** * @brief * Used by partially-transparent or alpha-blended child controls * to draw the part of their parent that they appear in front of. * @param hWnd Handle of the child control * @param hDC HDC of the child control * @param pRect (optional) rect that defines the area to be * Drawn (CHILD coordinates) * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT DrawThemeParentBackground(HWND hWnd, HDC hDC, RECT* pRect); /** * @brief * Enables/disables dialog background theme. This method can be * used to tailor dialog compatibility with child windows and * controls that may or may not coordinate the rendering of * their client area backgrounds with that of their parent * dialog in a manner that supports seamless background * texturing. * @param hWnd The window handle of the target dialog * @param dwFlags ETDT_ENABLE to enable the theme-defined dialog * background texturing, * ETDT_DISABLE to disable background texturing, * ETDT_ENABLETAB to enable the theme-defined * background texturing using the Tab texture * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT EnableThemeDialogTexture(HWND hWnd, DWORD dwFlags); /** * @brief * Enables or disables theming for the current user in the * current and future sessions. * @param bEnable If FALSE, disable theming & turn themes off. * if TRUE, enable theming and, if user * previously had a theme active, make it active * now. * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT EnableTheming(BOOL bEnable); /** * @brief * Get the name of the current theme in-use. Optionally, return * the ColorScheme name and the Size name of the theme. * @param pszThemeFileName Receives the theme path & filename * @param dwMaxNameChars Max chars allowed in pszNameBuff * @param pszColorBuff (optional) receives the canonical color * scheme name * (not the display name) * @param cchMaxColorChars Max chars allowed in pszColorBuff * @param pszSizeBuff (optional) receives the canonical size * name (not the display name) * @param cchMaxSizeChars Max chars allowed in pszSizeBuff * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetCurrentThemeName(LPWSTR pszThemeFileName, int dwMaxNameChars, LPWSTR pszColorBuff, int cchMaxColorChars, LPWSTR pszSizeBuff, int cchMaxSizeChars); /** * @brief * Retrieves the property flags that control how visual styles * are applied in the current application. * @return * The following return values are bit flags combined with a * logical OR operator. * STAP_ALLOW_NONCLIENT - Specifies that the non-client areas of * application windows have visual * styles applied. * STAP_ALLOW_CONTROLS - Specifies that controls in * application windows have visual * styles applied. * STAP_ALLOW_WEBCONTENT - Specifies that all web content * displayed in an application is * rendered using visual styles. */ DWORD ThemeAppProperties(); /** * @brief * Computes the region for a regular or partially transparent * theme-specified background that is bound by the specified * "pRect". If the rectangle is empty, sets the hRgn to NULL * and return S_FALSE. * @param hDC Optional hDC to draw into (DPI scaling) * @param iPartID Part number to draw. * @param iStateID State number (of the part) * @param pRect The RECT used to draw the part * @param pRegion Receives handle to calculated region * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemeBackgroundRegion(HDC hDC, int iPartID, int iStateID, const RECT* pRect, HRGN* pRegion); /** * @brief * Get the value for the specified BOOL property * @param iPartID Part number * @param iStateID State number of part * @param iPropID The property number to get the value for * @param pfVal Receives the value of the property * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemeBool(int iPartID, int iStateID, int iPropID, BOOL* pfVal); /** * @brief * Get the value for the specified COLOR property * @param iPartID Part number * @param iStateID State number of part * @param iPropID The property number to get the value for * @param pColor Receives the value of the property * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemeColor(int iPartID, int iStateID, int iPropID, COLORREF* pColor); /** * @brief * Get the value for the specified property name from the * [documentation] section of the themes.ini file for the * specified theme. If the property has been localized in the * theme files string table, the localized version of the * property value is returned. * @param pszThemeName Filename of the theme file to query * @param pszPropertyName Name of the string property to retrieve a * value for * @param pszValueBuff Receives the property string value * @param cchMaxValChars Max chars allowed in pszValueBuff * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemeDocumentationProperty(LPCWSTR pszThemeName, LPCWSTR pszPropertyName, LPWSTR pszValueBuff, int cchMaxValChars); /** * @brief * Get the value for the specified ENUM property * @param iPartID Part number * @param iStateID State number of part * @param iPropID The property number to get the value for * @param piVal Receives the value of the enum (cast to int*) * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemeEnumValue(int iPartID, int iStateID, int iPropID, int* piVal); /** * @brief * Get the value for the specified FILENAME property. * @param iPartID Part number * @param iStateID State number of part * @param iPropID The property number to search for * @param pszThemeFilename Output buffer to receive the filename * @param cchMaxBuffChars The size of the return buffer, in chars * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemeFilename(int iPartID, int iStateID, int iPropID, LPWSTR pszThemeFilename, int cchMaxBuffChars); /** * @brief * Get the value for the specified font property * @param hDC (optional) hDC to be drawn to (DPI scaling) * @param iPartID Part number * @param iStateID State number of part * @param iPropID The property number to get the value for * @param pFont Receives the value of the LOGFONT property * (scaled for the current logical screen dpi) * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemeFont(HDC hDC, int iPartID, int iStateID, int iPropID, LOGFONTW* pFont); /** * @brief * Get the value for the specified int property * @param iPartID Part number * @param iStateID State number of part * @param iPropID The property number to get the value for * @param piVal Receives the value of the property * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemeInt(int iPartID, int iStateID, int iPropID, int* piVal); /** * @brief * Get the value for the specified INTLIST struct * @param iPartID Part number * @param iStateID State number of part * @param iPropID The property number to get the value for * @param pIntList Receives the value of the INTLIST property * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemeIntList(int iPartID, int iStateID, int iPropID, INTLIST* pIntList); /** * @brief * Get the value for the specified MARGINS property * @param hDC (optional) hDC to be used for drawing * @param iPartID Part number * @param iStateID State number of part * @param iPropID The property number to get the value for * @param pRect RECT for area to be drawn into * @param pMargins Receives the value of the MARGINS property * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemeMargins(HDC hDC, int iPartID, int iStateID, int iPropID, RECT* pRect, MARGINS* pMargins); /** * @brief * Get the value for the specified metric/size property * @param hDC (optional) hDC to be drawn into (DPI scaling) * @param iPartID Part number * @param iStateID State number of part * @param iPropID The property number to get the value for * @param piVal Receives the value of the property * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemeMetric(HDC hDC, int iPartID, int iStateID, int iPropID, int* piVal); /** * @brief * Returns the specified size of the theme part * @param hDC HDC to select font into & measure against * @param iPartID Part number to retrieve size for * @param iStateID State number (of the part) * @param pRect (optional) rect for part drawing destination * @param eSize The type of size to be retrieved * @param pSize Receives the specified size of the part * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemePartSize(HDC hDC, int iPartID, int iStateID, RECT* pRect, THEMESIZE eSize, SIZE* pSize); /** * @brief * Get the value for the specified position property * @param iPartID Part number * @param iStateID State number of part * @param iPropID The property number to get the value for * @param pPoint Receives the value of the position property * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemePosition(int iPartID, int iStateID, int iPropID, POINT* pPoint); /** * @brief * Searches for the specified theme property and sets "pOrigin" * to indicate where it was found (or not found) * @param iPartID Part number * @param iStateID State number of part * @param iPropID The property number to search for * @param pOrigin Receives the value of the property origin * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemePropertyOrigin(int iPartID, int iStateID, int iPropID, PROPERTYORIGIN* pOrigin); /** * @brief * Get the value for the specified RECT property * @param iPartID Part number * @param iStateID State number of part * @param iPropID The property number to get the value for * @param pRect Receives the value of the RECT property * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemeRect(int iPartID, int iStateID, int iPropID, RECT* pRect); /** * @brief * Get the value for the specified string property * @param iPartID Part number * @param iStateID State number of part * @param iPropID The property number to get the value for * @param pszBuff Receives the string property value * @param cchMaxBuffChars Max. number of chars allowed in pszBuff * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemeString(int iPartID, int iStateID, int iPropID, LPWSTR pszBuff, int cchMaxBuffChars); /** * @brief * Get the boolean value of specified System metric. * @param iBoolID The TMT_XXX BOOL number (first BOOL is * TMT_FLATMENUS) * @return * Returns S_OK if successful, or an error value otherwise. */ BOOL GetThemeSysBool(int iBoolID); /** * @brief * Get the value of the specified System color. * @param iColorID The system color index defined in winuser.h * @return * The value of the specified system color. */ COLORREF GetThemeSysColor(int iColorID); /** * @brief * Get the brush for the specified System color. * @param iColorID The system color index defined in winuser.h * @return * Handle to brush data. */ HBRUSH GetThemeSysColorBrush(int iColorID); /** * @brief * Get the LOGFONT for the specified System font. * @param iFontID The TMT_XXX font number (first font * is TMT_CAPTIONFONT) * @param pLF Ptr to LOGFONT to receive the font value. * (scaled for the current logical screen dpi) * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemeSysFont(int iFontID, LOGFONT* pLF); /** * @brief * Get the value of specified System int. * @param iIntID Must be one of the following values: * TMT_DPIX * TMT_DPIY * TMT_MINCOLORDEPTH * @param piValue Ptr to int to receive value * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemeSysInt(int iIntID, int* piValue); /** * @brief * Get the value of the specified System size metric. (scaled * for the current logical screen dpi) * @param iSizeID The following values are supported: * SM_CXBORDER (border width) * SM_CXVSCROLL (scrollbar width) * SM_CYHSCROLL (scrollbar height) * SM_CXSIZE (caption width) * SM_CYSIZE (caption height) * SM_CXSMSIZE (small caption width) * SM_CYSMSIZE (small caption height) * SM_CXMENUSIZE (menubar width) * SM_CYMENUSIZE (menubar height) * @return * Returns S_OK if successful, or an error value otherwise. */ int GetThemeSysSize(int iSizeID); /** * @brief * Get the value of specified System string metric. * @param iStringID Must be one of the following values: * TMT_CSSNAME * TMT_XMLNAME * @param pszStringBuff The buffer to receive the string value * @param cchMaxStringChars Max. number of chars that pszStringBuff * can hold * @return * The size in dots per inch (DPI) scaled for the current * logical screen. */ HRESULT GetThemeSysString(int iStringID, LPWSTR pszStringBuff, int cchMaxStringChars); /** * @brief * Calculates the size/location of the specified text when * rendered in the Theme Font. * @param hDC HDC to select font & measure into * @param iPartID Part number to draw. * @param iStateID State number (of the part) * @param pszText The text to be measured * @param iCharCount Number of chars to draw (-1 for all) * @param dwTextFlags Same as DrawText() "uFormat" param * @param pBoundingRect Optional: to control layout of text * @param pExtentRect Receives the RECT for text size/location * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemeTextExtent(HDC hDC, int iPartID, int iStateID, LPCWSTR pszText, int iCharCount, DWORD dwTextFlags, const RECT* pBoundingRect, RECT* pExtentRect); /** * @brief * Returns info about the theme-specified font for the part/ * state passed in. * @param hDC Optional: hDC for screen context * @param iPartID Part number to draw. * @param iStateID State number (of the part) * @param ptm Receives the font info * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT GetThemeTextMetrics(HDC hDC, int iPartID, int iStateID, TEXTMETRIC* ptm); /** * @brief * If window is themed, returns its most recent HTHEME from * OpenThemeData() - Otherwise, returns NULL. * @param hWnd The window to get the HTHEME of * @return * The most recent theme handle from OpenThemeData. */ HTHEME GetWindowTheme(HWND hWnd); /** * @brief * Returns a HitTestCode (a subset of the values returned by * WM_NCHITTEST) for the point "ptTest" within the theme- * specified background (bound by pRect). "pRect" and "ptTest" * should both be in the same coordinate system (client, screen, * etc). * @param hDC HDC to draw into * @param iPartID Part number to test against * @param iStateID State number (of the part) * @param pRect The RECT used to draw the part * @param hRgn Optional region to use; must be in same * coordinates as * pRect and pTest. * @param ptTest The hit point to be tested * @param dwOptions HTTB_xxx constants * @param pwHitTestCode Receives the returned hit test code One of: * HTNOWHERE, HTLEFT, HTTOPLEFT, HTBOTTOMLEFT, * HTRIGHT, HTTOPRIGHT, HTBOTTOMRIGHT, * HTTOP, HTBOTTOM, HTCLIENT * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT HitTestThemeBackground(HDC hDC, int iPartID, int iStateID, DWORD dwOptions, const RECT* pRect, HRGN hRgn, POINT ptTest, WORD* pwHitTestCode); /** * @brief * Reports whether the current application's user interface * displays using visual styles. * @return * Returns one of the following values. * TRUE - The application has a visual style applied. * FALSE - The application does not have a visual style applied. */ BOOL IsAppThemed() const; /** * @brief * Can be used to test if a system theme is active for the * current user session. * use the API "IsAppThemed()" to test if a theme is active for * the calling process. * @return * Returns one of the following values: * TRUE - A visual style is enabled, and windows with visual * styles applied should call OpenThemeData to start * using theme drawing services. * FALSE - A visual style is not enabled, and the window message * handler does not need to make another call to * IsThemeActive until it receives a WM_THEMECHANGED * message. */ BOOL IsThemeActive() const; /** * @brief * Call this member function to determine if the application should * display Windows XP themes. IsAppThemeReady() will first check * to see if the operating system supports Windows XP theme display, * then checks to see if the application has any controls that are * able to display Windows XP themes, then finally checks to see if * the application has included a manifest file. * @return * TRUE if the application can display Windows XP themes, otherwise FALSE. */ BOOL IsAppThemeReady() const; /** * @brief * Checks whether the current application's user interface * displays using visual styles and the theme is opened and * ready for for being used. * @return * Returns one of the following values. * TRUE - The application has a visual style applied and the theme is opened. * FALSE - The application does not have a visual style applied or * the theme is not opened. */ BOOL IsAppThemeActive() const; /** * @brief * Returns TRUE if the theme specified background for the part/ * state has transparent pieces or alpha-blended pieces. * @param iPartID Part number * @param iStateID State number of part * @return * Returns one of the following values. * * TRUE * The theme-specified background for a particular * iPartId and iStateId has transparent pieces or alpha- * blended pieces. * * FALSE * The theme-specified background for a particular * iPartId and iStateId does not have transparent pieces * or alpha-blended pieces. */ BOOL IsThemeBackgroundPartiallyTransparent(int iPartID, int iStateID); /** * @brief * Reports whether the dialog supports background texturing. * @param hWnd A handle of a window to check. * @return * Returns one of the following values. * * TRUE * Background texturing is supported. * * FALSE * Background texturing is not supported. */ BOOL IsThemeDialogTextureEnabled(HWND hWnd); /** * @brief * Returns TRUE if the theme has defined parameters for the * specified "iPartID" and "iStateID". * @param iPartID Part number to find definition for * @param iStateID State number of part * @return * Returns one of the following values. * * TRUE * The theme has defined parameters for the specified * iPartId and iStateId * * FALSE * The theme does not have defined parameters for the * specified iPartId and iStateId */ BOOL IsThemePartDefined(int iPartID, int iStateID); /** * @brief * Sets the flags that control theming within the app * @param dwFlags The flag values to be set */ void SetThemeAppProperties(DWORD dwFlags); /** * @brief * Redirects an existing Window to use a different section of * the current theme information than its class normally asks * for. * @param hWnd The handle of the window (cannot be NULL) * @param pszSubAppName App (group) name to use in place of the * calling app's name. If NULL, the actual * calling app name will be used. * @param pszSubIdList Semicolon separated list of class Id names to * use in place of actual list passed by the * window's class. if NULL, the id list from * the calling class is used. * @details The Theme Manager will remember the "pszSubAppName" and the * "pszSubIdList" associations thru the lifetime of the window * (even if themes are subsequently changed). The window is * sent a "WM_THEMECHANGED" msg at the end of this call, so that * the new theme can be found and applied. * When "pszSubAppName" or "pszSubIdList" are NULL, the Theme * Manager removes the previously remember association. To turn * off theme-ing for the specified window, you can pass an empty * string (L"") so it won't match any section entries. * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT SetWindowTheme(HWND hWnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList); /** * @brief * Call this member function to determine if OpenThemeData() was * called to open theme information for a particular window. * @return * TRUE if theme information was loaded, otherwise FALSE. */ BOOL ThemeDataOpen() const; /** * @return * Retrieves the property flags that control how visual styles are applied in the current * application. */ DWORD GetThemeAppProperties(); /** @cond */ static BOOL m_bDllDetached; // for compatibility with older versions. void CloseTheme() { CloseThemeData(); } void OpenTheme(HWND hWnd, LPCWSTR pszClassList) { OpenThemeData(hWnd, pszClassList); } void DrawBackground(HDC hdc, int iPartId, int iStateId, const RECT* pRect, const RECT* pClipRect) { DrawThemeBackground(hdc, iPartId, iStateId, pRect, pClipRect); } /** @endcond */ /** * @brief * Sets the alpha to a specified value in a given rectangle. * The alpha controls the amount of transparency applied when blending * with the buffer onto the destination target device context (DC). * @param alpha Alpha channel value. * @param prc Target rectangle pointer. * @param hBufferedPaint Paint buffer handle. * @return S_OK if successful or an error code otherwise. */ HRESULT BufferedPaintSetAlpha(HPAINTBUFFER hBufferedPaint, const RECT* prc, BYTE alpha); /** * @brief * Begins a buffered paint operation * @param hdcTarget Handle of the target device context (DC) on which * the buffer will be painted. * @param prcTarget Pointer to a RECT structure that specifies the area * of the target DC in which to paint. * @param dwFormat A member of the BP_BUFFERFORMAT enumeration that * specifies the format of the buffer. * @param pPaintParams [in] Pointer to a BP_PAINTPARAMS structure that * defines the paint operation parameters. This value * can be NULL. * @param phdc [out] When this function returns, this value points * to the handle of the new device context. * @return * A handle to the buffered paint context * @see * EndBufferedPaint */ HPAINTBUFFER BeginBufferedPaint(HDC hdcTarget, const RECT* prcTarget, XTP_UX_BUFFERFORMAT dwFormat, XTP_UX_PAINTPARAMS* pPaintParams, HDC* phdc); /** * @brief * Completes a buffered paint operation and frees the associated buffered paint handle * @param hBufferedPaint Handle of the buffered paint context, obtained through * BeginBufferedPaint * @param fUpdateTarget TRUE to copy the buffer to the target device context * (DC) * @see * BeginBufferedPaint */ void EndBufferedPaint(HPAINTBUFFER hBufferedPaint, BOOL fUpdateTarget); /** * @brief * Draws the text using the theme-specified color and font for * the "iPartID" and "iStateID". * @param hdc HDC to draw into * @param iPartId Part number to draw * @param iStateId State number (of the part) to draw * @param pszText Actual text to draw * @param cchText Number of chars to draw (-1 for all) * @param dwTextFlags Same as DrawText() "uFormat" param * @param pRect Defines the size/location of the part * @param pOptions Additional drawing options * @return * Returns S_OK if successful, or an error value otherwise. */ HRESULT DrawThemeTextEx(HDC hdc, int iPartId, int iStateId, LPCWSTR pszText, int cchText, DWORD dwTextFlags, LPRECT pRect, const XTP_UX_DTTOPTS* pOptions); /** * @brief * This method is used to set user-defined wrappers. * @param nThemeWrapper Wrapper ID. * @param lpWrapperPtr Wrapper pointer. */ void SetThemeWrapperPtr(int nThemeWrapper, LPVOID lpWrapperPtr); void CreateSharedData(); private: void ReloadLibrary() const; private: HTHEME m_hTheme; /**< Handle to the theme data. */ BOOL m_bUseSkinFramework; CSharedData* m_pSharedData; CSharedData& GetSharedData() const; }; /** @cond */ struct XTP_DWM_MARGINS { int cxLeftWidth; /**< width of left border that retains its size */ int cxRightWidth; /**< width of right border that retains its size */ int cyTopHeight; /**< height of top border that retains its size */ int cyBottomHeight; /**< height of bottom border that retains its size */ }; TYPEDEF_WRAPPER_POINTER(0, HRESULT, DwmDefWindowProc) (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT* plResult); TYPEDEF_WRAPPER_POINTER(1, HRESULT, DwmIsCompositionEnabled)(BOOL*); TYPEDEF_WRAPPER_POINTER(2, HRESULT, DwmExtendFrameIntoClientArea)(HWND, const XTP_DWM_MARGINS*); /** * @brief * The CXTPWinDwmWrapper class wraps the dwp api. */ class _XTP_EXT_CLASS CXTPWinDwmWrapper { private: /** * @brief * Shared data of wrappers */ class CSharedData { public: /** * @brief * Constructs a CSharedData object. */ CSharedData(); public: LPVOID m_ptrWrappers[3]; /**< Wrapper pointer */ HMODULE m_hDwmDll; /**< Handle to the theme dll. */ }; public: CXTPWinDwmWrapper(); ~CXTPWinDwmWrapper(); public: HRESULT DefWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT* plResult); BOOL IsCompositionEnabled(); HRESULT ExtendFrameIntoClientArea(HWND hWnd, int cxLeftWidth, int cyTopHeight, int cxRightWidth, int cyBottomHeight); public: void LogicalToPhysicalPoint(HWND hWnd, LPPOINT lpPoint); void SetProcessDPIAware(); private: CSharedData& GetSharedData() const; }; /** @endcond */ ///////////////////////////////////////////////////////////////////////////// # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif // !defined(__XTPWINTHEMEWRAPPER_H__) /** @endcond */