Something went wrong. Try again.
A simple, small calculator placed discreetly near the Windows Taskbar or anywhere on the screen taskbar-calculator.marcomaroni.it
Something went wrong. Try again.
taskbar-calculator VisualStyle.cpp
3.5 kB · 151 lines
C++
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151////////////////////////////////////////////////////////////////////////////////// #include "StdAfx.h"#include "VisualStyle.h"#include "Utils.h"
// Point size of the calculator display; the one knob for readability tweaks.const int DISPLAY_FONT_PT = 10;
static LONG DisplayFontHeight(UINT dpi){ return -::MulDiv(DISPLAY_FONT_PT, (int)dpi, 72);}
////////////////////////////////////////////////////////////////////////////////// Classic visual style
class CClassicVisualStyle : public CVisualStyle{public: CClassicVisualStyle(UINT dpi) { CreateFont(dpi); CreateTextColor(); }
virtual void DrawBackground(HWND /*hWnd*/, HDC hdc, const RECT& rcPaint) const { ::FillRect(hdc, &rcPaint, ::GetSysColorBrush(CTLCOLOR_DLG)); }
private: bool CreateFont(UINT dpi) { NONCLIENTMETRICS ncm = { 0 }; ncm.cbSize = sizeof(NONCLIENTMETRICS) - (::IsVistaOrHigher() ? 0 : sizeof(ncm.iPaddedBorderWidth));
if(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0)) { ncm.lfMessageFont.lfHeight = DisplayFontHeight(dpi); m_hFont = ::CreateFontIndirect(&ncm.lfMessageFont); }
ATLASSERT(m_hFont);
return (m_hFont != NULL); }
bool CreateTextColor() { m_clrText = ::GetSysColor(COLOR_MENUTEXT);
return true; }};
////////////////////////////////////////////////////////////////////////////////// Themed visual style
class CThemedVisualStyle : public CVisualStyle{public: CThemedVisualStyle(UINT dpi) { CreateFont(dpi); CreateTextColor(); }
virtual void DrawBackground(HWND hWnd, HDC hdc, const RECT& rcPaint) const { ::DrawThemeParentBackground(hWnd, hdc, &rcPaint); }
private: bool CreateFont(UINT dpi) { HTHEME hTheme = ::OpenThemeData(NULL, VSCLASS_REBAR); ATLASSERT(hTheme);
if(hTheme) { LOGFONT lf = { 0 }; const HRESULT hr = ::GetThemeFont(hTheme, NULL, RP_BAND, 0, TMT_FONT, &lf); ATLASSERT(SUCCEEDED(hr));
if(SUCCEEDED(hr)) { lf.lfHeight = DisplayFontHeight(dpi); lf.lfWeight = 600; m_hFont = ::CreateFontIndirect(&lf); ATLASSERT(m_hFont); }
::CloseThemeData(hTheme); }
return (m_hFont != NULL); }
bool CreateTextColor() { bool bRet = false; HTHEME hTheme = ::OpenThemeData(NULL, VSCLASS_TASKBAND); ATLASSERT(hTheme);
if(hTheme) { const HRESULT hr = ::GetThemeColor(hTheme, TDP_GROUPCOUNT, 0, TMT_TEXTCOLOR, &m_clrText); ATLASSERT(SUCCEEDED(hr));
::CloseThemeData(hTheme); bRet = SUCCEEDED(hr); }
return bRet; }};
////////////////////////////////////////////////////////////////////////////////// CVisualStyle
CVisualStyle::~CVisualStyle(){ if(m_hFont) ::DeleteObject(m_hFont);}
// staticCVisualStyle* CVisualStyle::Create(VisualStyle vs, UINT dpi){ CVisualStyle* pVS = NULL;
if(vs == Auto) vs = (::IsAppThemed() ? Themed : Classic);
switch(vs) { case Classic: pVS = new CClassicVisualStyle(dpi); break; case Themed: pVS = new CThemedVisualStyle(dpi); break; default: ATLASSERT(FALSE); }
return pVS;}