Repository navigation
Expand file tree
/
Copy pathMenuFont.cpp
More file actions
114 lines (88 loc) · 2.63 KB
/
Copy pathMenuFont.cpp
File metadata and controls
114 lines (88 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* $Header: /Cleaner/MenuFont.cpp 12 22.03.02 12:57 Oslph312 $
*/
#include "precomp.h"
#include "MenuFont.h"
#include "Registry.h"
#include "os.h"
#include "trace.h"
#ifdef _DEBUG
#include "winUtils.h"
#endif
MenuFont MenuFont::theMenuFont;
MenuFont::MenuFont() : m_hfontMenu( 0 ) {
assert( this == &theMenuFont ); // One and only one!
refresh();
}
MenuFont::~MenuFont() {
trace( _T( "Menufont dtor" ) );
if ( 0 != m_hfontMenu ) {
DeleteFont( m_hfontMenu );
m_hfontMenu = 0;
trace( _T( " deletes font\n" ) );
} else {
trace( _T( " has no font!\n" ) );
}
}
HFONT MenuFont::getFont( void ) {
if ( 0 != theMenuFont.m_hfontMenu ) {
return theMenuFont.m_hfontMenu;
}
return GetStockFont( DEFAULT_GUI_FONT );
}
int MenuFont::getHeight( void ) {
return theMenuFont.m_nCachedHeight;
}
#pragma pack( 1 )
typedef struct LOGFONTWIN95REG {
short lfHeight;
short lfWidth;
short lfEscapement;
short lfOrientation;
short lfWeight;
BYTE lfItalic;
BYTE lfUnderline;
BYTE lfStrikeOut;
BYTE lfCharSet;
BYTE lfOutPrecision;
BYTE lfClipPrecision;
BYTE lfQuality;
BYTE lfPitchAndFamily;
CHAR lfFaceName[ LF_FACESIZE ];
} LOGFONTWIN95REG;
#pragma pack()
void MenuFont::refresh( void ) {
if ( 0 != theMenuFont.m_hfontMenu ) {
DeleteFont( theMenuFont.m_hfontMenu );
theMenuFont.m_hfontMenu = 0;
}
#define REG_PATH _T( "Control Panel\\Desktop\\WindowMetrics" )
#define REG_ENTRY _T( "MenuFont" )
// Check for wild values:
#define CHECKFONT( logfont ) \
if ( abs( logfont.lfHeight ) < min_height ) { \
logfont.lfHeight = min_height; \
} else if ( max_height < abs( logfont.lfHeight ) ) { \
logfont.lfHeight = max_height; \
} \
logfont.lfEscapement = logfont.lfOrientation = \
logfont.lfUnderline = logfont.lfStrikeOut = 0
LOGFONTW logFontW = { 0 };
bool isMenuFontOK = Registry::getBlob(HKEY_CURRENT_USER,
REG_PATH, REG_ENTRY, &logFontW, sizeof logFontW);
if (isMenuFontOK) {
CHECKFONT(logFontW);
theMenuFont.m_hfontMenu = CreateFontIndirectW(&logFontW);
GetObject(theMenuFont.m_hfontMenu, sizeof logFontW, &logFontW);
theMenuFont.m_nCachedHeight = abs(logFontW.lfHeight);
}
#ifdef _DEBUG
trace( _T( "Menufont::refresh: OK = %d\n" ), isMenuFontOK );
if ( !isMenuFontOK ) {
messageBox( HWND_DESKTOP, MB_OK, _T( "isMenuFontOK is FALSE" ) );
}
#endif
#undef REG_PATH
#undef REG_ENTRY
}
// end of file