home *** CD-ROM | disk | FTP | other *** search
- // FontSelDialog.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "allctls.h"
- #include "FntSlDlg.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CFontSelDialog dialog
-
-
- CFontSelDialog::CFontSelDialog(CWnd* pParent /*=NULL*/)
- : CDialog(CFontSelDialog::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CFontSelDialog)
- //}}AFX_DATA_INIT
- }
-
-
- void CFontSelDialog::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CFontSelDialog)
- DDX_Control(pDX, IDC_TEXT, m_text);
- DDX_Control(pDX, IDC_FONTSELCTRL1, m_fontsel);
- DDX_Control(pDX, IDC_BOLD, m_bold);
- DDX_Control(pDX, IDC_ITALIC, m_italic);
- //}}AFX_DATA_MAP
- }
-
-
- BEGIN_MESSAGE_MAP(CFontSelDialog, CDialog)
- //{{AFX_MSG_MAP(CFontSelDialog)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CFontSelDialog message handlers
-
- BOOL CFontSelDialog::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- CFont* sfont;
- LOGFONT lg;
-
- sfont = m_text.GetFont();
- sfont->GetLogFont(&lg);
- m_fontsel.SetFontName(lg.lfFaceName);
- m_fontsel.SetPointSize((short)lg.lfHeight);
-
- if (lg.lfItalic)
- m_italic.SetColorCodeColor(RGB(0, 255, 0));
- else
- m_italic.SetColorCodeColor(RGB(255, 0, 0));
-
- if (lg.lfWeight >= 700)
- m_bold.SetColorCodeColor(RGB(0, 255, 0));
- else
- m_bold.SetColorCodeColor(RGB(255, 0, 0));
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
-
- BEGIN_EVENTSINK_MAP(CFontSelDialog, CDialog)
- //{{AFX_EVENTSINK_MAP(CFontSelDialog)
- ON_EVENT(CFontSelDialog, IDC_FONTSELCTRL1, 1 /* FontNameChange */, OnFontNameChangeFontselctrl1, VTS_NONE)
- ON_EVENT(CFontSelDialog, IDC_FONTSELCTRL1, 2 /* PointSizeChange */, OnPointSizeChangeFontselctrl1, VTS_NONE)
- ON_EVENT(CFontSelDialog, IDC_ITALIC, -600 /* Click */, OnClickItalic, VTS_NONE)
- ON_EVENT(CFontSelDialog, IDC_BOLD, -600 /* Click */, OnClickBold, VTS_NONE)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
-
- void CFontSelDialog::OnFontNameChangeFontselctrl1()
- {
- // TODO: Add your control notification handler code here
- ChangeFont();
- }
-
- void CFontSelDialog::OnPointSizeChangeFontselctrl1()
- {
- // TODO: Add your control notification handler code here
- ChangeFont();
- }
-
- void CFontSelDialog::OnClickItalic()
- {
- // TODO: Add your control notification handler code here
- COLORREF oldColor;
-
- oldColor = m_italic.GetColorCodeColor();
- if (oldColor == RGB(255, 0, 0))
- m_italic.SetColorCodeColor(RGB(0, 255, 0));
- else
- m_italic.SetColorCodeColor(RGB(255, 0, 0));
-
- ChangeFont();
- }
-
- void CFontSelDialog::OnClickBold()
- {
- // TODO: Add your control notification handler code here
- COLORREF oldColor;
-
- oldColor = m_bold.GetColorCodeColor();
- if (oldColor == RGB(255, 0, 0))
- m_bold.SetColorCodeColor(RGB(0, 255, 0));
- else
- m_bold.SetColorCodeColor(RGB(255, 0, 0));
-
- ChangeFont();
- }
-
- void CFontSelDialog::ChangeFont()
- {
- CString cstr;
- short ptsize;
- HFONT hFont, hNewFont;
- LOGFONT lg;
- COLORREF Bold;
- COLORREF Italic;
-
- cstr = m_fontsel.GetFontName();
- ptsize = m_fontsel.GetPointSize();
- Bold = m_bold.GetColorCodeColor();
- Italic = m_italic.GetColorCodeColor();
- hFont = (HFONT)m_text.SendMessage(WM_GETFONT, 0, 0L);
- GetObject((HFONT)hFont, sizeof(LOGFONT), &lg);
-
- lstrcpy(lg.lfFaceName, (LPCSTR)cstr);
- lg.lfHeight = ptsize;
- lg.lfWeight = (Bold == RGB(0, 255, 0)) ? 700 : 400;
- lg.lfItalic = (Italic == RGB(0, 255, 0)) ? TRUE : FALSE;
-
- hNewFont = CreateFontIndirect(&lg);
- m_text.SendMessage(WM_SETFONT, (WPARAM)hNewFont, (LPARAM)MAKELONG((WORD)TRUE,0));
- }