Click here to Skip to main content
15,886,737 members
Articles / Desktop Programming / MFC

The Ultimate Toolbox - Updates and User Contributions

Rate me:
Please Sign up or sign in to vote.
4.79/5 (26 votes)
12 Feb 2013CPOL8 min read 254.8K   23.7K   170  
Updates and User Contributions for the Ultimate Toolbox Libraries
// UGXPThemes.h: interface for the UGXPThemes class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_UGXPThemes_H__5F3CE743_0206_482D_9C42_E408B983A3C6__INCLUDED_)
#define AFX_UGXPThemes_H__5F3CE743_0206_482D_9C42_E408B983A3C6__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


#include "ugcell.h"

#pragma warning (push,3)
#pragma warning (disable : 4018 4146)
#include<string>
#pragma warning (pop)

typedef struct _XPMARGINS
{
    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
} XPMARGINS, *PXPMARGINS;


enum UGXPThemeStyles { Style1, Style2 };

class UG_CLASS_DECL UGXPThemes  
{
private:
	static UGXPThemeStyles m_style;
	static HMODULE m_huxtheme;
	static bool useThemes;
	static bool drawEdgeBorder;
public:
	virtual ~UGXPThemes();
	static bool IsThemed();

	static void SetGridStyle(UGXPThemeStyles style);
	static UGXPThemeStyles GetGridStyle() { return m_style; }
private:

	static BOOL IsThemeBackgroundPartiallyTransparent(HANDLE hTheme, int iPartId, int iStateId);
	static HRESULT DrawThemeParentBackground(HWND hwnd, HDC hdc, RECT * prc);

	static HRESULT DrawThemeBackground(HANDLE hTheme, HDC hdc, 
		int iPartId, int iStateId, const RECT *pRect, const RECT *pClipRect);
	static HANDLE OpenThemeData(HWND hwnd, LPCWSTR pszClassList, bool useCache = true);
	static HRESULT CloseThemeData(HANDLE hTheme);
	static HRESULT DrawThemeText(HANDLE hTheme, HDC hdc, int iPartId, 
		int iStateId, LPCWSTR pszText, int iCharCount, DWORD dwTextFlags, 
		DWORD dwTextFlags2, const RECT *pRect);	
	static HRESULT DrawThemeEdge(HANDLE hTheme, HDC hdc, 
		int iPartId, int iStateId, const RECT *pRect, UINT uEdge, UINT uFlags, RECT *pContentRect);
	static HRESULT GetThemeMargins(HANDLE hTheme,  HDC hdc, int iPartId, 
		 int iStateId, int iPropId,  RECT *prc, XPMARGINS *pMargins);
		static HRESULT GetThemeTextExtent(HANDLE hTheme, HDC hdc, 
		int iPartId, int iStateId, LPCWSTR pszText, int iCharCount, 
		DWORD dwTextFlags,  const RECT *pBoundingRect, 
		RECT *pExtentRect);
	static HRESULT GetThemeString(HANDLE theme, int iPartId, 
		int iStateId, int iPropId,  LPWSTR pszBuff, int cchMaxBuffChars);

	static HRESULT GetThemeRect(HANDLE hTheme, int iPartId, int iStateId, int iPropId,  RECT *pRect);
	static HRESULT GetThemePartSize(HANDLE hTheme, HDC dc, int iPartId, int iStateId, RECT * pRect, int eSize,  SIZE *psz);

public:

	static bool GetThemeString(LPCWSTR theme, int iPartId, 
		int iStateId, int iPropId,  LPWSTR pszBuff, int cchMaxBuffChars);

	static bool GetTextExtent(HWND hwnd, HDC hdc, LPCWSTR themeName, int iPartId, int iStateId,
		LPCSTR pszText, int iCharCount, DWORD dwTextFlags,  const RECT *pBoundingRect, 
		RECT *pExtentRect);

	static bool WriteText(HWND hwnd, HDC hdc, LPCTSTR theme, int partID, 
		int stateID, LPCTSTR text, int textLength, DWORD textFlags, const RECT *pRect, bool useCache = true);

	static bool DrawBackground(HWND hwnd, HDC hdc, LPCWSTR theme, int partID, 
		int stateID,  const RECT *pRect, const RECT *pClipRect, bool useCache = true);
	static bool DrawBackground(HWND hwnd, HDC hdc, UGXPCellType type, UGXPThemeState state,
		const RECT *pRect, const RECT *pClipRect);
	static bool WriteText(HWND hwnd, HDC hdc, UGXPCellType type, UGXPThemeState state,
		LPCTSTR text, int textLength, DWORD textFlags, const RECT *pRect);
	static bool DrawEdge(HWND hwnd, HDC hdc, UGXPCellType type, UGXPThemeState state, 
		const RECT *pRect, UINT uEdge, UINT uFlags, RECT *pContentRect);

	static bool GetThemeRect(LPCWSTR hTheme, int iPartId, int iStateId, RECT *pRect);

