// XMonoFontDialogTestDlg.cpp : implementation file // #include "stdafx.h" #include "XMonoFontDialogTest.h" #include "XMonoFontDialogTestDlg.h" #include "XMonoFontDialog.h" #include "about.h" #include "XTrace.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #pragma warning(disable : 4996) // disable bogus deprecation warning //============================================================================= BEGIN_MESSAGE_MAP(CXMonoFontDialogTestDlg, CDialog) //============================================================================= //{{AFX_MSG_MAP(CXMonoFontDialogTestDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_TEST, OnCXMonoFontDialog) ON_BN_CLICKED(IDC_TEST2, OnCFontDialog) ON_BN_CLICKED(IDC_ONLINE_HELP, OnOnlineHelp) ON_WM_CTLCOLOR() //}}AFX_MSG_MAP END_MESSAGE_MAP() //============================================================================= CXMonoFontDialogTestDlg::CXMonoFontDialogTestDlg(CWnd* pParent /*=NULL*/) : CDialog(CXMonoFontDialogTestDlg::IDD, pParent) //============================================================================= { //{{AFX_DATA_INIT(CXMonoFontDialogTestDlg) m_nFonts = 0; m_strSampleText = _T("AaBbYyZz 0123456789"); m_bShowMonospacedAsBold = TRUE; m_bShowMonospacedLabel = TRUE; //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } //============================================================================= CXMonoFontDialogTestDlg::~CXMonoFontDialogTestDlg() //============================================================================= { m_font.DeleteObject(); m_buttonfont.DeleteObject(); } //============================================================================= void CXMonoFontDialogTestDlg::DoDataExchange(CDataExchange* pDX) //============================================================================= { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CXMonoFontDialogTestDlg) DDX_Control(pDX, IDC_NOTE, m_Note); DDX_Control(pDX, IDC_PROPERTIES, m_Properties); DDX_Control(pDX, IDC_SAMPLE, m_Sample); DDX_Radio(pDX, IDC_ALL_FONTS, m_nFonts); DDX_Text(pDX, IDC_SAMPLE_TEXT, m_strSampleText); DDX_Check(pDX, IDC_SHOW_MONOSPACED_AS_BOLD, m_bShowMonospacedAsBold); DDX_Check(pDX, IDC_SHOW_MONOSPACED_LABEL, m_bShowMonospacedLabel); //}}AFX_DATA_MAP } //============================================================================= BOOL CXMonoFontDialogTestDlg::OnInitDialog() //============================================================================= { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(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 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 m_Sample.SetWindowText(m_strSampleText); // create font for sample LOGFONT lf; CFont *pFont = GetFont(); pFont->GetLogFont(&lf); m_nHeight = lf.lfHeight; m_strFaceName = lf.lfFaceName; m_font.CreateFontIndirect(&lf); m_Sample.SetFont(&m_font); if (lf.lfHeight < 0) lf.lfHeight -= 1; else lf.lfHeight += 1; //lf.lfWeight = FW_BOLD; m_buttonfont.CreateFontIndirect(&lf); GetDlgItem(IDC_TEST)->SetFont(&m_buttonfont); GetDlgItem(IDC_TEST2)->SetFont(&m_buttonfont); GetDlgItem(IDC_ONLINE_HELP)->SetFont(&m_buttonfont); // display font name in sample groupbox GetDlgItem(IDC_GROUPBOX)->SetWindowText(lf.lfFaceName); return TRUE; // return TRUE unless you set the focus to a control } //============================================================================= void CXMonoFontDialogTestDlg::OnSysCommand(UINT nID, LPARAM lParam) //============================================================================= { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } //============================================================================= void CXMonoFontDialogTestDlg::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(); } } //============================================================================= HCURSOR CXMonoFontDialogTestDlg::OnQueryDragIcon() //============================================================================= { return (HCURSOR) m_hIcon; } //============================================================================= void CXMonoFontDialogTestDlg::OnCXMonoFontDialog() //============================================================================= { UpdateData(TRUE); // get font for current dialog, just to fill in LOGFONT LOGFONT lf; CFont *pFont = GetFont(); pFont->GetLogFont(&lf); // use last font height lf.lfHeight = m_nHeight; // use last face name _tcscpy(lf.lfFaceName, m_strFaceName); TRACE(_T("m_strFaceName=%s\n"), m_strFaceName); // display CXMonoFontDialog CXMonoFontDialog dlg(&lf); DWORD dwFonts = XFONT_SHOW_ALL; // get font filters switch (m_nFonts) { case 0: dwFonts = XFONT_SHOW_ALL; break; case 1: dwFonts = XFONT_SHOW_SYMBOL; break; case 2: dwFonts &= ~XFONT_SHOW_SYMBOL; break; case 3: dwFonts = XFONT_SHOW_MONOSPACED; break; case 4: dwFonts &= ~XFONT_SHOW_MONOSPACED; break; case 5: dwFonts &= ~(XFONT_SHOW_MONOSPACED|XFONT_SHOW_SYMBOL); break; default: dwFonts = 0; break; } dlg.SetFontFilter(dwFonts) .SetCaption(_T("XMonoFontDialog")) .SetSampleText(m_strSampleText) .ShowMonospacedLabel(m_bShowMonospacedLabel) .ShowMonospacedAsBold(m_bShowMonospacedAsBold); if (dlg.DoModal() == IDOK) { // display properties for selected font CString strProperties = _T(""); strProperties.Format(_T(" tmHeight = %d "), dlg.GetTmHeight()); CString str; str.Format(_T("GetSize() = %d "), dlg.GetSize()); strProperties += str; if (dlg.IsMonospaced()) strProperties += _T("Monospaced "); if (dlg.IsSymbol()) strProperties += _T("Symbol "); if (dlg.IsTrueType()) strProperties += _T("TrueType "); if (dlg.IsOpenType()) strProperties += _T("OpenType "); if (dlg.IsVector()) strProperties += _T("Vector "); m_Properties.SetWindowText(strProperties); m_Note.ShowWindow(SW_SHOW); dlg.GetCurrentFont(&lf); TRACE(_T("lfCharSet=%d\n"), lf.lfCharSet); m_nHeight = lf.lfHeight; m_strFaceName = lf.lfFaceName; GetDlgItem(IDC_GROUPBOX)->SetWindowText(lf.lfFaceName); m_font.DeleteObject(); m_font.CreateFontIndirect(&lf); m_Sample.SetWindowText(m_strSampleText); m_Sample.SetFont(&m_font); } } //============================================================================= void CXMonoFontDialogTestDlg::OnCFontDialog() //============================================================================= { TRACE(_T("in CXMonoFontDialogTestDlg::OnCFontDialog\n")); UpdateData(TRUE); // get font for current dialog, just to fill in LOGFONT LOGFONT lf; CFont *pFont = GetFont(); pFont->GetLogFont(&lf); // use last font height lf.lfHeight = m_nHeight; // use last face name _tcscpy(lf.lfFaceName, m_strFaceName); // display CFontDialog CFontDialog dlg(&lf); if (m_nFonts == 3) dlg.m_cf.Flags |= CF_FIXEDPITCHONLY; dlg.m_cf.Flags |= CF_PRINTERFONTS; //dlg.m_cf.Flags &= ~CF_EFFECTS; // remove the Effects controls //dlg.m_cf.Flags |= CF_NOSCRIPTSEL; // disable the script combo if (dlg.DoModal() == IDOK) { CString strProperties = _T(""); CString str; str.Format(_T(" GetSize() = %d "), dlg.GetSize()); strProperties += str; m_Properties.SetWindowText(strProperties); m_Note.ShowWindow(SW_SHOW); dlg.GetCurrentFont(&lf); m_nHeight = lf.lfHeight; m_strFaceName = lf.lfFaceName; TRACE(_T("lfCharSet=%d\n"), lf.lfCharSet); //TRACE(_T("GetStyleName=%s\n"), dlg.GetStyleName()); TRACE(_T("IsBold=%d lfWeight=%d\n"), dlg.IsBold(), lf.lfWeight); GetDlgItem(IDC_GROUPBOX)->SetWindowText(lf.lfFaceName); m_font.DeleteObject(); m_font.CreateFontIndirect(&lf); m_Sample.SetWindowText(m_strSampleText); m_Sample.SetFont(&m_font); } } //============================================================================= void CXMonoFontDialogTestDlg::OnOnlineHelp() //============================================================================= { CString strHelp = _T(""); VERIFY(strHelp.LoadString(IDS_ONLINE_HELP)); CXHyperLink::GotoURL(strHelp, SW_SHOW, TRUE); } //============================================================================= HBRUSH CXMonoFontDialogTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) //============================================================================= { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); CWnd *pNote = GetDlgItem(IDC_NOTE); if (pWnd->m_hWnd == pNote->m_hWnd) pDC->SetTextColor(RGB(0,0,255)); return hbr; }