home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / protview / demowinx / data.1 / FNTSLDLG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  3.8 KB  |  145 lines

  1. // FontSelDialog.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "allctls.h"
  6. #include "FntSlDlg.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CFontSelDialog dialog
  16.  
  17.  
  18. CFontSelDialog::CFontSelDialog(CWnd* pParent /*=NULL*/)
  19.     : CDialog(CFontSelDialog::IDD, pParent)
  20. {
  21.     //{{AFX_DATA_INIT(CFontSelDialog)
  22.     //}}AFX_DATA_INIT
  23. }
  24.  
  25.  
  26. void CFontSelDialog::DoDataExchange(CDataExchange* pDX)
  27. {
  28.     CDialog::DoDataExchange(pDX);
  29.     //{{AFX_DATA_MAP(CFontSelDialog)
  30.     DDX_Control(pDX, IDC_TEXT, m_text);
  31.     DDX_Control(pDX, IDC_FONTSELCTRL1, m_fontsel);
  32.     DDX_Control(pDX, IDC_BOLD, m_bold);
  33.     DDX_Control(pDX, IDC_ITALIC, m_italic);
  34.     //}}AFX_DATA_MAP
  35. }
  36.  
  37.  
  38. BEGIN_MESSAGE_MAP(CFontSelDialog, CDialog)
  39.     //{{AFX_MSG_MAP(CFontSelDialog)
  40.     //}}AFX_MSG_MAP
  41. END_MESSAGE_MAP()
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CFontSelDialog message handlers
  45.  
  46. BOOL CFontSelDialog::OnInitDialog() 
  47. {
  48.     CDialog::OnInitDialog();
  49.     
  50.     // TODO: Add extra initialization here
  51.     CFont* sfont;
  52.     LOGFONT lg;
  53.  
  54.     sfont = m_text.GetFont();
  55.     sfont->GetLogFont(&lg);
  56.     m_fontsel.SetFontName(lg.lfFaceName);
  57.     m_fontsel.SetPointSize((short)lg.lfHeight);
  58.  
  59.     if (lg.lfItalic)
  60.         m_italic.SetColorCodeColor(RGB(0, 255, 0));
  61.     else
  62.         m_italic.SetColorCodeColor(RGB(255, 0, 0));
  63.  
  64.     if (lg.lfWeight >= 700)
  65.         m_bold.SetColorCodeColor(RGB(0, 255, 0));
  66.     else
  67.         m_bold.SetColorCodeColor(RGB(255, 0, 0));
  68.  
  69.     return TRUE;  // return TRUE unless you set the focus to a control
  70.                   // EXCEPTION: OCX Property Pages should return FALSE
  71. }
  72.  
  73. BEGIN_EVENTSINK_MAP(CFontSelDialog, CDialog)
  74.     //{{AFX_EVENTSINK_MAP(CFontSelDialog)
  75.     ON_EVENT(CFontSelDialog, IDC_FONTSELCTRL1, 1 /* FontNameChange */, OnFontNameChangeFontselctrl1, VTS_NONE)
  76.     ON_EVENT(CFontSelDialog, IDC_FONTSELCTRL1, 2 /* PointSizeChange */, OnPointSizeChangeFontselctrl1, VTS_NONE)
  77.     ON_EVENT(CFontSelDialog, IDC_ITALIC, -600 /* Click */, OnClickItalic, VTS_NONE)
  78.     ON_EVENT(CFontSelDialog, IDC_BOLD, -600 /* Click */, OnClickBold, VTS_NONE)
  79.     //}}AFX_EVENTSINK_MAP
  80. END_EVENTSINK_MAP()
  81.  
  82. void CFontSelDialog::OnFontNameChangeFontselctrl1() 
  83. {
  84.     // TODO: Add your control notification handler code here
  85.     ChangeFont();
  86. }
  87.  
  88. void CFontSelDialog::OnPointSizeChangeFontselctrl1() 
  89. {
  90.     // TODO: Add your control notification handler code here
  91.     ChangeFont();
  92. }
  93.  
  94. void CFontSelDialog::OnClickItalic() 
  95. {
  96.     // TODO: Add your control notification handler code here
  97.     COLORREF oldColor;
  98.  
  99.     oldColor = m_italic.GetColorCodeColor();
  100.     if (oldColor == RGB(255, 0, 0))
  101.         m_italic.SetColorCodeColor(RGB(0, 255, 0));
  102.     else
  103.         m_italic.SetColorCodeColor(RGB(255, 0, 0));
  104.  
  105.     ChangeFont();
  106. }
  107.  
  108. void CFontSelDialog::OnClickBold() 
  109. {
  110.     // TODO: Add your control notification handler code here
  111.     COLORREF oldColor;
  112.  
  113.     oldColor = m_bold.GetColorCodeColor();
  114.     if (oldColor == RGB(255, 0, 0))
  115.         m_bold.SetColorCodeColor(RGB(0, 255, 0));
  116.     else
  117.         m_bold.SetColorCodeColor(RGB(255, 0, 0));
  118.  
  119.     ChangeFont();
  120. }
  121.  
  122. void CFontSelDialog::ChangeFont()
  123. {
  124.     CString cstr;
  125.     short ptsize;
  126.     HFONT hFont, hNewFont;
  127.     LOGFONT lg;
  128.     COLORREF Bold;
  129.     COLORREF Italic;
  130.  
  131.     cstr = m_fontsel.GetFontName();
  132.     ptsize = m_fontsel.GetPointSize();
  133.     Bold = m_bold.GetColorCodeColor();
  134.     Italic = m_italic.GetColorCodeColor();
  135.     hFont = (HFONT)m_text.SendMessage(WM_GETFONT, 0, 0L);
  136.     GetObject((HFONT)hFont, sizeof(LOGFONT), &lg);
  137.  
  138.     lstrcpy(lg.lfFaceName, (LPCSTR)cstr);
  139.     lg.lfHeight = ptsize;
  140.     lg.lfWeight = (Bold == RGB(0, 255, 0)) ? 700 : 400;
  141.     lg.lfItalic = (Italic == RGB(0, 255, 0)) ? TRUE : FALSE;
  142.     
  143.     hNewFont = CreateFontIndirect(&lg);
  144.     m_text.SendMessage(WM_SETFONT, (WPARAM)hNewFont, (LPARAM)MAKELONG((WORD)TRUE,0));
  145. }