// FontComboDlg.cpp // // (c)1998-2025 Codejock Software, All Rights Reserved. // // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN // CONSENT OF CODEJOCK SOFTWARE. // // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A // SINGLE COMPUTER. // // CONTACT INFORMATION: // support@codejock.com // http://www.codejock.com // ///////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "FontCombo.h" #include "FontComboDlg.h" #ifdef _DEBUG # define new DEBUG_NEW # undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CFontComboDlg dialog CFontComboDlg::CFontComboDlg(CWnd* pParent /*=NULL*/) : CDialog(CFontComboDlg::IDD, pParent) { //{{AFX_DATA_INIT(CFontComboDlg) m_bBold = FALSE; m_bItalic = FALSE; m_bUnderline = FALSE; //}}AFX_DATA_INIT m_crCurrent = COLORREF_NULL; // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_crBackground = 0; CXTPRegistryManager regMgr; m_bBold = regMgr.GetProfileInt(_T("Settings"), _T("m_bBold"), TRUE); m_bItalic = regMgr.GetProfileInt(_T("Settings"), _T("m_bItalic"), FALSE); m_bUnderline = regMgr.GetProfileInt(_T("Settings"), _T("m_bUnderline"), FALSE); m_strFontSize = regMgr.GetProfileString(_T("Settings"), _T("m_strFontSize"), _T("36")); m_strFontName = regMgr.GetProfileString(_T("Settings"), _T("m_strFontName"), _T("Verdana")); m_crCurrent = regMgr.GetProfileInt(_T("Settings"), _T("m_crCurrent"), CLR_DEFAULT); } CFontComboDlg::~CFontComboDlg() { CXTPRegistryManager regMgr; regMgr.WriteProfileInt(_T("Settings"), _T("m_bBold"), m_bBold); regMgr.WriteProfileInt(_T("Settings"), _T("m_bItalic"), m_bItalic); regMgr.WriteProfileInt(_T("Settings"), _T("m_bUnderline"), m_bUnderline); regMgr.WriteProfileString(_T("Settings"), _T("m_strFontSize"), m_strFontSize); regMgr.WriteProfileString(_T("Settings"), _T("m_strFontName"), m_strFontName); regMgr.WriteProfileInt(_T("Settings"), _T("m_crCurrent"), m_crCurrent); } void CFontComboDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CFontComboDlg) DDX_Control(pDX, IDC_TXT_SAMPLE, m_txtSample); DDX_Control(pDX, IDC_COMBO_THEME, m_wndComboTheme); DDX_Control(pDX, IDC_COMBO_SIZE, m_wndComboSize); DDX_Control(pDX, IDC_COMBO_FONT, m_wndComboFont); DDX_Control(pDX, IDC_COLOR_FONT, m_wndColorPicker); DDX_Control(pDX, IDC_CHK_BOLD, m_btnBold); DDX_Control(pDX, IDC_CHK_ITALIC, m_btnItalic); DDX_Control(pDX, IDC_CHK_UNDERLINE, m_btnUnderline); DDX_Control(pDX, IDCANCEL, m_btnCancel); DDX_Check(pDX, IDC_CHK_BOLD, m_bBold); DDX_Check(pDX, IDC_CHK_ITALIC, m_bItalic); DDX_Check(pDX, IDC_CHK_UNDERLINE, m_bUnderline); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CFontComboDlg, CDialog) //{{AFX_MSG_MAP(CFontComboDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_WM_CTLCOLOR() ON_CBN_SELENDOK(IDC_COMBO_THEME, OnThemeChanged) ON_CBN_SELENDOK(IDC_COMBO_SIZE, OnSelendokComboSize) ON_BN_CLICKED(IDC_CHK_BOLD, OnChkBold) ON_BN_CLICKED(IDC_CHK_ITALIC, OnChkItalic) ON_BN_CLICKED(IDC_CHK_UNDERLINE, OnChkUnderline) ON_CPN_XTP_SELENDOK(IDC_COLOR_FONT, OnSelEndOKColor) ON_CBN_SELENDOK(IDC_COMBO_FONT, OnSelEndOKFontCombo) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CFontComboDlg message handlers BOOL CFontComboDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. _ASSERTE((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); _ASSERTE(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the default font for all dialog controls. SendMessageToDescendants(WM_SETFONT, (WPARAM)(HFONT)XTPFontManager()->GetFont()); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // select the font and set the drop width for the combo. m_wndComboFont.InitControl(m_strFontName); // insert strings into the size combo box. m_wndComboSize.AddString(_T("8")); m_wndComboSize.AddString(_T("10")); m_wndComboSize.AddString(_T("12")); m_wndComboSize.AddString(_T("14")); m_wndComboSize.AddString(_T("18")); m_wndComboSize.AddString(_T("24")); m_wndComboSize.AddString(_T("36")); // set the selection. if (m_wndComboSize.SelectString(-1, m_strFontSize) == CB_ERR) { m_wndComboSize.SetWindowText(m_strFontSize); } m_wndColorPicker.SetColor(m_crCurrent); m_wndColorPicker.SetThemeColors(); m_wndColorPicker.SetStandardColors(); // initialize the text sample display UpdateFont(); m_wndComboTheme.SetCurSel(25); OnThemeChanged(); // SetTheme(xtpControlThemeDefault); return TRUE; // return TRUE unless you set the focus to a control } void CFontComboDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CFontComboDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM)dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CFontComboDlg::OnQueryDragIcon() { return (HCURSOR)m_hIcon; } void CFontComboDlg::OnSelEndOKColor() { m_crCurrent = m_wndColorPicker.GetColor(); m_txtSample.UpdateFont(m_lf, m_crCurrent); } void CFontComboDlg::OnSelEndOKFontCombo() { UpdateFont(); } void CFontComboDlg::UpdateFont() { UpdateData(); m_wndComboFont.GetSelFont(m_lf); m_strFontName = m_lf.lfFaceName; int iSel = m_wndComboSize.GetCurSel(); if (iSel != CB_ERR) { m_wndComboSize.GetLBText(iSel, m_strFontSize); m_lf.lfHeight = -(_ttoi(m_strFontSize)); } else { m_wndComboSize.GetWindowText(m_strFontSize); m_lf.lfHeight = -(_ttoi(m_strFontSize)); } m_lf.lfWeight = m_bBold ? FW_BOLD : FW_NORMAL; m_lf.lfItalic = m_bItalic ? (BYTE)1 : (BYTE)0; m_lf.lfUnderline = m_bUnderline ? (BYTE)1 : (BYTE)0; m_txtSample.UpdateFont(m_lf, m_crCurrent); } void CFontComboDlg::SetTheme(XTPControlTheme theme) { // nTheme = xtpControlThemeOffice2013; // nTheme = xtpControlThemeVisualStudio2012Light; // nTheme = xtpControlThemeVisualStudio2012Dark; SendMessageToDescendants(WM_XTP_SETCONTROLTHEME, theme); m_wndComboTheme.SetTheme(theme); m_wndComboSize.SetTheme(theme); m_wndComboFont.SetTheme(theme); m_wndColorPicker.SetTheme(theme); m_txtSample.SetTheme(theme); RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_ERASE); } void CFontComboDlg::OnSelendokComboSize() { UpdateFont(); } void CFontComboDlg::OnThemeChanged() { XTPControlTheme theme = xtpControlThemeDefault; switch (m_wndComboTheme.GetCurSel()) { case 0: // Default theme = xtpControlThemeDefault; break; case 1: // Flat theme = xtpControlThemeFlat; break; case 2: // UltraFlat theme = xtpControlThemeUltraFlat; break; case 3: // Office 2000 theme = xtpControlThemeOffice2000; break; case 4: // Office XP theme = xtpControlThemeOfficeXP; break; case 5: // Office 2003 theme = xtpControlThemeOffice2003; break; case 6: // Office 2013 (Word) theme = xtpControlThemeOffice2013; XTPThemeDLL()->SetHandle(xtpIniOffice2013Word); break; case 7: // Office 2013 (Access) theme = xtpControlThemeOffice2013; XTPThemeDLL()->SetHandle(xtpIniOffice2013Access); break; case 8: // Windows XP theme = xtpControlThemeNativeWinXP; break; case 9: // Visual Studio 2005 theme = xtpControlThemeVisualStudio2005; break; case 10: // Visual Studio 2008 theme = xtpControlThemeVisualStudio2008; break; case 11: // Visual Studio 2010 theme = xtpControlThemeVisualStudio2010; break; case 12: // Visual Studio 2012 (Light) theme = xtpControlThemeVisualStudio2012Light; break; case 13: // Visual Studio 2012 (Dark) theme = xtpControlThemeVisualStudio2012Dark; break; case 14: // Visual Studio 2015 (Blue) theme = xtpControlThemeVisualStudio2015; XTPThemeDLL()->SetHandle(xtpIniVisualStudio2015Blue); break; case 15: // Visual Studio 2015 (Light) theme = xtpControlThemeVisualStudio2015; XTPThemeDLL()->SetHandle(xtpIniVisualStudio2015Light); break; case 16: // Visual Studio 2015 (Dark) theme = xtpControlThemeVisualStudio2015; XTPThemeDLL()->SetHandle(xtpIniVisualStudio2015Dark); break; case 17: // Visual Studio 2017 (Blue) theme = xtpControlThemeVisualStudio2017; XTPThemeDLL()->SetHandle(xtpIniVisualStudio2017Blue); break; case 18: // Visual Studio 2017 (Blue Extra) theme = xtpControlThemeVisualStudio2017; XTPThemeDLL()->SetHandle(xtpIniVisualStudio2017BlueExtra); break; case 19: // Visual Studio 2017 (Light) theme = xtpControlThemeVisualStudio2017; XTPThemeDLL()->SetHandle(xtpIniVisualStudio2017Light); break; case 20: // Visual Studio 2017 (Dark) theme = xtpControlThemeVisualStudio2017; XTPThemeDLL()->SetHandle(xtpIniVisualStudio2017Dark); break; case 21: // Visual Studio 2019 (Blue) theme = xtpControlThemeVisualStudio2019; XTPThemeDLL()->SetHandle(xtpIniVisualStudio2019Blue); break; case 22: // Visual Studio 2019 (Blue Extra) theme = xtpControlThemeVisualStudio2019; XTPThemeDLL()->SetHandle(xtpIniVisualStudio2019BlueExtra); break; case 23: // Visual Studio 2019 (Light) theme = xtpControlThemeVisualStudio2019; XTPThemeDLL()->SetHandle(xtpIniVisualStudio2019Light); break; case 24: // Visual Studio 2019 (Dark) theme = xtpControlThemeVisualStudio2019; XTPThemeDLL()->SetHandle(xtpIniVisualStudio2019Dark); break; case 25: // Visual Studio 2022 (Blue) theme = xtpControlThemeVisualStudio2022; XTPThemeDLL()->SetHandle(xtpIniVisualStudio2022Blue); break; case 26: // Visual Studio 2022 (Blue Extra) theme = xtpControlThemeVisualStudio2022; XTPThemeDLL()->SetHandle(xtpIniVisualStudio2022BlueExtra); break; case 27: // Visual Studio 2022 (Light) theme = xtpControlThemeVisualStudio2022; XTPThemeDLL()->SetHandle(xtpIniVisualStudio2022Light); break; case 28: // Visual Studio 2022 (Dark) theme = xtpControlThemeVisualStudio2022; XTPThemeDLL()->SetHandle(xtpIniVisualStudio2022Dark); break; default: _ASSERTE(!"Unknown theme selected"); break; } SetTheme(theme); } void CFontComboDlg::OnChkBold() { UpdateFont(); } void CFontComboDlg::OnChkItalic() { UpdateFont(); } void CFontComboDlg::OnChkUnderline() { UpdateFont(); } HBRUSH CFontComboDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { ASSERT_VALID(pDC); COLORREF crFace = XTPIniColor(_T("Controls.Button"), _T("Back"), ::GetSysColor(COLOR_BTNFACE)); COLORREF crText = XTPIniColor(_T("Controls.Button"), _T("Text"), ::GetSysColor(COLOR_BTNTEXT)); if (m_crBackground != crFace) { m_crBackground = crFace; if (NULL != m_brushBackground.m_hObject) m_brushBackground.DeleteObject(); m_brushBackground.CreateSolidBrush(m_crBackground); } pDC->SetBkColor(crFace); pDC->SetTextColor(crText); return reinterpret_cast(m_brushBackground.m_hObject); }