home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / MFC / SRC / DLGFNT.CP_ / DLGFNT.CP
Encoding:
Text File  |  1993-02-08  |  3.5 KB  |  130 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library. 
  2. // Copyright (C) 1992 Microsoft Corporation 
  3. // All rights reserved. 
  4. //  
  5. // This source code is only intended as a supplement to the 
  6. // Microsoft Foundation Classes Reference and Microsoft 
  7. // QuickHelp and/or WinHelp documentation provided with the library. 
  8. // See these sources for detailed information regarding the 
  9. // Microsoft Foundation Classes product. 
  10.  
  11.  
  12. #include "stdafx.h"
  13.  
  14. #ifdef AFX_AUX_SEG
  15. #pragma code_seg(AFX_AUX_SEG)
  16. #endif
  17.  
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char BASED_CODE THIS_FILE[] = __FILE__;
  21. #define new DEBUG_NEW
  22. #endif
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // Choose Font dialog
  26.  
  27. IMPLEMENT_DYNAMIC(CFontDialog, CDialog)
  28.  
  29. CFontDialog::CFontDialog(LPLOGFONT lplfInitial  /* = NULL */,
  30.         DWORD dwFlags /* = CF_EFFECTS | CF_SCREENFONTS */, 
  31.         CDC* pdcPrinter /* = NULL */,
  32.         CWnd* pParentWnd /* = NULL */) : CDialog((UINT)0, pParentWnd)
  33. {
  34.     memset(&m_cf, 0, sizeof(m_cf));
  35.     memset(&m_lf, 0, sizeof(m_lf));
  36.     memset(&m_szStyleName, 0, sizeof(m_szStyleName));
  37.  
  38.     m_nIDHelp = AFX_IDD_FONT;
  39.  
  40.     m_cf.lStructSize = sizeof(m_cf);
  41.     m_cf.lpszStyle = (LPSTR)&m_szStyleName;
  42.     m_cf.Flags = dwFlags | CF_ENABLEHOOK;
  43.     if (_AfxHelpEnabled())
  44.         m_cf.Flags |= CF_SHOWHELP;
  45.     m_cf.lpfnHook = (COMMDLGPROC)_AfxCommDlgProc;
  46.  
  47.     if (lplfInitial)
  48.     {
  49.         m_cf.lpLogFont = lplfInitial;
  50.         m_cf.Flags |= CF_INITTOLOGFONTSTRUCT;
  51.         _fmemcpy(&m_lf, m_cf.lpLogFont, sizeof(m_lf));
  52.     }
  53.     else
  54.     {
  55.         m_cf.lpLogFont = &m_lf;
  56.     }
  57.  
  58.     if (pdcPrinter)
  59.     {
  60.         ASSERT(pdcPrinter->m_hDC != NULL);
  61.         m_cf.hDC = pdcPrinter->m_hDC;
  62.         m_cf.Flags |= CF_PRINTERFONTS;
  63.     }
  64. }
  65.  
  66. BOOL CFontDialog::DoModal()
  67. {
  68.     ASSERT_VALID(this);
  69.     ASSERT(m_cf.Flags & CF_ENABLEHOOK);
  70.     ASSERT(m_cf.lpfnHook != NULL); // can still be a user hook
  71.  
  72.     m_cf.hwndOwner = _AfxGetSafeOwner(m_pParentWnd);
  73.     _AfxHookWindowCreate(this);
  74.     BOOL bResult = ::ChooseFont(&m_cf);
  75.     _AfxUnhookWindowCreate();   // just in case
  76.     Detach();                   // just in case
  77.  
  78.     if (bResult)
  79.     {
  80.         // copy logical font from user's initialization buffer (if needed)
  81.         _fmemcpy(&m_lf, m_cf.lpLogFont, sizeof(m_lf));
  82.         return IDOK;
  83.     }
  84.  
  85.     return IDCANCEL;
  86. }
  87.  
  88.  
  89. void CFontDialog::OnOK()
  90. {
  91.     // Common dialogs do not require ::EndDialog
  92.     ASSERT_VALID(this);
  93.     Default();
  94. }
  95.  
  96. void CFontDialog::OnCancel()
  97. {
  98.     // Common dialogs do not require ::EndDialog
  99.     ASSERT_VALID(this);
  100.     Default();
  101. }
  102.  
  103. ////////////////////////////////////////////////////////////////////////////
  104. // CFontDialog diagnostics
  105.  
  106. #ifdef _DEBUG
  107. void CFontDialog::Dump(CDumpContext& dc) const
  108. {
  109.     ASSERT_VALID(this);
  110.  
  111.     CDialog::Dump(dc);
  112.     AFX_DUMP1(dc, "\nm_cf.hwndOwner = ", (UINT)m_cf.hwndOwner);
  113.     AFX_DUMP1(dc, "\nm_cf.hDC = ", (UINT)m_cf.hDC);
  114.     AFX_DUMP1(dc, "\nm_cf.iPointSize = ", m_cf.iPointSize);
  115.     AFX_DUMP1(dc, "\nm_cf.Flags = ", (LPVOID)m_cf.Flags);
  116.     AFX_DUMP1(dc, "\nm_cf.lpszStyle = ", m_cf.lpszStyle);
  117.     AFX_DUMP1(dc, "\nm_cf.nSizeMin = ", m_cf.nSizeMin);
  118.     AFX_DUMP1(dc, "\nm_cf.nSizeMax = ", m_cf.nSizeMax);
  119.     AFX_DUMP1(dc, "\nm_cf.nFontType = ", m_cf.nFontType);
  120.     AFX_DUMP1(dc, "\nm_cf.rgbColors = ", (LPVOID)m_cf.rgbColors);
  121.     if (m_cf.lpfnHook == (COMMDLGPROC)_AfxCommDlgProc)
  122.         AFX_DUMP0(dc, "\nhook function set to standard MFC hook function");
  123.     else
  124.         AFX_DUMP0(dc, "\nhook function set to non-standard hook function");
  125. }
  126.  
  127. #endif //_DEBUG
  128.  
  129. ////////////////////////////////////////////////////////////////////////////
  130.