	static bool GetThemePartSize(LPCWSTR hTheme, HDC dc, int iPartId, int iStateId, RECT * pRect, int eSize,  SIZE *psz);

	static bool GetMargins(HWND hwnd, HDC hdc, UGXPCellType type, UGXPThemeState state, int propID,
		RECT *prc, XPMARGINS *pMargins);


	static bool GetTextExtent(HWND hwnd, HDC hdc, UGXPCellType type, UGXPThemeState state,
		LPCTSTR pszText, int iCharCount, DWORD dwTextFlags,  const RECT *pBoundingRect, 
		RECT *pExtentRect);

	static bool UseThemes() { return useThemes; }
	static void UseThemes(bool use) { useThemes = use; }

	static void DrawBorderEdges(bool draw) { drawEdgeBorder = draw; }
	static bool DrawBorderEdges() { return drawEdgeBorder; }

	static UGXPThemeState GetState(bool selected, bool current);

	static void CleanUp();

	static void SetXPTheme(UGXPCellType type, UGXPThemeState state, LPCWSTR typeName, int iPartId, int iStateId);

	static bool DrawEdge(HWND hwnd, HDC hdc, LPCWSTR theme, int partID, int stateID, 
		const RECT *pRect, UINT uEdge, UINT uFlags, RECT *pContentRect);

private:
	// This class has only static methods
	UGXPThemes();

	// Calling LoadLibrary here means that our static HMODULE can be initialised to NULL 
	// ( i.e. it is only loaded if we need it )
	// The function returns true if the load succeeds.
	static bool LoadLibrary(); 

	// These are the function signatures used when calling GetProcAddress.
	typedef HANDLE(__stdcall *OPENTHEMEDATA)(HWND hwnd, LPCWSTR pszClassList);
	typedef HRESULT(__stdcall *DRAWTHEMEBACKGROUND)(HANDLE hTheme, HDC hdc, 
		int iPartId, int iStateId, const RECT *pRect,  const RECT *pClipRect);
	typedef HRESULT(__stdcall *CLOSETHEMEDATA)(HANDLE hTheme);
	typedef HRESULT (__stdcall *DRAWTHEMETEXT)(HANDLE hTheme, HDC hdc, int iPartId, 
		int iStateId, LPCWSTR pszText, int iCharCount, DWORD dwTextFlags, 
		DWORD dwTextFlags2, const RECT *pRect);
	typedef HRESULT (__stdcall *DRAWTHEMEEDGE)(HANDLE hTheme, HDC hdc, int iPartId, int iStateId, 
		const RECT *pDestRect, UINT uEdge, UINT uFlags,   RECT *pContentRect);
	typedef HRESULT (__stdcall *GETTHEMEMARGINS)(HANDLE hTheme,  HDC hdc, int iPartId, 
		int iStateId, int iPropId,  RECT *prc,  XPMARGINS *pMargins);
	typedef HRESULT (__stdcall *GETTHEMETEXTEXTENT)(HANDLE hTheme, HDC hdc, 
		int iPartId, int iStateId, LPCWSTR pszText, int iCharCount, 
		DWORD dwTextFlags,  const RECT *pBoundingRect, 
		RECT *pExtentRect);
	typedef HRESULT (__stdcall *GETTHEMESTRING)(HANDLE hTheme, int iPartId, 
		int iStateId, int iPropId,  LPWSTR pszBuff, int cchMaxBuffChars);
	typedef BOOL (__stdcall *ISTHEMEBACKGROUNDPARTIALLYTRANSPARENT)(HANDLE hTheme, int iPartId, int iStateId);
	typedef HRESULT (__stdcall *DRAWTHEMEPARENTBACKGROUND)(HWND hwnd, HDC hdc, RECT * prc);
	typedef HRESULT (__stdcall *GETTHEMERECT)(HANDLE hTheme, int iPartId, 
		int iStateId, int iPropId,  RECT *pRect);
	typedef HRESULT(__stdcall *GETTHEMEPARTSIZE)(HANDLE hTheme, HDC hdc, 
		int iPartId, int iStateId, RECT * pRect, int eSize,  SIZE *psz);
	/* eSize is really this:
	typedef enum THEMESIZE
	{
		TS_MIN,             // minimum size
		TS_TRUE,            // size without stretching
		TS_DRAW,            // size that theme mgr will use to draw part
	};*/
};

#endif // !defined(AFX_UGXPThemes_H__5F3CE743_0206_482D_9C42_E408B983A3C6__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created TheUltimateToolbox.com, a new group dedicated to the continued development, support and growth of Dundas Software’s award winning line of MFC, C++ and ActiveX control products.

Ultimate Grid for MFC, Ultimate Toolbox for MFC, and Ultimate TCP/IP have been stalwarts of C++/MFC development for a decade. Thousands of developers have used these products to speed their time to market, improve the quality of their finished products, and enhance the reliability and flexibility of their software.
This is a Organisation

476 members

Comments and Discussions