1 // This is a part of the Microsoft Foundation Classes C++ library.
2 // Copyright (C) Microsoft Corporation
3 // All rights reserved.
5 // This source code is only intended as a supplement to the
6 // Microsoft Foundation Classes Reference and related
7 // electronic documentation provided with the library.
8 // See these sources for detailed information regarding the
9 // Microsoft Foundation Classes product.
13 // #include "afxcontrolbarutil.h"
14 #include "afxglobals.h"
16 #pragma warning(disable:4995 4996)
18 #if defined(__INTEL_COMPILER)
19 #pragma warning(disable:810)
23 #include "afxvisualmanager.h"
24 #include "afxkeyboardmanager.h"
25 #include "afxmenuhash.h"
26 #include "afxtoolbar.h"
27 #include "afxmenuimages.h"
28 #include "afxpaneframewnd.h"
29 #include "afxdockingmanager.h"
30 #include "afxvisualmanageroffice2007.h"
31 #include "afxribbonres.h"
33 #include "afxframewndex.h"
34 #include "afxmdiframewndex.h"
35 #include "afxoleipframewndex.h"
36 #include "afxoledocipframewndex.h"
37 #include "afxmdichildwndex.h"
40 extern CObList afxAllToolBars
;
42 BOOL
CMemDC::m_bUseMemoryDC
= TRUE
;
44 #if (_MSC_VER == 1700)
46 #define AFX_FONT_NAME_OFFICE _T("Tahoma")
47 #define AFX_FONT_NAME_OFFICE_2007 _T("Segoe UI")
48 #define AFX_FONT_NAME_DEFAULT _T("MS Sans Serif")
49 #define AFX_FONT_NAME_VERT _T("Arial")
50 #define AFX_FONT_NAME_MARLETT _T("Marlett")
52 CMemDC::CMemDC(CDC
& dc
, CWnd
* pWnd
) :
53 m_dc(dc
), m_bMemDC(FALSE
), m_hBufferedPaint(NULL
), m_pOldBmp(NULL
)
57 pWnd
->GetClientRect(m_rect
);
59 m_rect
.right
+= pWnd
->GetScrollPos(SB_HORZ
);
60 m_rect
.bottom
+= pWnd
->GetScrollPos(SB_VERT
);
64 if (!GetGlobalData()->m_bBufferedPaintInited
)
67 GetGlobalData()->m_bBufferedPaintInited
= TRUE
;
70 m_hBufferedPaint
= BeginBufferedPaint(dc
.GetSafeHdc(), m_rect
, BPBF_TOPDOWNDIB
, NULL
, &hdcPaint
);
72 if (m_hBufferedPaint
!= NULL
&& hdcPaint
!= NULL
)
75 m_dcMem
.Attach(hdcPaint
);
79 CMemDC::CMemDC(CDC
& dc
, const CRect
& rect
) :
80 m_dc(dc
), m_bMemDC(FALSE
), m_hBufferedPaint(NULL
), m_pOldBmp(NULL
), m_rect(rect
)
82 ASSERT(!m_rect
.IsRectEmpty());
86 if (!GetGlobalData()->m_bBufferedPaintInited
)
89 GetGlobalData()->m_bBufferedPaintInited
= TRUE
;
92 m_hBufferedPaint
= BeginBufferedPaint(dc
.GetSafeHdc(), m_rect
, BPBF_TOPDOWNDIB
, NULL
, &hdcPaint
);
94 if (m_hBufferedPaint
!= NULL
&& hdcPaint
!= NULL
)
97 m_dcMem
.Attach(hdcPaint
);
103 if (m_hBufferedPaint
!= NULL
)
106 EndBufferedPaint(m_hBufferedPaint
, TRUE
);
110 static int CALLBACK
FontFamilyProcFonts(const LOGFONT FAR
* lplf
, const TEXTMETRIC FAR
* /*lptm*/, ULONG
/*ulFontType*/, LPARAM lParam
)
112 ENSURE(lplf
!= NULL
);
113 ENSURE(lParam
!= NULL
);
115 CString strFont
= lplf
->lfFaceName
;
116 return strFont
.CollateNoCase((LPCTSTR
) lParam
) == 0 ? 0 : 1;
119 /////////////////////////////////////////////////////////////////////////////
120 // Cached system metrics, etc
121 AFX_GLOBAL_DATA afxGlobalData
;
124 // Reference count on global data
125 DWORD g_dwAfxGlobalDataRef
= 0;
128 AFX_GLOBAL_DATA::AFX_GLOBAL_DATA()
130 m_bInitialized
= FALSE
;
131 m_bIsRibbonImageScale
= TRUE
;
133 // Cached system values(updated in CWnd::OnSysColorChange)
138 m_hcurStretch
= NULL
;
139 m_hcurStretchVert
= NULL
;
141 m_hcurSizeAll
= NULL
;
144 m_hiconColors
= NULL
;
145 m_hcurMoveTab
= NULL
;
146 m_hcurNoMoveTab
= NULL
;
148 m_bUseSystemFont
= FALSE
;
149 m_bDontReduceFontHeight
= FALSE
;
150 m_bInSettingChange
= FALSE
;
153 m_bBufferedPaintInited
= FALSE
;
155 m_nDragFrameThicknessFloat
= 4; // pixels
156 m_nDragFrameThicknessDock
= 3; // pixels
158 m_nAutoHideToolBarSpacing
= 14; // pixels
159 m_nAutoHideToolBarMargin
= 4; // pixels
161 m_nCoveredMainWndClientAreaPercent
= 50; // percents
163 m_nMaxToolTipWidth
= -1;
164 m_bIsBlackHighContrast
= FALSE
;
165 m_bIsWhiteHighContrast
= FALSE
;
167 m_bUseBuiltIn32BitIcons
= TRUE
;
174 // Initialization code
175 void AFX_GLOBAL_DATA::Initialize()
182 OSVERSIONINFOEX osvi
= { sizeof(osvi
), HIBYTE(_WIN32_WINNT_WIN7
), LOBYTE(_WIN32_WINNT_WIN7
) };
184 // The condition mask specifies to test for the OS major/minor versions using greater than or equal.
185 DWORDLONG
const dwlConditionMask
= VerSetConditionMask(VerSetConditionMask(0, VER_MAJORVERSION
, VER_GREATER_EQUAL
), VER_MINORVERSION
, VER_GREATER_EQUAL
);
187 bIsWindows7
= VerifyVersionInfo(&osvi
, VER_MAJORVERSION
| VER_MINORVERSION
, dwlConditionMask
);
189 bIsRemoteSession
= GetSystemMetrics(SM_REMOTESESSION
);
194 EnableAccessibilitySupport();
197 AFX_GLOBAL_DATA::~AFX_GLOBAL_DATA()
202 void AFX_GLOBAL_DATA::UpdateFonts()
205 m_dblRibbonImageScale
= dc
.GetDeviceCaps(LOGPIXELSX
) / 96.0f
;
207 if (m_dblRibbonImageScale
> 1. && m_dblRibbonImageScale
< 1.1)
209 m_dblRibbonImageScale
= 1.;
212 if (fontRegular
.GetSafeHandle() != NULL
)
214 ::DeleteObject(fontRegular
.Detach());
217 if (fontTooltip
.GetSafeHandle() != NULL
)
219 ::DeleteObject(fontTooltip
.Detach());
222 if (fontBold
.GetSafeHandle() != NULL
)
224 ::DeleteObject(fontBold
.Detach());
227 if (fontDefaultGUIBold
.GetSafeHandle() != NULL
)
229 ::DeleteObject(fontDefaultGUIBold
.Detach());
232 if (fontUnderline
.GetSafeHandle() != NULL
)
234 ::DeleteObject(fontUnderline
.Detach());
237 if (fontDefaultGUIUnderline
.GetSafeHandle() != NULL
)
239 ::DeleteObject(fontDefaultGUIUnderline
.Detach());
242 if (fontVert
.GetSafeHandle() != NULL
)
244 ::DeleteObject(fontVert
.Detach());
247 if (fontVertCaption
.GetSafeHandle() != NULL
)
249 ::DeleteObject(fontVertCaption
.Detach());
252 if (fontMarlett
.GetSafeHandle() != NULL
)
254 ::DeleteObject(fontMarlett
.Detach());
257 if (fontSmall
.GetSafeHandle() != NULL
)
259 ::DeleteObject(fontSmall
.Detach());
264 NONCLIENTMETRICS info
;
265 info
.cbSize
= sizeof(info
);
266 GetNonClientMetrics (info
);
269 memset(&lf
, 0, sizeof(LOGFONT
));
271 lf
.lfCharSet
= (BYTE
) GetTextCharsetInfo(dc
.GetSafeHdc(), NULL
, 0);
273 lf
.lfHeight
= info
.lfMenuFont
.lfHeight
;
274 lf
.lfWeight
= info
.lfMenuFont
.lfWeight
;
275 lf
.lfItalic
= info
.lfMenuFont
.lfItalic
;
280 int nFontHeight
= lf
.lfHeight
< 0 ? -lf
.lfHeight
: lf
.lfHeight
;
281 if (nFontHeight
<= 12)
285 else if (!m_bDontReduceFontHeight
)
290 lf
.lfHeight
= (lf
.lfHeight
< 0) ? -nFontHeight
: nFontHeight
;
292 // Check if we should use system font
293 lstrcpy(lf
.lfFaceName
, info
.lfMenuFont
.lfFaceName
);
295 BOOL fUseSystemFont
= m_bUseSystemFont
|| (info
.lfMenuFont
.lfCharSet
> SYMBOL_CHARSET
);
298 // Check for "Segoe UI" or "Tahoma" font existance:
299 if (::EnumFontFamilies(dc
.GetSafeHdc(), NULL
, FontFamilyProcFonts
, (LPARAM
)(LPCTSTR
) AFX_FONT_NAME_OFFICE_2007
) == 0)
301 // Found! Use MS Office 2007 font!
302 lstrcpy(lf
.lfFaceName
, AFX_FONT_NAME_OFFICE_2007
);
303 lf
.lfQuality
= 5 /*CLEARTYPE_QUALITY*/;
305 else if (::EnumFontFamilies(dc
.GetSafeHdc(), NULL
, FontFamilyProcFonts
, (LPARAM
)(LPCTSTR
) AFX_FONT_NAME_OFFICE
) == 0)
307 // Found! Use MS Office font!
308 lstrcpy(lf
.lfFaceName
, AFX_FONT_NAME_OFFICE
);
312 // Not found. Use default font:
313 lstrcpy(lf
.lfFaceName
, AFX_FONT_NAME_DEFAULT
);
317 fontRegular
.CreateFontIndirect(&lf
);
319 // Create small font:
320 LONG lfHeightSaved
= lf
.lfHeight
;
322 lf
.lfHeight
= (long)((1. + abs(lf
.lfHeight
)) * 2 / 3);
323 if (lfHeightSaved
< 0)
325 lf
.lfHeight
= -lf
.lfHeight
;
328 fontSmall
.CreateFontIndirect(&lf
);
329 lf
.lfHeight
= lfHeightSaved
;
331 // Create tooltip font:
332 NONCLIENTMETRICS ncm
;
333 ncm
.cbSize
= sizeof(ncm
);
334 GetNonClientMetrics (ncm
);
336 lf
.lfItalic
= ncm
.lfStatusFont
.lfItalic
;
337 lf
.lfWeight
= ncm
.lfStatusFont
.lfWeight
;
338 fontTooltip
.CreateFontIndirect(&lf
);
340 lf
.lfItalic
= info
.lfMenuFont
.lfItalic
;
341 lf
.lfWeight
= info
.lfMenuFont
.lfWeight
;
343 // Create "underline" font:
344 lf
.lfUnderline
= TRUE
;
345 fontUnderline
.CreateFontIndirect(&lf
);
346 lf
.lfUnderline
= FALSE
;
349 lf
.lfWeight
= FW_BOLD
;
350 fontBold
.CreateFontIndirect(&lf
);
352 // Create Marlett font:
353 BYTE bCharSet
= lf
.lfCharSet
;
354 lf
.lfWeight
= info
.lfMenuFont
.lfWeight
;
355 lf
.lfCharSet
= SYMBOL_CHARSET
;
357 lf
.lfHeight
= ::GetSystemMetrics(SM_CYMENUCHECK
) - 1;
358 lstrcpy(lf
.lfFaceName
, AFX_FONT_NAME_MARLETT
);
360 fontMarlett
.CreateFontIndirect(&lf
);
361 lf
.lfCharSet
= bCharSet
; // Restore charset
363 // Create vertical font:
365 if (font
.CreateStockObject(DEFAULT_GUI_FONT
))
367 if (font
.GetLogFont(&lf
) != 0)
369 lf
.lfOrientation
= 900;
370 lf
.lfEscapement
= 2700;
372 lf
.lfHeight
= info
.lfMenuFont
.lfHeight
;
373 lf
.lfWeight
= info
.lfMenuFont
.lfWeight
;
374 lf
.lfItalic
= info
.lfMenuFont
.lfItalic
;
377 lstrcpy(lf
.lfFaceName
, AFX_FONT_NAME_VERT
);
380 fontVert
.CreateFontIndirect(&lf
);
382 lf
.lfEscapement
= 900;
383 fontVertCaption
.CreateFontIndirect(&lf
);
387 // Create dialog underline and bold fonts:
388 CFont
* pDefaultGUIFont
= CFont::FromHandle((HFONT
) GetStockObject(DEFAULT_GUI_FONT
));
389 ASSERT_VALID(pDefaultGUIFont
);
390 pDefaultGUIFont
->GetLogFont(&lf
);
392 lf
.lfUnderline
= TRUE
;
393 fontDefaultGUIUnderline
.CreateFontIndirect(&lf
);
394 lf
.lfUnderline
= FALSE
;
396 lf
.lfWeight
= FW_BOLD
;
397 fontDefaultGUIBold
.CreateFontIndirect(&lf
);
402 // Notify toolbars about font changing:
403 for (POSITION posTlb
= afxAllToolBars
.GetHeadPosition(); posTlb
!= NULL
;)
405 CMFCToolBar
* pToolBar
= (CMFCToolBar
*) afxAllToolBars
.GetNext(posTlb
);
406 ENSURE(pToolBar
!= NULL
);
408 if (CWnd::FromHandlePermanent(pToolBar
->m_hWnd
) != NULL
)
410 ASSERT_VALID(pToolBar
);
411 pToolBar
->OnGlobalFontsChanged();
417 static BOOL CALLBACK
InfoEnumProc( HMONITOR hMonitor
, HDC
/*hdcMonitor*/, LPRECT
/*lprcMonitor*/, LPARAM dwData
)
419 CRect
* pRect
= (CRect
*) dwData
;
422 mi
.cbSize
= sizeof(MONITORINFO
);
424 if (GetMonitorInfo(hMonitor
, &mi
))
426 CRect rectMon
= mi
.rcWork
;
428 pRect
->left
= min(pRect
->left
, rectMon
.left
);
429 pRect
->right
= max(pRect
->right
, rectMon
.right
);
430 pRect
->top
= min(pRect
->top
, rectMon
.top
);
431 pRect
->bottom
= max(pRect
->bottom
, rectMon
.bottom
);
437 void AFX_GLOBAL_DATA::OnSettingChange()
439 m_bInSettingChange
= TRUE
;
441 m_sizeSmallIcon
.cx
= ::GetSystemMetrics(SM_CXSMICON
);
442 m_sizeSmallIcon
.cy
= ::GetSystemMetrics(SM_CYSMICON
);
444 m_rectVirtual
.SetRectEmpty();
446 if (!EnumDisplayMonitors(NULL
, NULL
, InfoEnumProc
, (LPARAM
) &m_rectVirtual
))
448 ::SystemParametersInfo(SPI_GETWORKAREA
, 0, &m_rectVirtual
, 0);
451 // Get system menu animation type:
452 m_bMenuAnimation
= FALSE
;
453 m_bMenuFadeEffect
= FALSE
;
455 if (!bIsRemoteSession
)
457 ::SystemParametersInfo(SPI_GETMENUANIMATION
, 0, &m_bMenuAnimation
, 0);
459 if (m_bMenuAnimation
)
461 ::SystemParametersInfo(SPI_GETMENUFADE
, 0, &m_bMenuFadeEffect
, 0);
465 m_nShellAutohideBars
= 0;
466 m_bRefreshAutohideBars
= TRUE
;
468 ::SystemParametersInfo(SPI_GETMENUUNDERLINES
, 0, &m_bSysUnderlineKeyboardShortcuts
, 0);
469 m_bUnderlineKeyboardShortcuts
= m_bSysUnderlineKeyboardShortcuts
;
471 m_bInSettingChange
= FALSE
;
474 void AFX_GLOBAL_DATA::UpdateSysColors()
476 m_bIsBlackHighContrast
= ::GetSysColor(COLOR_3DLIGHT
) == RGB(255, 255, 255) && ::GetSysColor(COLOR_3DFACE
) == RGB(0, 0, 0);
477 m_bIsWhiteHighContrast
= ::GetSysColor(COLOR_3DDKSHADOW
) == RGB(0, 0, 0) && ::GetSysColor(COLOR_3DFACE
) == RGB(255, 255, 255);
480 m_nBitsPerPixel
= dc
.GetDeviceCaps(BITSPIXEL
);
482 clrBarFace
= clrBtnFace
= ::GetSysColor(COLOR_BTNFACE
);
483 clrBarShadow
= clrBtnShadow
= ::GetSysColor(COLOR_BTNSHADOW
);
484 clrBarDkShadow
= clrBtnDkShadow
= ::GetSysColor(COLOR_3DDKSHADOW
);
485 clrBarLight
= clrBtnLight
= ::GetSysColor(COLOR_3DLIGHT
);
486 clrBarHilite
= clrBtnHilite
= ::GetSysColor(COLOR_BTNHIGHLIGHT
);
487 clrBarText
= clrBtnText
= ::GetSysColor(COLOR_BTNTEXT
);
488 clrGrayedText
= ::GetSysColor(COLOR_GRAYTEXT
);
489 clrWindowFrame
= ::GetSysColor(COLOR_WINDOWFRAME
);
491 clrHilite
= ::GetSysColor(COLOR_HIGHLIGHT
);
492 clrTextHilite
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
494 clrBarWindow
= clrWindow
= ::GetSysColor(COLOR_WINDOW
);
495 clrWindowText
= ::GetSysColor(COLOR_WINDOWTEXT
);
497 clrCaptionText
= ::GetSysColor(COLOR_CAPTIONTEXT
);
498 clrMenuText
= ::GetSysColor(COLOR_MENUTEXT
);
500 clrActiveCaption
= ::GetSysColor(COLOR_ACTIVECAPTION
);
501 clrInactiveCaption
= ::GetSysColor(COLOR_INACTIVECAPTION
);
503 clrActiveCaptionGradient
= ::GetSysColor(COLOR_GRADIENTACTIVECAPTION
);
504 clrInactiveCaptionGradient
= ::GetSysColor(COLOR_GRADIENTINACTIVECAPTION
);
506 clrActiveBorder
= ::GetSysColor(COLOR_ACTIVEBORDER
);
507 clrInactiveBorder
= ::GetSysColor(COLOR_INACTIVEBORDER
);
509 clrInactiveCaptionText
= ::GetSysColor(COLOR_INACTIVECAPTIONTEXT
);
511 if (m_bIsBlackHighContrast
)
513 clrHotLinkNormalText
= clrWindowText
;
514 clrHotLinkHoveredText
= clrWindowText
;
515 clrHotLinkVisitedText
= clrWindowText
;
519 clrHotLinkNormalText
= ::GetSysColor(COLOR_HOTLIGHT
);
520 clrHotLinkHoveredText
= RGB(0, 0, 255); // Bright blue
521 clrHotLinkVisitedText
= RGB(128, 0, 128); // Violet
524 hbrBtnShadow
= ::GetSysColorBrush(COLOR_BTNSHADOW
);
525 ENSURE(hbrBtnShadow
!= NULL
);
527 hbrBtnHilite
= ::GetSysColorBrush(COLOR_BTNHIGHLIGHT
);
528 ENSURE(hbrBtnHilite
!= NULL
);
530 hbrWindow
= ::GetSysColorBrush(COLOR_WINDOW
);
531 ENSURE(hbrWindow
!= NULL
);
533 brBtnFace
.DeleteObject();
534 brBtnFace
.CreateSolidBrush(clrBtnFace
);
536 brBarFace
.DeleteObject();
537 brBarFace
.CreateSolidBrush(clrBarFace
);
539 brActiveCaption
.DeleteObject();
540 brActiveCaption
.CreateSolidBrush(clrActiveCaption
);
542 brInactiveCaption
.DeleteObject();
543 brInactiveCaption
.CreateSolidBrush(clrInactiveCaption
);
545 brHilite
.DeleteObject();
546 brHilite
.CreateSolidBrush(clrHilite
);
548 brBlack
.DeleteObject();
549 brBlack
.CreateSolidBrush(clrBtnDkShadow
);
551 brWindow
.DeleteObject();
552 brWindow
.CreateSolidBrush(clrWindow
);
554 penHilite
.DeleteObject();
555 penHilite
.CreatePen(PS_SOLID
, 1, afxGlobalData
.clrHilite
);
557 penBarFace
.DeleteObject();
558 penBarFace
.CreatePen(PS_SOLID
, 1, afxGlobalData
.clrBarFace
);
560 penBarShadow
.DeleteObject();
561 penBarShadow
.CreatePen(PS_SOLID
, 1, afxGlobalData
.clrBarShadow
);
563 if (brLight
.GetSafeHandle())
565 brLight
.DeleteObject();
568 if (m_nBitsPerPixel
> 8)
570 COLORREF clrLight
= RGB(GetRValue(clrBtnFace
) +((GetRValue(clrBtnHilite
) - GetRValue(clrBtnFace
)) / 2 ),
571 GetGValue(clrBtnFace
) +((GetGValue(clrBtnHilite
) - GetGValue(clrBtnFace
)) / 2),
572 GetBValue(clrBtnFace
) +((GetBValue(clrBtnHilite
) - GetBValue(clrBtnFace
)) / 2));
574 brLight
.CreateSolidBrush(clrLight
);
578 HBITMAP hbmGray
= CreateDitherBitmap(dc
.GetSafeHdc());
579 ENSURE(hbmGray
!= NULL
);
584 brLight
.CreatePatternBrush(&bmp
);
587 // CMenuImages::CleanUp();
588 // CDockingManager::m_bSDParamsModified = TRUE;
591 BOOL
AFX_GLOBAL_DATA::SetMenuFont(LPLOGFONT lpLogFont
, BOOL bHorz
)
593 ENSURE(lpLogFont
!= NULL
);
597 // Create regular font:
598 fontRegular
.DeleteObject();
599 if (!fontRegular
.CreateFontIndirect(lpLogFont
))
605 // Create underline font:
606 lpLogFont
->lfUnderline
= TRUE
;
607 fontUnderline
.DeleteObject();
608 fontUnderline
.CreateFontIndirect(lpLogFont
);
609 lpLogFont
->lfUnderline
= FALSE
;
611 // Create bold font(used in the default menu items):
612 long lSavedWeight
= lpLogFont
->lfWeight
;
613 lpLogFont
->lfWeight
= 700;
615 fontBold
.DeleteObject();
616 BOOL bResult
= fontBold
.CreateFontIndirect(lpLogFont
);
618 lpLogFont
->lfWeight
= lSavedWeight
; // Restore weight
626 else // Vertical font
628 fontVert
.DeleteObject();
629 if (!fontVert
.CreateFontIndirect(lpLogFont
))
640 void AFX_GLOBAL_DATA::UpdateTextMetrics()
644 CFont
* pOldFont
= dc
.SelectObject(&fontRegular
);
645 ENSURE(pOldFont
!= NULL
);
648 dc
.GetTextMetrics(&tm
);
650 int nExtra
= tm
.tmHeight
< 15 ? 2 : 5;
652 m_nTextHeightHorz
= tm
.tmHeight
+ nExtra
;
653 m_nTextWidthHorz
= tm
.tmMaxCharWidth
+ nExtra
;
655 dc
.SelectObject(&fontVert
);
656 dc
.GetTextMetrics(&tm
);
658 nExtra
= tm
.tmHeight
< 15 ? 2 : 5;
660 m_nTextHeightVert
= tm
.tmHeight
+ nExtra
;
661 m_nTextWidthVert
= tm
.tmMaxCharWidth
+ nExtra
;
663 dc
.SelectObject(pOldFont
);
666 HBITMAP
AFX_GLOBAL_DATA::CreateDitherBitmap(HDC hDC
)
668 struct // BITMAPINFO with 16 colors
670 BITMAPINFOHEADER bmiHeader
;
671 RGBQUAD bmiColors
[16];
674 memset(&bmi
, 0, sizeof(bmi
));
676 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
677 bmi
.bmiHeader
.biWidth
= 8;
678 bmi
.bmiHeader
.biHeight
= 8;
679 bmi
.bmiHeader
.biPlanes
= 1;
680 bmi
.bmiHeader
.biBitCount
= 1;
681 bmi
.bmiHeader
.biCompression
= BI_RGB
;
683 COLORREF clr
= afxGlobalData
.clrBtnFace
;
685 bmi
.bmiColors
[0].rgbBlue
= GetBValue(clr
);
686 bmi
.bmiColors
[0].rgbGreen
= GetGValue(clr
);
687 bmi
.bmiColors
[0].rgbRed
= GetRValue(clr
);
689 clr
= ::GetSysColor(COLOR_BTNHIGHLIGHT
);
690 bmi
.bmiColors
[1].rgbBlue
= GetBValue(clr
);
691 bmi
.bmiColors
[1].rgbGreen
= GetGValue(clr
);
692 bmi
.bmiColors
[1].rgbRed
= GetRValue(clr
);
694 // initialize the brushes
696 for (int i
= 0; i
< 8; i
++)
697 patGray
[i
] = (i
& 1) ? 0xAAAA5555L
: 0x5555AAAAL
;
699 HBITMAP hbm
= CreateDIBitmap(hDC
, &bmi
.bmiHeader
, CBM_INIT
, (LPBYTE
)patGray
, (LPBITMAPINFO
)&bmi
, DIB_RGB_COLORS
);
703 ITaskbarList
* AFX_GLOBAL_DATA::GetITaskbarList()
705 // Backward-compatibility wrapper
706 CWinApp
* pApp
= AfxGetApp();
709 return pApp
->GetITaskbarList();
715 ITaskbarList3
* AFX_GLOBAL_DATA::GetITaskbarList3()
717 // Backward-compatibility wrapper
718 CWinApp
* pApp
= AfxGetApp();
721 return pApp
->GetITaskbarList3();
727 void AFX_GLOBAL_DATA::CleanUp()
729 if (brLight
.GetSafeHandle())
731 brLight
.DeleteObject();
735 fontRegular
.DeleteObject();
736 fontBold
.DeleteObject();
737 fontUnderline
.DeleteObject();
738 fontVert
.DeleteObject();
739 fontVertCaption
.DeleteObject();
740 fontTooltip
.DeleteObject();
742 if (m_bBufferedPaintInited
)
744 BufferedPaintUnInit();
745 m_bBufferedPaintInited
= FALSE
;
748 if (m_hinstDwmapiDLL
!= NULL
)
750 ::FreeLibrary(m_hinstDwmapiDLL
);
751 m_hinstDwmapiDLL
= NULL
;
754 m_bEnableAccessibility
= FALSE
;
757 void ControlBarCleanUp()
759 if (afxGlobalData
.m_bInitialized
)
761 afxGlobalData
.CleanUp();
764 // afxMenuHash.CleanUp();
766 // CMFCToolBar::CleanUpImages();
767 // CMenuImages::CleanUp();
769 // if (GetCmdMgr() != NULL)
771 // GetCmdMgr()->CleanUp();
774 // CKeyboardManager::CleanUp();
776 // Destroy visualization manager:
777 // CMFCVisualManager::DestroyInstance(TRUE /* bAutoDestroyOnly */);
778 // CMFCVisualManagerOffice2007::CleanStyle();
782 void AfxGlobalsAddRef()
784 InterlockedIncrement(&g_dwAfxGlobalDataRef
);
787 void AfxGlobalsRelease()
789 InterlockedDecrement(&g_dwAfxGlobalDataRef
);
790 if (g_dwAfxGlobalDataRef
== 0)
797 BOOL
AFX_GLOBAL_DATA::DrawParentBackground(CWnd
* pWnd
, CDC
* pDC
, LPRECT rectClip
)
805 if (rectClip
!= NULL
)
807 rgn
.CreateRectRgnIndirect(rectClip
);
808 pDC
->SelectClipRgn(&rgn
);
811 CWnd
* pParent
= pWnd
->GetParent();
812 ASSERT_VALID(pParent
);
814 // In Windows XP, we need to call DrawThemeParentBackground function to implement
815 // transparent controls
816 bRes
= DrawThemeParentBackground(pWnd
->GetSafeHwnd(), pDC
->GetSafeHdc(), rectClip
) == S_OK
;
821 pWnd
->MapWindowPoints(pParent
, &pt
, 1);
822 pt
= pDC
->OffsetWindowOrg(pt
.x
, pt
.y
);
824 bRes
= (BOOL
) pParent
->SendMessage(WM_ERASEBKGND
, (WPARAM
)pDC
->m_hDC
);
826 pDC
->SetWindowOrg(pt
.x
, pt
.y
);
829 pDC
->SelectClipRgn(NULL
);
834 CFrameWnd
* AFX_CDECL
AFXGetParentFrame(const CWnd
* pWnd
)
836 if (pWnd
->GetSafeHwnd() == NULL
)
842 const CWnd
* pParentWnd
= pWnd
;
844 while (pParentWnd
!= NULL
)
846 // if (pParentWnd->IsKindOf(RUNTIME_CLASS(CPaneFrameWnd)))
848 // CPaneFrameWnd* pMiniFrame = DYNAMIC_DOWNCAST(CPaneFrameWnd, pParentWnd);
849 // pParentWnd = pMiniFrame->GetParent();
853 pParentWnd
= pParentWnd
->GetParent();
856 if (pParentWnd
== NULL
)
861 if (pParentWnd
->IsFrameWnd())
863 return(CFrameWnd
*)pParentWnd
;
870 COLORREF
AFX_GLOBAL_DATA::GetColor(int nColor
)
874 case COLOR_BTNFACE
: return clrBtnFace
;
875 case COLOR_BTNSHADOW
: return clrBtnShadow
;
876 case COLOR_3DDKSHADOW
: return clrBtnDkShadow
;
877 case COLOR_3DLIGHT
: return clrBtnLight
;
878 case COLOR_BTNHIGHLIGHT
: return clrBtnHilite
;
879 case COLOR_BTNTEXT
: return clrBtnText
;
880 case COLOR_GRAYTEXT
: return clrGrayedText
;
881 case COLOR_WINDOWFRAME
: return clrWindowFrame
;
883 case COLOR_HIGHLIGHT
: return clrHilite
;
884 case COLOR_HIGHLIGHTTEXT
: return clrTextHilite
;
886 case COLOR_WINDOW
: return clrWindow
;
887 case COLOR_WINDOWTEXT
: return clrWindowText
;
889 case COLOR_CAPTIONTEXT
: return clrCaptionText
;
890 case COLOR_MENUTEXT
: return clrMenuText
;
892 case COLOR_ACTIVECAPTION
: return clrActiveCaption
;
893 case COLOR_INACTIVECAPTION
: return clrInactiveCaption
;
895 case COLOR_ACTIVEBORDER
: return clrActiveBorder
;
896 case COLOR_INACTIVEBORDER
: return clrInactiveBorder
;
898 case COLOR_INACTIVECAPTIONTEXT
: return clrInactiveCaptionText
;
901 return ::GetSysColor(nColor
);
904 BOOL
AFX_GLOBAL_DATA::SetLayeredAttrib(HWND hwnd
, COLORREF crKey
, BYTE bAlpha
, DWORD dwFlags
)
906 return(::SetLayeredWindowAttributes(hwnd
, crKey
, bAlpha
, dwFlags
));
909 void AFX_GLOBAL_DATA::EnableAccessibilitySupport(BOOL bEnable
/* = TRUE*/)
911 m_bEnableAccessibility
= bEnable
;
914 CString
AFX_GLOBAL_DATA::RegisterWindowClass(LPCTSTR lpszClassNamePrefix
)
916 ENSURE(lpszClassNamePrefix
!= NULL
);
918 // Register a new window class:
919 HINSTANCE hInst
= AfxGetInstanceHandle();
920 UINT uiClassStyle
= CS_DBLCLKS
;
921 HCURSOR hCursor
= ::LoadCursor(NULL
, IDC_ARROW
);
922 HBRUSH hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
924 CString strClassName
;
925 strClassName
.Format(_T("%s:%x:%x:%x:%x"), lpszClassNamePrefix
, (UINT_PTR
)hInst
, uiClassStyle
, (UINT_PTR
)hCursor
, (UINT_PTR
)hbrBackground
);
927 // See if the class already exists:
929 if (::GetClassInfo(hInst
, strClassName
, &wndcls
))
931 // Already registered, assert everything is good:
932 ASSERT(wndcls
.style
== uiClassStyle
);
936 // Otherwise we need to register a new class:
937 wndcls
.style
= uiClassStyle
;
938 wndcls
.lpfnWndProc
= ::DefWindowProc
;
939 wndcls
.cbClsExtra
= wndcls
.cbWndExtra
= 0;
940 wndcls
.hInstance
= hInst
;
942 wndcls
.hCursor
= hCursor
;
943 wndcls
.hbrBackground
= hbrBackground
;
944 wndcls
.lpszMenuName
= NULL
;
945 wndcls
.lpszClassName
= strClassName
;
947 if (!AfxRegisterClass(&wndcls
))
949 AfxThrowResourceException();
956 BOOL
AFX_GLOBAL_DATA::ExcludeTag(CString
& strBuffer
, LPCTSTR lpszTag
, CString
& strTag
, BOOL bIsCharsList
/* = FALSE*/)
958 const int iBufLen
= strBuffer
.GetLength();
960 CString strTagStart
= _T("<");
961 strTagStart
+= lpszTag
;
962 strTagStart
+= _T(">");
964 const int iTagStartLen
= strTagStart
.GetLength();
968 int iIndexStart
= strBuffer
.Find(strTagStart
);
974 iStart
= iIndexStart
+ iTagStartLen
;
976 CString strTagEnd
= _T("</");
977 strTagEnd
+= lpszTag
;
978 strTagEnd
+= _T('>');
980 const int iTagEndLen
= strTagEnd
.GetLength();
984 for (int i
= iStart
; i
< iBufLen
- iTagEndLen
+ 1; i
++)
986 if (strBuffer
[i
] != '<')
991 if (i
< iBufLen
- iTagStartLen
&& _tcsncmp(strBuffer
.Mid(i
), strTagStart
, iTagStartLen
) == 0)
993 i
+= iTagStartLen
- 1;
998 if (_tcsncmp(strBuffer
.Mid(i
), strTagEnd
, iTagEndLen
) == 0)
1007 i
+= iTagEndLen
- 1;
1011 if (iIndexEnd
== -1 || iStart
> iIndexEnd
)
1016 strTag
= strBuffer
.Mid(iStart
, iIndexEnd
- iStart
);
1020 strBuffer
.Delete(iIndexStart
, iIndexEnd
+ iTagEndLen
- iIndexStart
);
1024 if (strTag
.GetLength() > 1 && strTag
[0] == _T('\"'))
1026 strTag
= strTag
.Mid(1, strTag
.GetLength() - 2);
1029 strTag
.Replace(_T("\\t"), _T("\t"));
1030 strTag
.Replace(_T("\\n"), _T("\n"));
1031 strTag
.Replace(_T("\\r"), _T("\r"));
1032 strTag
.Replace(_T("\\b"), _T("\b"));
1033 strTag
.Replace(_T("LT"), _T("<"));
1034 strTag
.Replace(_T("GT"), _T(">"));
1035 strTag
.Replace(_T("AMP"), _T("&"));
1041 BOOL
AFX_GLOBAL_DATA::IsDwmCompositionEnabled()
1043 // It appears that DwmIsCompositionEnabled can fail if called and
1044 // then called again after a very short time, so use a static var
1045 // so the last obtained value is returned if the method fails.
1046 static BOOL bEnabled
= FALSE
;
1047 DwmIsCompositionEnabled(&bEnabled
);
1051 BOOL
AFX_GLOBAL_DATA::DrawTextOnGlass(HTHEME hTheme
, CDC
* pDC
, int iPartId
, int iStateId
, CString strText
, CRect rect
, DWORD dwFlags
, int nGlowSize
, COLORREF clrText
)
1053 if (hTheme
== NULL
|| !IsDwmCompositionEnabled())
1055 pDC
->DrawText(strText
, rect
, dwFlags
);
1059 CComBSTR bstmp
= (LPCTSTR
)strText
;
1061 wchar_t* wbuf
= new wchar_t[bstmp
.Length() + 1];
1062 wcscpy_s(wbuf
, bstmp
.Length() + 1, bstmp
);
1065 memset(&dto
, 0, sizeof(DTTOPTS
));
1066 dto
.dwSize
= sizeof(DTTOPTS
);
1067 dto
.dwFlags
= DTT_COMPOSITED
;
1071 dto
.dwFlags
|= DTT_GLOWSIZE
;
1072 dto
.iGlowSize
= nGlowSize
;
1075 if (clrText
!= (COLORREF
)-1)
1077 dto
.dwFlags
|= DTT_TEXTCOLOR
;
1078 dto
.crText
= clrText
;
1081 DrawThemeTextEx(hTheme
, pDC
->GetSafeHdc(), iPartId
, iStateId
, wbuf
, -1, dwFlags
, rect
, &dto
);
1088 HCURSOR
AFX_GLOBAL_DATA::GetHandCursor()
1090 if (m_hcurHand
== NULL
)
1092 #pragma warning(push)
1093 #pragma warning(disable: 4302) // 'type cast' : truncation from 'LPSTR' to 'WORD'
1094 m_hcurHand
= ::LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_HAND
));
1095 #pragma warning(pop)
1101 BOOL
AFX_GLOBAL_DATA::Resume()
1103 if (m_bEnableAccessibility
)
1105 EnableAccessibilitySupport();
1108 // CMFCVisualManagerOffice2007::Style style = CMFCVisualManagerOffice2007::GetStyle();
1109 // CMFCVisualManagerOffice2007::CleanStyle ();
1111 // if (CMFCVisualManager::m_pRTIDefault != NULL)
1113 // CMFCVisualManagerOffice2007::SetStyle(style);
1114 // CMFCVisualManager::SetDefaultManager (CMFCVisualManager::m_pRTIDefault);
1120 BOOL
AFX_GLOBAL_DATA::GetNonClientMetrics (NONCLIENTMETRICS
& info
)
1122 struct AFX_OLDNONCLIENTMETRICS
1130 LOGFONT lfCaptionFont
;
1131 int iSmCaptionWidth
;
1132 int iSmCaptionHeight
;
1133 LOGFONT lfSmCaptionFont
;
1137 LOGFONT lfStatusFont
;
1138 LOGFONT lfMessageFont
;
1143 info
.cbSize
= sizeof(AFX_OLDNONCLIENTMETRICS
);
1146 return ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, info
.cbSize
, &info
, 0);
1150 BOOL AFXAPI
AfxIsExtendedFrameClass(CWnd
* pWnd
)
1154 if (pWnd
->IsKindOf(RUNTIME_CLASS(CFrameWndEx
)))
1158 if (pWnd
->IsKindOf(RUNTIME_CLASS(CMDIFrameWndEx
)))
1162 if (pWnd
->IsKindOf(RUNTIME_CLASS(COleIPFrameWndEx
)))
1166 if (pWnd
->IsKindOf(RUNTIME_CLASS(COleDocIPFrameWndEx
)))
1170 if (pWnd
->IsKindOf(RUNTIME_CLASS(CMDIChildWndEx
)))
1179 BOOL AFXAPI
AfxIsMFCToolBar(CWnd
* pWnd
)
1182 // if (pWnd->IsKindOf(RUNTIME_CLASS(CMFCToolBar)))
1189 HRESULT
AFX_GLOBAL_DATA::ShellCreateItemFromParsingName(PCWSTR pszPath
, IBindCtx
*pbc
, REFIID riid
, void **ppv
)
1191 return SHCreateItemFromParsingName(pszPath
, pbc
, riid
, ppv
);
1196 static const CString strOfficeFontName
= _T("Tahoma");
1197 static const CString strOffice2007FontName
= _T("Segoe UI");
1198 static const CString strDefaultFontName
= _T("MS Sans Serif");
1199 static const CString strVertFontName
= _T("Arial");
1200 static const CString strMarlettFontName
= _T("Marlett");
1202 HINSTANCE
AFX_GLOBAL_DATA::m_hinstD2DDLL
= NULL
;
1203 HINSTANCE
AFX_GLOBAL_DATA::m_hinstDWriteDLL
= NULL
;
1205 ID2D1Factory
* AFX_GLOBAL_DATA::m_pDirect2dFactory
= NULL
;
1206 IDWriteFactory
* AFX_GLOBAL_DATA::m_pWriteFactory
= NULL
;
1207 IWICImagingFactory
* AFX_GLOBAL_DATA::m_pWicFactory
= NULL
;
1209 D2D1MAKEROTATEMATRIX
AFX_GLOBAL_DATA::m_pfD2D1MakeRotateMatrix
= NULL
;
1211 BOOL
AFX_GLOBAL_DATA::m_bD2DInitialized
= FALSE
;
1213 CMemDC::CMemDC(CDC
& dc
, CWnd
* pWnd
) :
1214 m_dc(dc
), m_bMemDC(FALSE
), m_hBufferedPaint(NULL
), m_pOldBmp(NULL
)
1218 pWnd
->GetClientRect(m_rect
);
1220 m_rect
.right
+= pWnd
->GetScrollPos(SB_HORZ
);
1221 m_rect
.bottom
+= pWnd
->GetScrollPos(SB_VERT
);
1223 if (afxGlobalData
.m_pfBeginBufferedPaint
!= NULL
&& afxGlobalData
.m_pfEndBufferedPaint
!= NULL
)
1225 HDC hdcPaint
= NULL
;
1227 if (!afxGlobalData
.m_bBufferedPaintInited
&& afxGlobalData
.m_pfBufferedPaintInit
!= NULL
&& afxGlobalData
.m_pfBufferedPaintUnInit
!= NULL
)
1229 afxGlobalData
.m_pfBufferedPaintInit();
1230 afxGlobalData
.m_bBufferedPaintInited
= TRUE
;
1233 m_hBufferedPaint
= (*afxGlobalData
.m_pfBeginBufferedPaint
)(dc
.GetSafeHdc(), m_rect
, AFX_BPBF_TOPDOWNDIB
, NULL
, &hdcPaint
);
1235 if (m_hBufferedPaint
!= NULL
&& hdcPaint
!= NULL
)
1238 m_dcMem
.Attach(hdcPaint
);
1243 if (m_bUseMemoryDC
&& m_dcMem
.CreateCompatibleDC(&m_dc
) && m_bmp
.CreateCompatibleBitmap(&m_dc
, m_rect
.Width(), m_rect
.Height()))
1245 //-------------------------------------------------------------
1246 // Off-screen DC successfully created. Better paint to it then!
1247 //-------------------------------------------------------------
1249 m_pOldBmp
= m_dcMem
.SelectObject(&m_bmp
);
1254 CMemDC::CMemDC(CDC
& dc
, const CRect
& rect
) :
1255 m_dc(dc
), m_bMemDC(FALSE
), m_hBufferedPaint(NULL
), m_pOldBmp(NULL
), m_rect(rect
)
1257 ASSERT(!m_rect
.IsRectEmpty());
1259 if (afxGlobalData
.m_pfBeginBufferedPaint
!= NULL
&& afxGlobalData
.m_pfEndBufferedPaint
!= NULL
)
1261 HDC hdcPaint
= NULL
;
1263 if (!afxGlobalData
.m_bBufferedPaintInited
&& afxGlobalData
.m_pfBufferedPaintInit
!= NULL
&& afxGlobalData
.m_pfBufferedPaintUnInit
!= NULL
)
1265 afxGlobalData
.m_pfBufferedPaintInit();
1266 afxGlobalData
.m_bBufferedPaintInited
= TRUE
;
1269 m_hBufferedPaint
= (*afxGlobalData
.m_pfBeginBufferedPaint
)(dc
.GetSafeHdc(), m_rect
, AFX_BPBF_TOPDOWNDIB
, NULL
, &hdcPaint
);
1271 if (m_hBufferedPaint
!= NULL
&& hdcPaint
!= NULL
)
1274 m_dcMem
.Attach(hdcPaint
);
1279 if (m_bUseMemoryDC
&& m_dcMem
.CreateCompatibleDC(&m_dc
) && m_bmp
.CreateCompatibleBitmap(&m_dc
, m_rect
.Width(), m_rect
.Height()))
1281 //-------------------------------------------------------------
1282 // Off-screen DC successfully created. Better paint to it then!
1283 //-------------------------------------------------------------
1285 m_pOldBmp
= m_dcMem
.SelectObject(&m_bmp
);
1292 if (m_hBufferedPaint
!= NULL
)
1295 (*afxGlobalData
.m_pfEndBufferedPaint
)(m_hBufferedPaint
, TRUE
);
1299 //--------------------------------------
1300 // Copy the results to the on-screen DC:
1301 //--------------------------------------
1303 int nClipType
= m_dc
.GetClipBox(rectClip
);
1305 if (nClipType
!= NULLREGION
)
1307 if (nClipType
!= SIMPLEREGION
)
1312 m_dc
.BitBlt(rectClip
.left
, rectClip
.top
, rectClip
.Width(), rectClip
.Height(), &m_dcMem
, rectClip
.left
, rectClip
.top
, SRCCOPY
);
1315 m_dcMem
.SelectObject(m_pOldBmp
);
1319 static int CALLBACK
FontFamalyProcFonts(const LOGFONT FAR
* lplf
, const TEXTMETRIC FAR
* /*lptm*/, ULONG
/*ulFontType*/, LPARAM lParam
)
1321 ENSURE(lplf
!= NULL
);
1322 ENSURE(lParam
!= NULL
);
1324 CString strFont
= lplf
->lfFaceName
;
1325 return strFont
.CollateNoCase((LPCTSTR
) lParam
) == 0 ? 0 : 1;
1328 /////////////////////////////////////////////////////////////////////////////
1331 inline HMODULE
AfxLoadSystemLibraryUsingFullPath(_In_z_
const WCHAR
*pszLibrary
)
1333 WCHAR wszLoadPath
[MAX_PATH
+1];
1334 if (::GetSystemDirectoryW(wszLoadPath
, _countof(wszLoadPath
)) == 0)
1339 if (wszLoadPath
[wcslen(wszLoadPath
)-1] != L
'\\')
1341 if (wcscat_s(wszLoadPath
, _countof(wszLoadPath
), L
"\\") != 0)
1347 if (wcscat_s(wszLoadPath
, _countof(wszLoadPath
), pszLibrary
) != 0)
1352 return(::AfxCtxLoadLibraryW(wszLoadPath
));
1355 /////////////////////////////////////////////////////////////////////////////
1356 // Cached system metrics, etc
1357 AFX_GLOBAL_DATA afxGlobalData
;
1360 // Reference count on global data
1361 DWORD g_dwAfxGlobalDataRef
= 0;
1364 // Initialization code
1365 AFX_GLOBAL_DATA::AFX_GLOBAL_DATA()
1367 // Detect the kind of OS:
1369 osvi
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
1371 ::GetVersionEx(&osvi
);
1373 bIsRemoteSession
= GetSystemMetrics(SM_REMOTESESSION
);
1375 bIsWindowsVista
= (osvi
.dwMajorVersion
>= 6);
1376 bIsWindows7
= (osvi
.dwMajorVersion
== 6) && (osvi
.dwMinorVersion
>= 1) || (osvi
.dwMajorVersion
> 6) ;
1377 bDisableAero
= FALSE
;
1379 m_bIsRibbonImageScale
= TRUE
;
1381 // Cached system values(updated in CWnd::OnSysColorChange)
1382 hbrBtnShadow
= NULL
;
1383 hbrBtnHilite
= NULL
;
1388 m_hinstUXThemeDLL
= ::AfxCtxLoadLibraryW(L
"UxTheme.dll");
1389 if (m_hinstUXThemeDLL
!= NULL
)
1391 m_pfDrawThemeBackground
= (DRAWTHEMEPARENTBACKGROUND
)::GetProcAddress(m_hinstUXThemeDLL
, "DrawThemeParentBackground");
1392 m_pfDrawThemeTextEx
= (DRAWTHEMETEXTEX
)::GetProcAddress(m_hinstUXThemeDLL
, "DrawThemeTextEx");
1394 m_pfBufferedPaintInit
= (BUFFEREDPAINTINIT
)::GetProcAddress(m_hinstUXThemeDLL
, "BufferedPaintInit");
1395 m_pfBufferedPaintUnInit
= (BUFFEREDPAINTUNINIT
)::GetProcAddress(m_hinstUXThemeDLL
, "BufferedPaintUnInit");
1397 m_pfBeginBufferedPaint
= (BEGINBUFFEREDPAINT
)::GetProcAddress(m_hinstUXThemeDLL
, "BeginBufferedPaint");
1398 m_pfEndBufferedPaint
= (ENDBUFFEREDPAINT
)::GetProcAddress(m_hinstUXThemeDLL
, "EndBufferedPaint");
1402 m_pfDrawThemeBackground
= NULL
;
1403 m_pfDrawThemeTextEx
= NULL
;
1405 m_pfBufferedPaintInit
= NULL
;
1406 m_pfBufferedPaintUnInit
= NULL
;
1408 m_pfBeginBufferedPaint
= NULL
;
1409 m_pfEndBufferedPaint
= NULL
;
1412 m_hinstDwmapiDLL
= AfxLoadSystemLibraryUsingFullPath(L
"dwmapi.dll");
1413 if (m_hinstDwmapiDLL
!= NULL
)
1415 m_pfDwmExtendFrameIntoClientArea
= (DWMEXTENDFRAMEINTOCLIENTAREA
)::GetProcAddress(m_hinstDwmapiDLL
, "DwmExtendFrameIntoClientArea");
1416 m_pfDwmDefWindowProc
= (DWMDEFWINDOWPROC
) ::GetProcAddress(m_hinstDwmapiDLL
, "DwmDefWindowProc");
1417 m_pfDwmIsCompositionEnabled
= (DWMISCOMPOSITIONENABLED
)::GetProcAddress(m_hinstDwmapiDLL
, "DwmIsCompositionEnabled");
1421 m_pfDwmExtendFrameIntoClientArea
= NULL
;
1422 m_pfDwmDefWindowProc
= NULL
;
1423 m_pfDwmIsCompositionEnabled
= NULL
;
1426 m_hcurStretch
= NULL
;
1427 m_hcurStretchVert
= NULL
;
1429 m_hcurSizeAll
= NULL
;
1432 m_hiconColors
= NULL
;
1433 m_hcurMoveTab
= NULL
;
1434 m_hcurNoMoveTab
= NULL
;
1436 m_bUseSystemFont
= FALSE
;
1437 m_bInSettingChange
= FALSE
;
1443 m_bBufferedPaintInited
= FALSE
;
1445 m_nDragFrameThicknessFloat
= 4; // pixels
1446 m_nDragFrameThicknessDock
= 3; // pixels
1448 m_nAutoHideToolBarSpacing
= 14; // pixels
1449 m_nAutoHideToolBarMargin
= 4; // pixels
1451 m_nCoveredMainWndClientAreaPercent
= 50; // percents
1453 m_nMaxToolTipWidth
= -1;
1454 m_bIsBlackHighContrast
= FALSE
;
1455 m_bIsWhiteHighContrast
= FALSE
;
1457 m_bUseBuiltIn32BitIcons
= TRUE
;
1459 m_bComInitialized
= FALSE
;
1461 m_pTaskbarList
= NULL
;
1462 m_pTaskbarList3
= NULL
;
1463 m_bTaskBarInterfacesAvailable
= TRUE
;
1465 EnableAccessibilitySupport();
1468 AFX_GLOBAL_DATA::~AFX_GLOBAL_DATA()
1473 void AFX_GLOBAL_DATA::UpdateFonts()
1476 m_dblRibbonImageScale
= dc
.GetDeviceCaps(LOGPIXELSX
) / 96.0f
;
1478 if (m_dblRibbonImageScale
> 1. && m_dblRibbonImageScale
< 1.1)
1480 m_dblRibbonImageScale
= 1.;
1483 if (fontRegular
.GetSafeHandle() != NULL
)
1485 ::DeleteObject(fontRegular
.Detach());
1488 if (fontTooltip
.GetSafeHandle() != NULL
)
1490 ::DeleteObject(fontTooltip
.Detach());
1493 if (fontBold
.GetSafeHandle() != NULL
)
1495 ::DeleteObject(fontBold
.Detach());
1498 if (fontDefaultGUIBold
.GetSafeHandle() != NULL
)
1500 ::DeleteObject(fontDefaultGUIBold
.Detach());
1503 if (fontUnderline
.GetSafeHandle() != NULL
)
1505 ::DeleteObject(fontUnderline
.Detach());
1508 if (fontDefaultGUIUnderline
.GetSafeHandle() != NULL
)
1510 ::DeleteObject(fontDefaultGUIUnderline
.Detach());
1513 if (fontVert
.GetSafeHandle() != NULL
)
1515 ::DeleteObject(fontVert
.Detach());
1518 if (fontVertCaption
.GetSafeHandle() != NULL
)
1520 ::DeleteObject(fontVertCaption
.Detach());
1523 if (fontMarlett
.GetSafeHandle() != NULL
)
1525 ::DeleteObject(fontMarlett
.Detach());
1528 if (fontSmall
.GetSafeHandle() != NULL
)
1530 ::DeleteObject(fontSmall
.Detach());
1533 // Initialize fonts:
1535 NONCLIENTMETRICS info
;
1536 info
.cbSize
= sizeof(info
);
1537 GetNonClientMetrics (info
);
1540 memset(&lf
, 0, sizeof(LOGFONT
));
1542 lf
.lfCharSet
= (BYTE
) GetTextCharsetInfo(dc
.GetSafeHdc(), NULL
, 0);
1544 lf
.lfHeight
= info
.lfMenuFont
.lfHeight
;
1545 lf
.lfWeight
= info
.lfMenuFont
.lfWeight
;
1546 lf
.lfItalic
= info
.lfMenuFont
.lfItalic
;
1548 //------------------
1549 // Adjust font size:
1550 //------------------
1551 int nFontHeight
= lf
.lfHeight
< 0 ? -lf
.lfHeight
: lf
.lfHeight
;
1552 if (nFontHeight
<= 12)
1561 lf
.lfHeight
= (lf
.lfHeight
< 0) ? -nFontHeight
: nFontHeight
;
1563 // Check if we should use system font
1564 lstrcpy(lf
.lfFaceName
, info
.lfMenuFont
.lfFaceName
);
1566 BOOL fUseSystemFont
= m_bUseSystemFont
|| (info
.lfMenuFont
.lfCharSet
> SYMBOL_CHARSET
);
1567 if (!fUseSystemFont
)
1569 // Check for "Segoe UI" or "Tahoma" font existance:
1570 if (::EnumFontFamilies(dc
.GetSafeHdc(), NULL
, FontFamalyProcFonts
, (LPARAM
)(LPCTSTR
) strOffice2007FontName
) == 0)
1572 // Found! Use MS Office 2007 font!
1573 lstrcpy(lf
.lfFaceName
, strOffice2007FontName
);
1574 lf
.lfQuality
= 5 /*CLEARTYPE_QUALITY*/;
1576 else if (::EnumFontFamilies(dc
.GetSafeHdc(), NULL
, FontFamalyProcFonts
, (LPARAM
)(LPCTSTR
) strOfficeFontName
) == 0)
1578 // Found! Use MS Office font!
1579 lstrcpy(lf
.lfFaceName
, strOfficeFontName
);
1583 // Not found. Use default font:
1584 lstrcpy(lf
.lfFaceName
, strDefaultFontName
);
1588 fontRegular
.CreateFontIndirect(&lf
);
1590 // Create small font:
1591 LONG lfHeightSaved
= lf
.lfHeight
;
1593 lf
.lfHeight
= (long)((1. + abs(lf
.lfHeight
)) * 2 / 3);
1594 if (lfHeightSaved
< 0)
1596 lf
.lfHeight
= -lf
.lfHeight
;
1599 fontSmall
.CreateFontIndirect(&lf
);
1600 lf
.lfHeight
= lfHeightSaved
;
1602 // Create tooltip font:
1603 NONCLIENTMETRICS ncm
;
1604 ncm
.cbSize
= sizeof(ncm
);
1605 GetNonClientMetrics (ncm
);
1607 lf
.lfItalic
= ncm
.lfStatusFont
.lfItalic
;
1608 lf
.lfWeight
= ncm
.lfStatusFont
.lfWeight
;
1609 fontTooltip
.CreateFontIndirect(&lf
);
1611 lf
.lfItalic
= info
.lfMenuFont
.lfItalic
;
1612 lf
.lfWeight
= info
.lfMenuFont
.lfWeight
;
1614 // Create "underline" font:
1615 lf
.lfUnderline
= TRUE
;
1616 fontUnderline
.CreateFontIndirect(&lf
);
1617 lf
.lfUnderline
= FALSE
;
1619 // Create bold font:
1620 lf
.lfWeight
= FW_BOLD
;
1621 fontBold
.CreateFontIndirect(&lf
);
1623 // Create Marlett font:
1624 BYTE bCharSet
= lf
.lfCharSet
;
1625 lf
.lfWeight
= info
.lfMenuFont
.lfWeight
;
1626 lf
.lfCharSet
= SYMBOL_CHARSET
;
1628 lf
.lfHeight
= ::GetSystemMetrics(SM_CYMENUCHECK
) - 1;
1629 lstrcpy(lf
.lfFaceName
, strMarlettFontName
);
1631 fontMarlett
.CreateFontIndirect(&lf
);
1632 lf
.lfCharSet
= bCharSet
; // Restore charset
1634 // Create vertical font:
1636 if (font
.CreateStockObject(DEFAULT_GUI_FONT
))
1638 if (font
.GetLogFont(&lf
) != 0)
1640 lf
.lfOrientation
= 900;
1641 lf
.lfEscapement
= 2700;
1643 lf
.lfHeight
= info
.lfMenuFont
.lfHeight
;
1644 lf
.lfWeight
= info
.lfMenuFont
.lfWeight
;
1645 lf
.lfItalic
= info
.lfMenuFont
.lfItalic
;
1648 lstrcpy(lf
.lfFaceName
, strVertFontName
);
1651 fontVert
.CreateFontIndirect(&lf
);
1653 lf
.lfEscapement
= 900;
1654 fontVertCaption
.CreateFontIndirect(&lf
);
1658 // Create dialog underline and bold fonts:
1659 CFont
* pDefaultGUIFont
= CFont::FromHandle((HFONT
) GetStockObject(DEFAULT_GUI_FONT
));
1660 ASSERT_VALID(pDefaultGUIFont
);
1661 pDefaultGUIFont
->GetLogFont(&lf
);
1663 lf
.lfUnderline
= TRUE
;
1664 fontDefaultGUIUnderline
.CreateFontIndirect(&lf
);
1665 lf
.lfUnderline
= FALSE
;
1667 lf
.lfWeight
= FW_BOLD
;
1668 fontDefaultGUIBold
.CreateFontIndirect(&lf
);
1670 UpdateTextMetrics();
1673 // Notify toolbars about font changing:
1674 for (POSITION posTlb
= afxAllToolBars
.GetHeadPosition(); posTlb
!= NULL
;)
1676 CMFCToolBar
* pToolBar
= (CMFCToolBar
*) afxAllToolBars
.GetNext(posTlb
);
1677 ENSURE(pToolBar
!= NULL
);
1679 if (CWnd::FromHandlePermanent(pToolBar
->m_hWnd
) != NULL
)
1681 ASSERT_VALID(pToolBar
);
1682 pToolBar
->OnGlobalFontsChanged();
1688 static BOOL CALLBACK
InfoEnumProc( HMONITOR hMonitor
, HDC
/*hdcMonitor*/, LPRECT
/*lprcMonitor*/, LPARAM dwData
)
1690 CRect
* pRect
= (CRect
*) dwData
;
1693 mi
.cbSize
= sizeof(MONITORINFO
);
1695 if (GetMonitorInfo(hMonitor
, &mi
))
1697 CRect rectMon
= mi
.rcWork
;
1699 pRect
->left
= min(pRect
->left
, rectMon
.left
);
1700 pRect
->right
= max(pRect
->right
, rectMon
.right
);
1701 pRect
->top
= min(pRect
->top
, rectMon
.top
);
1702 pRect
->bottom
= max(pRect
->bottom
, rectMon
.bottom
);
1708 void AFX_GLOBAL_DATA::OnSettingChange()
1710 m_bInSettingChange
= TRUE
;
1712 m_sizeSmallIcon
.cx
= ::GetSystemMetrics(SM_CXSMICON
);
1713 m_sizeSmallIcon
.cy
= ::GetSystemMetrics(SM_CYSMICON
);
1715 m_rectVirtual
.SetRectEmpty();
1717 if (!EnumDisplayMonitors(NULL
, NULL
, InfoEnumProc
, (LPARAM
) &m_rectVirtual
))
1719 ::SystemParametersInfo(SPI_GETWORKAREA
, 0, &m_rectVirtual
, 0);
1722 // Get system menu animation type:
1723 m_bMenuAnimation
= FALSE
;
1724 m_bMenuFadeEffect
= FALSE
;
1726 if (!bIsRemoteSession
)
1728 ::SystemParametersInfo(SPI_GETMENUANIMATION
, 0, &m_bMenuAnimation
, 0);
1730 if (m_bMenuAnimation
)
1732 ::SystemParametersInfo(SPI_GETMENUFADE
, 0, &m_bMenuFadeEffect
, 0);
1736 m_nShellAutohideBars
= 0;
1737 m_bRefreshAutohideBars
= TRUE
;
1739 ::SystemParametersInfo(SPI_GETMENUUNDERLINES
, 0, &m_bSysUnderlineKeyboardShortcuts
, 0);
1740 m_bUnderlineKeyboardShortcuts
= m_bSysUnderlineKeyboardShortcuts
;
1742 m_bInSettingChange
= FALSE
;
1745 void AFX_GLOBAL_DATA::UpdateSysColors()
1747 m_bIsBlackHighContrast
= ::GetSysColor(COLOR_3DLIGHT
) == RGB(255, 255, 255) && ::GetSysColor(COLOR_3DFACE
) == RGB(0, 0, 0);
1748 m_bIsWhiteHighContrast
= ::GetSysColor(COLOR_3DDKSHADOW
) == RGB(0, 0, 0) && ::GetSysColor(COLOR_3DFACE
) == RGB(255, 255, 255);
1751 m_nBitsPerPixel
= dc
.GetDeviceCaps(BITSPIXEL
);
1753 clrBarFace
= clrBtnFace
= ::GetSysColor(COLOR_BTNFACE
);
1754 clrBarShadow
= clrBtnShadow
= ::GetSysColor(COLOR_BTNSHADOW
);
1755 clrBarDkShadow
= clrBtnDkShadow
= ::GetSysColor(COLOR_3DDKSHADOW
);
1756 clrBarLight
= clrBtnLight
= ::GetSysColor(COLOR_3DLIGHT
);
1757 clrBarHilite
= clrBtnHilite
= ::GetSysColor(COLOR_BTNHIGHLIGHT
);
1758 clrBarText
= clrBtnText
= ::GetSysColor(COLOR_BTNTEXT
);
1759 clrGrayedText
= ::GetSysColor(COLOR_GRAYTEXT
);
1760 clrWindowFrame
= ::GetSysColor(COLOR_WINDOWFRAME
);
1762 clrHilite
= ::GetSysColor(COLOR_HIGHLIGHT
);
1763 clrTextHilite
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
1765 clrBarWindow
= clrWindow
= ::GetSysColor(COLOR_WINDOW
);
1766 clrWindowText
= ::GetSysColor(COLOR_WINDOWTEXT
);
1768 clrCaptionText
= ::GetSysColor(COLOR_CAPTIONTEXT
);
1769 clrMenuText
= ::GetSysColor(COLOR_MENUTEXT
);
1771 clrActiveCaption
= ::GetSysColor(COLOR_ACTIVECAPTION
);
1772 clrInactiveCaption
= ::GetSysColor(COLOR_INACTIVECAPTION
);
1774 clrActiveCaptionGradient
= ::GetSysColor(COLOR_GRADIENTACTIVECAPTION
);
1775 clrInactiveCaptionGradient
= ::GetSysColor(COLOR_GRADIENTINACTIVECAPTION
);
1777 clrActiveBorder
= ::GetSysColor(COLOR_ACTIVEBORDER
);
1778 clrInactiveBorder
= ::GetSysColor(COLOR_INACTIVEBORDER
);
1780 clrInactiveCaptionText
= ::GetSysColor(COLOR_INACTIVECAPTIONTEXT
);
1782 if (m_bIsBlackHighContrast
)
1784 clrHotLinkNormalText
= clrWindowText
;
1785 clrHotLinkHoveredText
= clrWindowText
;
1786 clrHotLinkVisitedText
= clrWindowText
;
1790 clrHotLinkNormalText
= ::GetSysColor(COLOR_HOTLIGHT
);
1791 clrHotLinkHoveredText
= RGB(0, 0, 255); // Bright blue
1792 clrHotLinkVisitedText
= RGB(128, 0, 128); // Violet
1795 hbrBtnShadow
= ::GetSysColorBrush(COLOR_BTNSHADOW
);
1796 ENSURE(hbrBtnShadow
!= NULL
);
1798 hbrBtnHilite
= ::GetSysColorBrush(COLOR_BTNHIGHLIGHT
);
1799 ENSURE(hbrBtnHilite
!= NULL
);
1801 hbrWindow
= ::GetSysColorBrush(COLOR_WINDOW
);
1802 ENSURE(hbrWindow
!= NULL
);
1804 brBtnFace
.DeleteObject();
1805 brBtnFace
.CreateSolidBrush(clrBtnFace
);
1807 brBarFace
.DeleteObject();
1808 brBarFace
.CreateSolidBrush(clrBarFace
);
1810 brActiveCaption
.DeleteObject();
1811 brActiveCaption
.CreateSolidBrush(clrActiveCaption
);
1813 brInactiveCaption
.DeleteObject();
1814 brInactiveCaption
.CreateSolidBrush(clrInactiveCaption
);
1816 brHilite
.DeleteObject();
1817 brHilite
.CreateSolidBrush(clrHilite
);
1819 brBlack
.DeleteObject();
1820 brBlack
.CreateSolidBrush(clrBtnDkShadow
);
1822 brWindow
.DeleteObject();
1823 brWindow
.CreateSolidBrush(clrWindow
);
1825 penHilite
.DeleteObject();
1826 penHilite
.CreatePen(PS_SOLID
, 1, afxGlobalData
.clrHilite
);
1828 penBarFace
.DeleteObject();
1829 penBarFace
.CreatePen(PS_SOLID
, 1, afxGlobalData
.clrBarFace
);
1831 penBarShadow
.DeleteObject();
1832 penBarShadow
.CreatePen(PS_SOLID
, 1, afxGlobalData
.clrBarShadow
);
1834 if (brLight
.GetSafeHandle())
1836 brLight
.DeleteObject();
1839 if (m_nBitsPerPixel
> 8)
1841 COLORREF clrLight
= RGB(GetRValue(clrBtnFace
) +((GetRValue(clrBtnHilite
) - GetRValue(clrBtnFace
)) / 2 ),
1842 GetGValue(clrBtnFace
) +((GetGValue(clrBtnHilite
) - GetGValue(clrBtnFace
)) / 2),
1843 GetBValue(clrBtnFace
) +((GetBValue(clrBtnHilite
) - GetBValue(clrBtnFace
)) / 2));
1845 brLight
.CreateSolidBrush(clrLight
);
1849 HBITMAP hbmGray
= CreateDitherBitmap(dc
.GetSafeHdc());
1850 ENSURE(hbmGray
!= NULL
);
1853 bmp
.Attach(hbmGray
);
1855 brLight
.CreatePatternBrush(&bmp
);
1858 // CMenuImages::CleanUp();
1859 // CDockingManager::m_bSDParamsModified = TRUE;
1862 BOOL
AFX_GLOBAL_DATA::SetMenuFont(LPLOGFONT lpLogFont
, BOOL bHorz
)
1864 ENSURE(lpLogFont
!= NULL
);
1868 // Create regular font:
1869 fontRegular
.DeleteObject();
1870 if (!fontRegular
.CreateFontIndirect(lpLogFont
))
1876 // Create underline font:
1877 lpLogFont
->lfUnderline
= TRUE
;
1878 fontUnderline
.DeleteObject();
1879 fontUnderline
.CreateFontIndirect(lpLogFont
);
1880 lpLogFont
->lfUnderline
= FALSE
;
1882 // Create bold font(used in the default menu items):
1883 long lSavedWeight
= lpLogFont
->lfWeight
;
1884 lpLogFont
->lfWeight
= 700;
1886 fontBold
.DeleteObject();
1887 BOOL bResult
= fontBold
.CreateFontIndirect(lpLogFont
);
1889 lpLogFont
->lfWeight
= lSavedWeight
; // Restore weight
1897 else // Vertical font
1899 fontVert
.DeleteObject();
1900 if (!fontVert
.CreateFontIndirect(lpLogFont
))
1907 UpdateTextMetrics();
1911 void AFX_GLOBAL_DATA::UpdateTextMetrics()
1915 CFont
* pOldFont
= dc
.SelectObject(&fontRegular
);
1916 ENSURE(pOldFont
!= NULL
);
1919 dc
.GetTextMetrics(&tm
);
1921 int nExtra
= tm
.tmHeight
< 15 ? 2 : 5;
1923 m_nTextHeightHorz
= tm
.tmHeight
+ nExtra
;
1924 m_nTextWidthHorz
= tm
.tmMaxCharWidth
+ nExtra
;
1926 dc
.SelectObject(&fontVert
);
1927 dc
.GetTextMetrics(&tm
);
1929 nExtra
= tm
.tmHeight
< 15 ? 2 : 5;
1931 m_nTextHeightVert
= tm
.tmHeight
+ nExtra
;
1932 m_nTextWidthVert
= tm
.tmMaxCharWidth
+ nExtra
;
1934 dc
.SelectObject(pOldFont
);
1937 HBITMAP
AFX_GLOBAL_DATA::CreateDitherBitmap(HDC hDC
)
1939 struct // BITMAPINFO with 16 colors
1941 BITMAPINFOHEADER bmiHeader
;
1942 RGBQUAD bmiColors
[16];
1945 memset(&bmi
, 0, sizeof(bmi
));
1947 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1948 bmi
.bmiHeader
.biWidth
= 8;
1949 bmi
.bmiHeader
.biHeight
= 8;
1950 bmi
.bmiHeader
.biPlanes
= 1;
1951 bmi
.bmiHeader
.biBitCount
= 1;
1952 bmi
.bmiHeader
.biCompression
= BI_RGB
;
1954 COLORREF clr
= afxGlobalData
.clrBtnFace
;
1956 bmi
.bmiColors
[0].rgbBlue
= GetBValue(clr
);
1957 bmi
.bmiColors
[0].rgbGreen
= GetGValue(clr
);
1958 bmi
.bmiColors
[0].rgbRed
= GetRValue(clr
);
1960 clr
= ::GetSysColor(COLOR_BTNHIGHLIGHT
);
1961 bmi
.bmiColors
[1].rgbBlue
= GetBValue(clr
);
1962 bmi
.bmiColors
[1].rgbGreen
= GetGValue(clr
);
1963 bmi
.bmiColors
[1].rgbRed
= GetRValue(clr
);
1965 // initialize the brushes
1967 for (int i
= 0; i
< 8; i
++)
1968 patGray
[i
] = (i
& 1) ? 0xAAAA5555L
: 0x5555AAAAL
;
1970 HBITMAP hbm
= CreateDIBitmap(hDC
, &bmi
.bmiHeader
, CBM_INIT
, (LPBYTE
)patGray
, (LPBITMAPINFO
)&bmi
, DIB_RGB_COLORS
);
1974 #if (WINVER >= 0x0601)
1975 ITaskbarList
* AFX_GLOBAL_DATA::GetITaskbarList()
1979 if (!bIsWindows7
|| !m_bTaskBarInterfacesAvailable
)
1984 if (m_pTaskbarList
!= NULL
)
1986 return m_pTaskbarList
;
1989 if (!m_bComInitialized
)
1991 hr
= CoInitialize(NULL
);
1994 m_bComInitialized
= TRUE
;
2000 hr
= CoCreateInstance(CLSID_TaskbarList
, NULL
, CLSCTX_INPROC_SERVER
, IID_PPV_ARGS(&m_pTaskbarList
));
2003 ASSERT(SUCCEEDED(hr
));
2004 return m_pTaskbarList
;
2007 ITaskbarList3
* AFX_GLOBAL_DATA::GetITaskbarList3()
2011 if (!bIsWindows7
|| !m_bTaskBarInterfacesAvailable
)
2016 if (m_pTaskbarList3
!= NULL
)
2018 return m_pTaskbarList3
;
2021 if (!m_bComInitialized
)
2023 hr
= CoInitialize(NULL
);
2026 m_bComInitialized
= TRUE
;
2032 hr
= CoCreateInstance(CLSID_TaskbarList
, NULL
, CLSCTX_INPROC_SERVER
, IID_PPV_ARGS(&m_pTaskbarList3
));
2035 ASSERT(SUCCEEDED(hr
));
2036 return m_pTaskbarList3
;
2039 void AFX_GLOBAL_DATA::ReleaseTaskBarRefs()
2041 m_bTaskBarInterfacesAvailable
= FALSE
;
2043 if (m_pTaskbarList
!= NULL
)
2045 RELEASE(m_pTaskbarList
);
2046 m_pTaskbarList
= NULL
;
2049 if (m_pTaskbarList3
!= NULL
)
2051 RELEASE(m_pTaskbarList3
);
2052 m_pTaskbarList3
= NULL
;
2057 void AFX_GLOBAL_DATA::CleanUp()
2059 if (brLight
.GetSafeHandle())
2061 brLight
.DeleteObject();
2065 fontRegular
.DeleteObject();
2066 fontBold
.DeleteObject();
2067 fontUnderline
.DeleteObject();
2068 fontVert
.DeleteObject();
2069 fontVertCaption
.DeleteObject();
2070 fontTooltip
.DeleteObject();
2072 ReleaseTaskBarRefs();
2075 if (m_bBufferedPaintInited
&& m_pfBufferedPaintUnInit
!= NULL
)
2077 m_pfBufferedPaintUnInit();
2078 m_bBufferedPaintInited
= FALSE
;
2081 if (m_hinstUXThemeDLL
!= NULL
)
2083 ::FreeLibrary(m_hinstUXThemeDLL
);
2084 m_hinstUXThemeDLL
= NULL
;
2087 if (m_hinstDwmapiDLL
!= NULL
)
2089 ::FreeLibrary(m_hinstDwmapiDLL
);
2090 m_hinstDwmapiDLL
= NULL
;
2093 m_bEnableAccessibility
= FALSE
;
2095 if (m_bComInitialized
)
2098 m_bComInitialized
= FALSE
;
2102 void ControlBarCleanUp()
2104 afxGlobalData
.CleanUp();
2106 // afxMenuHash.CleanUp();
2108 // CMFCToolBar::CleanUpImages();
2109 // CMenuImages::CleanUp();
2111 // if (GetCmdMgr() != NULL)
2113 // GetCmdMgr()->CleanUp();
2116 // CKeyboardManager::CleanUp();
2118 // Destroy visualization manager:
2119 // CMFCVisualManager::DestroyInstance(TRUE /* bAutoDestroyOnly */);
2120 // CMFCVisualManagerOffice2007::CleanStyle();
2124 void AfxGlobalsAddRef()
2126 g_dwAfxGlobalDataRef
++;
2129 void AfxGlobalsRelease()
2131 g_dwAfxGlobalDataRef
--;
2132 if (g_dwAfxGlobalDataRef
== 0)
2134 ControlBarCleanUp();
2139 BOOL
AFX_GLOBAL_DATA::DrawParentBackground(CWnd
* pWnd
, CDC
* pDC
, LPRECT rectClip
)
2147 if (rectClip
!= NULL
)
2149 rgn
.CreateRectRgnIndirect(rectClip
);
2150 pDC
->SelectClipRgn(&rgn
);
2153 CWnd
* pParent
= pWnd
->GetParent();
2154 ASSERT_VALID(pParent
);
2156 // In Windows XP, we need to call DrawThemeParentBackground function to implement
2157 // transparent controls
2158 if (m_pfDrawThemeBackground
!= NULL
)
2160 bRes
= (*m_pfDrawThemeBackground
)(pWnd
->GetSafeHwnd(), pDC
->GetSafeHdc(), rectClip
) == S_OK
;
2166 pWnd
->MapWindowPoints(pParent
, &pt
, 1);
2167 pt
= pDC
->OffsetWindowOrg(pt
.x
, pt
.y
);
2169 bRes
= (BOOL
) pParent
->SendMessage(WM_ERASEBKGND
, (WPARAM
)pDC
->m_hDC
);
2171 pDC
->SetWindowOrg(pt
.x
, pt
.y
);
2174 pDC
->SelectClipRgn(NULL
);
2179 CFrameWnd
* AFXGetParentFrame(const CWnd
* pWnd
)
2181 if (pWnd
->GetSafeHwnd() == NULL
)
2187 const CWnd
* pParentWnd
= pWnd
;
2189 while (pParentWnd
!= NULL
)
2191 // if (pParentWnd->IsKindOf(RUNTIME_CLASS(CPaneFrameWnd)))
2193 // CPaneFrameWnd* pMiniFrame = DYNAMIC_DOWNCAST(CPaneFrameWnd, pParentWnd);
2194 // pParentWnd = pMiniFrame->GetParent();
2198 pParentWnd
= pParentWnd
->GetParent();
2201 if (pParentWnd
== NULL
)
2206 if (pParentWnd
->IsFrameWnd())
2208 return(CFrameWnd
*)pParentWnd
;
2215 COLORREF
AFX_GLOBAL_DATA::GetColor(int nColor
)
2219 case COLOR_BTNFACE
: return clrBtnFace
;
2220 case COLOR_BTNSHADOW
: return clrBtnShadow
;
2221 case COLOR_3DDKSHADOW
: return clrBtnDkShadow
;
2222 case COLOR_3DLIGHT
: return clrBtnLight
;
2223 case COLOR_BTNHIGHLIGHT
: return clrBtnHilite
;
2224 case COLOR_BTNTEXT
: return clrBtnText
;
2225 case COLOR_GRAYTEXT
: return clrGrayedText
;
2226 case COLOR_WINDOWFRAME
: return clrWindowFrame
;
2228 case COLOR_HIGHLIGHT
: return clrHilite
;
2229 case COLOR_HIGHLIGHTTEXT
: return clrTextHilite
;
2231 case COLOR_WINDOW
: return clrWindow
;
2232 case COLOR_WINDOWTEXT
: return clrWindowText
;
2234 case COLOR_CAPTIONTEXT
: return clrCaptionText
;
2235 case COLOR_MENUTEXT
: return clrMenuText
;
2237 case COLOR_ACTIVECAPTION
: return clrActiveCaption
;
2238 case COLOR_INACTIVECAPTION
: return clrInactiveCaption
;
2240 case COLOR_ACTIVEBORDER
: return clrActiveBorder
;
2241 case COLOR_INACTIVEBORDER
: return clrInactiveBorder
;
2243 case COLOR_INACTIVECAPTIONTEXT
: return clrInactiveCaptionText
;
2246 return ::GetSysColor(nColor
);
2249 BOOL
AFX_GLOBAL_DATA::SetLayeredAttrib(HWND hwnd
, COLORREF crKey
, BYTE bAlpha
, DWORD dwFlags
)
2251 return(::SetLayeredWindowAttributes(hwnd
, crKey
, bAlpha
, dwFlags
));
2254 void AFX_GLOBAL_DATA::EnableAccessibilitySupport(BOOL bEnable
/* = TRUE*/)
2256 m_bEnableAccessibility
= bEnable
;
2259 CString
AFX_GLOBAL_DATA::RegisterWindowClass(LPCTSTR lpszClassNamePrefix
)
2261 ENSURE(lpszClassNamePrefix
!= NULL
);
2263 // Register a new window class:
2264 HINSTANCE hInst
= AfxGetInstanceHandle();
2265 UINT uiClassStyle
= CS_DBLCLKS
;
2266 HCURSOR hCursor
= ::LoadCursor(NULL
, IDC_ARROW
);
2267 HBRUSH hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
2269 CString strClassName
;
2270 strClassName
.Format(_T("%s:%x:%x:%x:%x"), lpszClassNamePrefix
, (UINT_PTR
)hInst
, uiClassStyle
, (UINT_PTR
)hCursor
, (UINT_PTR
)hbrBackground
);
2272 // See if the class already exists:
2274 if (::GetClassInfo(hInst
, strClassName
, &wndcls
))
2276 // Already registered, assert everything is good:
2277 ASSERT(wndcls
.style
== uiClassStyle
);
2281 // Otherwise we need to register a new class:
2282 wndcls
.style
= uiClassStyle
;
2283 wndcls
.lpfnWndProc
= ::DefWindowProc
;
2284 wndcls
.cbClsExtra
= wndcls
.cbWndExtra
= 0;
2285 wndcls
.hInstance
= hInst
;
2286 wndcls
.hIcon
= NULL
;
2287 wndcls
.hCursor
= hCursor
;
2288 wndcls
.hbrBackground
= hbrBackground
;
2289 wndcls
.lpszMenuName
= NULL
;
2290 wndcls
.lpszClassName
= strClassName
;
2292 if (!AfxRegisterClass(&wndcls
))
2294 AfxThrowResourceException();
2298 return strClassName
;
2301 BOOL
AFX_GLOBAL_DATA::ExcludeTag(CString
& strBuffer
, LPCTSTR lpszTag
, CString
& strTag
, BOOL bIsCharsList
/* = FALSE*/)
2303 const int iBufLen
= strBuffer
.GetLength();
2305 CString strTagStart
= _T("<");
2306 strTagStart
+= lpszTag
;
2307 strTagStart
+= _T(">");
2309 const int iTagStartLen
= strTagStart
.GetLength();
2313 int iIndexStart
= strBuffer
.Find(strTagStart
);
2314 if (iIndexStart
< 0)
2319 iStart
= iIndexStart
+ iTagStartLen
;
2321 CString strTagEnd
= _T("</");
2322 strTagEnd
+= lpszTag
;
2323 strTagEnd
+= _T('>');
2325 const int iTagEndLen
= strTagEnd
.GetLength();
2329 for (int i
= iStart
; i
< iBufLen
- iTagEndLen
+ 1; i
++)
2331 if (strBuffer
[i
] != '<')
2336 if (i
< iBufLen
- iTagStartLen
&& _tcsncmp(strBuffer
.Mid(i
), strTagStart
, iTagStartLen
) == 0)
2338 i
+= iTagStartLen
- 1;
2343 if (_tcsncmp(strBuffer
.Mid(i
), strTagEnd
, iTagEndLen
) == 0)
2352 i
+= iTagEndLen
- 1;
2356 if (iIndexEnd
== -1 || iStart
> iIndexEnd
)
2361 strTag
= strBuffer
.Mid(iStart
, iIndexEnd
- iStart
);
2365 strBuffer
.Delete(iIndexStart
, iIndexEnd
+ iTagEndLen
- iIndexStart
);
2369 if (strTag
.GetLength() > 1 && strTag
[0] == _T('\"'))
2371 strTag
= strTag
.Mid(1, strTag
.GetLength() - 2);
2374 strTag
.Replace(_T("\\t"), _T("\t"));
2375 strTag
.Replace(_T("\\n"), _T("\n"));
2376 strTag
.Replace(_T("\\r"), _T("\r"));
2377 strTag
.Replace(_T("\\b"), _T("\b"));
2378 strTag
.Replace(_T("LT"), _T("<"));
2379 strTag
.Replace(_T("GT"), _T(">"));
2380 strTag
.Replace(_T("AMP"), _T("&"));
2386 BOOL
AFX_GLOBAL_DATA::DwmExtendFrameIntoClientArea(HWND hWnd
, AFX_MARGINS
* pMargins
)
2388 if (m_pfDwmExtendFrameIntoClientArea
== NULL
)
2393 HRESULT hres
= (*m_pfDwmExtendFrameIntoClientArea
)(hWnd
, pMargins
);
2394 return hres
== S_OK
;
2397 LRESULT
AFX_GLOBAL_DATA::DwmDefWindowProc(HWND hWnd
, UINT message
, WPARAM wp
, LPARAM lp
)
2399 if (m_pfDwmDefWindowProc
== NULL
)
2405 (*m_pfDwmDefWindowProc
)(hWnd
, message
, wp
, lp
, &lres
);
2410 BOOL
AFX_GLOBAL_DATA::DwmIsCompositionEnabled()
2412 if (m_pfDwmIsCompositionEnabled
== NULL
|| bDisableAero
)
2417 BOOL bEnabled
= FALSE
;
2419 (*m_pfDwmIsCompositionEnabled
)(&bEnabled
);
2423 BOOL
AFX_GLOBAL_DATA::DrawTextOnGlass(HTHEME hTheme
, CDC
* pDC
, int iPartId
, int iStateId
, CString strText
, CRect rect
, DWORD dwFlags
, int nGlowSize
, COLORREF clrText
)
2425 //---- bits used in dwFlags of DTTOPTS ----
2426 #define AFX_DTT_TEXTCOLOR (1UL << 0) // crText has been specified
2427 #define AFX_DTT_BORDERCOLOR (1UL << 1) // crBorder has been specified
2428 #define AFX_DTT_SHADOWCOLOR (1UL << 2) // crShadow has been specified
2429 #define AFX_DTT_SHADOWTYPE (1UL << 3) // iTextShadowType has been specified
2430 #define AFX_DTT_SHADOWOFFSET (1UL << 4) // ptShadowOffset has been specified
2431 #define AFX_DTT_BORDERSIZE (1UL << 5) // nBorderSize has been specified
2432 #define AFX_DTT_FONTPROP (1UL << 6) // iFontPropId has been specified
2433 #define AFX_DTT_COLORPROP (1UL << 7) // iColorPropId has been specified
2434 #define AFX_DTT_STATEID (1UL << 8) // IStateId has been specified
2435 #define AFX_DTT_CALCRECT (1UL << 9) // Use pRect as and in/out parameter
2436 #define AFX_DTT_APPLYOVERLAY (1UL << 10) // fApplyOverlay has been specified
2437 #define AFX_DTT_GLOWSIZE (1UL << 11) // iGlowSize has been specified
2438 #define AFX_DTT_CALLBACK (1UL << 12) // pfnDrawTextCallback has been specified
2439 #define AFX_DTT_COMPOSITED (1UL << 13) // Draws text with antialiased alpha(needs a DIB section)
2441 if (hTheme
== NULL
|| m_pfDrawThemeTextEx
== NULL
|| !DwmIsCompositionEnabled())
2443 pDC
->DrawText(strText
, rect
, dwFlags
);
2447 CComBSTR bstmp
= (LPCTSTR
)strText
;
2449 wchar_t* wbuf
= new wchar_t[bstmp
.Length() + 1];
2450 wcscpy_s(wbuf
, bstmp
.Length() + 1, bstmp
);
2453 memset(&dto
, 0, sizeof(AFX_DTTOPTS
));
2454 dto
.dwSize
= sizeof(AFX_DTTOPTS
);
2455 dto
.dwFlags
= AFX_DTT_COMPOSITED
;
2459 dto
.dwFlags
|= AFX_DTT_GLOWSIZE
;
2460 dto
.iGlowSize
= nGlowSize
;
2463 if (clrText
!= (COLORREF
)-1)
2465 dto
.dwFlags
|= AFX_DTT_TEXTCOLOR
;
2466 dto
.crText
= clrText
;
2469 (*m_pfDrawThemeTextEx
)(hTheme
, pDC
->GetSafeHdc(), iPartId
, iStateId
, wbuf
, -1, dwFlags
, rect
, &dto
);
2476 HCURSOR
AFX_GLOBAL_DATA::GetHandCursor()
2478 if (m_hcurHand
== NULL
)
2480 m_hcurHand
= ::LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_HAND
));
2486 BOOL
AFX_GLOBAL_DATA::Resume()
2488 m_hinstUXThemeDLL
= ::AfxCtxLoadLibraryW(L
"UxTheme.dll");
2490 if (m_hinstUXThemeDLL
!= NULL
)
2492 m_pfDrawThemeBackground
= (DRAWTHEMEPARENTBACKGROUND
)::GetProcAddress (m_hinstUXThemeDLL
, "DrawThemeParentBackground");
2493 m_pfDrawThemeTextEx
= (DRAWTHEMETEXTEX
)::GetProcAddress (m_hinstUXThemeDLL
, "DrawThemeTextEx");
2494 m_pfBeginBufferedPaint
= (BEGINBUFFEREDPAINT
)::GetProcAddress (m_hinstUXThemeDLL
, "BeginBufferedPaint");
2495 m_pfEndBufferedPaint
= (ENDBUFFEREDPAINT
)::GetProcAddress (m_hinstUXThemeDLL
, "EndBufferedPaint");
2499 m_pfDrawThemeBackground
= NULL
;
2500 m_pfDrawThemeTextEx
= NULL
;
2501 m_pfBeginBufferedPaint
= NULL
;
2502 m_pfEndBufferedPaint
= NULL
;
2505 if (m_hinstDwmapiDLL
!= NULL
)
2507 m_hinstDwmapiDLL
= AfxLoadSystemLibraryUsingFullPath(L
"dwmapi.dll");
2508 ENSURE(m_hinstDwmapiDLL
!= NULL
);
2510 m_pfDwmExtendFrameIntoClientArea
= (DWMEXTENDFRAMEINTOCLIENTAREA
)::GetProcAddress (m_hinstDwmapiDLL
, "DwmExtendFrameIntoClientArea");
2511 m_pfDwmDefWindowProc
= (DWMDEFWINDOWPROC
) ::GetProcAddress (m_hinstDwmapiDLL
, "DwmDefWindowProc");
2512 m_pfDwmIsCompositionEnabled
= (DWMISCOMPOSITIONENABLED
)::GetProcAddress (m_hinstDwmapiDLL
, "DwmIsCompositionEnabled");
2515 if (m_bEnableAccessibility
)
2517 EnableAccessibilitySupport();
2520 // CMFCVisualManagerOffice2007::CleanStyle ();
2522 // if (CMFCVisualManager::m_pRTIDefault != NULL)
2524 // CMFCVisualManager::SetDefaultManager (CMFCVisualManager::m_pRTIDefault);
2530 BOOL
AFX_GLOBAL_DATA::GetNonClientMetrics (NONCLIENTMETRICS
& info
)
2532 struct AFX_OLDNONCLIENTMETRICS
2540 LOGFONT lfCaptionFont
;
2541 int iSmCaptionWidth
;
2542 int iSmCaptionHeight
;
2543 LOGFONT lfSmCaptionFont
;
2547 LOGFONT lfStatusFont
;
2548 LOGFONT lfMessageFont
;
2551 if (_AfxGetComCtlVersion() < MAKELONG(1, 6))
2553 info
.cbSize
= sizeof(AFX_OLDNONCLIENTMETRICS
);
2556 return ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, info
.cbSize
, &info
, 0);
2560 BOOL AFXAPI
AfxIsExtendedFrameClass(CWnd
* pWnd
)
2564 if (pWnd
->IsKindOf(RUNTIME_CLASS(CFrameWndEx
)))
2568 if (pWnd
->IsKindOf(RUNTIME_CLASS(CMDIFrameWndEx
)))
2572 if (pWnd
->IsKindOf(RUNTIME_CLASS(COleIPFrameWndEx
)))
2576 if (pWnd
->IsKindOf(RUNTIME_CLASS(COleDocIPFrameWndEx
)))
2580 if (pWnd
->IsKindOf(RUNTIME_CLASS(CMDIChildWndEx
)))
2589 BOOL AFXAPI
AfxIsMFCToolBar(CWnd
* pWnd
)
2592 // if (pWnd->IsKindOf(RUNTIME_CLASS(CMFCToolBar)))
2599 HRESULT
AFX_GLOBAL_DATA::ShellCreateItemFromParsingName(PCWSTR pszPath
, IBindCtx
*pbc
, REFIID riid
, void **ppv
)
2601 static HMODULE hShellDll
= AfxCtxLoadLibrary(_T("Shell32.dll"));
2602 ENSURE(hShellDll
!= NULL
);
2604 typedef HRESULT (__stdcall
*PFNSHCREATEITEMFROMPARSINGNAME
)(
2611 PFNSHCREATEITEMFROMPARSINGNAME pSHCreateItemFromParsingName
=
2612 (PFNSHCREATEITEMFROMPARSINGNAME
)GetProcAddress(hShellDll
, "SHCreateItemFromParsingName");
2613 if (pSHCreateItemFromParsingName
== NULL
)
2618 return (*pSHCreateItemFromParsingName
)(pszPath
, pbc
, riid
, ppv
);
2621 BOOL
AFX_GLOBAL_DATA::InitD2D(D2D1_FACTORY_TYPE d2dFactoryType
, DWRITE_FACTORY_TYPE writeFactoryType
)
2623 if (m_bD2DInitialized
)
2630 if (!m_bComInitialized
)
2632 hr
= CoInitialize(NULL
);
2639 m_bComInitialized
= TRUE
;
2641 if ((m_hinstD2DDLL
= AfxLoadSystemLibraryUsingFullPath(L
"D2D1.dll")) == NULL
)
2646 typedef HRESULT (WINAPI
* D2D1CREATEFACTORY
)(D2D1_FACTORY_TYPE factoryType
, REFIID riid
, CONST D2D1_FACTORY_OPTIONS
*pFactoryOptions
, void **ppIFactory
);
2647 typedef HRESULT (WINAPI
* DWRITECREATEFACTORY
)(DWRITE_FACTORY_TYPE factoryType
, REFIID riid
, IUnknown
**factory
);
2649 D2D1CREATEFACTORY pfD2D1CreateFactory
= (D2D1CREATEFACTORY
)::GetProcAddress(m_hinstD2DDLL
, "D2D1CreateFactory");
2650 if (pfD2D1CreateFactory
!= NULL
)
2652 hr
= (*pfD2D1CreateFactory
)(d2dFactoryType
, __uuidof(ID2D1Factory
),
2653 NULL
, reinterpret_cast<void **>(&m_pDirect2dFactory
));
2656 m_pDirect2dFactory
= NULL
;
2661 m_pfD2D1MakeRotateMatrix
= (D2D1MAKEROTATEMATRIX
)::GetProcAddress(m_hinstD2DDLL
, "D2D1MakeRotateMatrix");
2663 m_hinstDWriteDLL
= AfxLoadSystemLibraryUsingFullPath(L
"DWrite.dll");
2664 if (m_hinstDWriteDLL
!= NULL
)
2666 DWRITECREATEFACTORY pfD2D1CreateFactory
= (DWRITECREATEFACTORY
)::GetProcAddress(m_hinstDWriteDLL
, "DWriteCreateFactory");
2667 if (pfD2D1CreateFactory
!= NULL
)
2669 hr
= (*pfD2D1CreateFactory
)(writeFactoryType
, __uuidof(IDWriteFactory
), (IUnknown
**)&m_pWriteFactory
);
2673 hr
= CoCreateInstance(CLSID_WICImagingFactory
, NULL
, CLSCTX_INPROC_SERVER
, IID_IWICImagingFactory
, (LPVOID
*)&m_pWicFactory
);
2675 m_bD2DInitialized
= TRUE
;
2679 void AFX_GLOBAL_DATA::ReleaseD2DRefs()
2681 if (!m_bD2DInitialized
)
2686 if (m_pDirect2dFactory
!= NULL
)
2688 m_pDirect2dFactory
->Release();
2689 m_pDirect2dFactory
= NULL
;
2692 if (m_pWriteFactory
!= NULL
)
2694 m_pWriteFactory
->Release();
2695 m_pWriteFactory
= NULL
;
2698 if (m_pWicFactory
!= NULL
)
2700 m_pWicFactory
->Release();
2701 m_pWicFactory
= NULL
;
2704 if (m_hinstD2DDLL
!= NULL
)
2706 ::FreeLibrary(m_hinstD2DDLL
);
2709 if (m_hinstDWriteDLL
!= NULL
)
2711 ::FreeLibrary(m_hinstDWriteDLL
);
2714 m_bD2DInitialized
= FALSE
;