home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / src / dlgclr.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-16  |  3.7 KB  |  149 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 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 related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef AFX_AUX_SEG
  14. #pragma code_seg(AFX_AUX_SEG)
  15. #endif
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. #define new DEBUG_NEW
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // Choose Color dialog
  26.  
  27. class _AFX_COLOR_STATE : public CNoTrackObject
  28. {
  29. public:
  30.     // custom colors are held here and saved between calls
  31.     COLORREF m_crSavedCustom[16];
  32.  
  33.     _AFX_COLOR_STATE();
  34. };
  35.  
  36. _AFX_COLOR_STATE::_AFX_COLOR_STATE()
  37. {
  38.     // custom colors are initialized to white
  39.     for (int i = 0; i < _countof(m_crSavedCustom); i++)
  40.         m_crSavedCustom[i] = RGB(255, 255, 255);
  41. }
  42.  
  43. #ifndef _AFX_NO_GRAYDLG_SUPPORT
  44. BEGIN_MESSAGE_MAP(CColorDialog, CCommonDialog)
  45.     //{{AFX_MSG_MAP(CColorDialog)
  46.     ON_WM_CTLCOLOR()
  47.     //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. #endif //!_AFX_NO_GRAYDLG_SUPPORT
  50.  
  51. EXTERN_PROCESS_LOCAL(_AFX_COLOR_STATE, _afxClrState)
  52.  
  53. CColorDialog::CColorDialog(COLORREF clrInit, DWORD dwFlags,
  54.     CWnd* pParentWnd) : CCommonDialog(pParentWnd)
  55. {
  56.     memset(&m_cc, 0, sizeof(m_cc));
  57.     m_nIDHelp = AFX_IDD_COLOR;
  58.  
  59.     m_cc.lStructSize = sizeof(m_cc);
  60.     m_cc.lpCustColors = GetSavedCustomColors();
  61.     m_cc.Flags = dwFlags | CC_ENABLEHOOK;
  62.     if (!afxData.bWin4 && AfxHelpEnabled())
  63.         m_cc.Flags |= CC_SHOWHELP;
  64.     m_cc.lpfnHook = (COMMDLGPROC)_AfxCommDlgProc;
  65.  
  66.     if ((m_cc.rgbResult = clrInit) != 0)
  67.         m_cc.Flags |= CC_RGBINIT;
  68. }
  69.  
  70. int CColorDialog::DoModal()
  71. {
  72.     ASSERT_VALID(this);
  73.     ASSERT(m_cc.Flags & CC_ENABLEHOOK);
  74.     ASSERT(m_cc.lpfnHook != NULL); // can still be a user hook
  75.  
  76.     m_cc.hwndOwner = PreModal();
  77.     int nResult = ::ChooseColor(&m_cc);
  78.     PostModal();
  79.     return nResult ? nResult : IDCANCEL;
  80. }
  81.  
  82. BOOL CColorDialog::OnColorOK()
  83. {
  84.     ASSERT_VALID(this);
  85.     // Do not call Default() if you override
  86.     return FALSE;
  87. }
  88.  
  89. void CColorDialog::SetCurrentColor(COLORREF clr)
  90. {
  91.     ASSERT_VALID(this);
  92.     ASSERT(m_hWnd != NULL);
  93.  
  94.     SendMessage(_afxMsgSETRGB, 0, (DWORD)clr);
  95. }
  96.  
  97. COLORREF* PASCAL CColorDialog::GetSavedCustomColors()
  98. {
  99.     return &_afxClrState->m_crSavedCustom[0];
  100. }
  101.  
  102. // The color tracker in the COMMDLG.DLL can't handle gray backgrounds,
  103. //  so we force the default with this override.
  104.  
  105. #ifndef _AFX_NO_GRAYDLG_SUPPORT
  106. HBRUSH CColorDialog::OnCtlColor(CDC*, CWnd*, UINT)
  107. {
  108.     return (HBRUSH)Default();
  109. }
  110. #endif //!_AFX_NO_GRAYDLG_SUPPORT
  111.  
  112. ////////////////////////////////////////////////////////////////////////////
  113. // CColorDialog diagnostics
  114.  
  115. #ifdef _DEBUG
  116. void CColorDialog::Dump(CDumpContext& dc) const
  117. {
  118.     CDialog::Dump(dc);
  119.  
  120.     dc << "m_cc.hwndOwner = " << (UINT)m_cc.hwndOwner;
  121.     dc << "\nm_cc.rgbResult = " << (LPVOID)m_cc.rgbResult;
  122.     dc << "\nm_cc.Flags = " << (LPVOID)m_cc.Flags;
  123.     dc << "\nm_cc.lpCustColors ";
  124.  
  125.     for (int iClr = 0; iClr < 16; iClr++)
  126.         dc << "\n\t" << (LPVOID)m_cc.lpCustColors[iClr];
  127.  
  128.     if (m_cc.lpfnHook == (COMMDLGPROC)_AfxCommDlgProc)
  129.         dc << "\nhook function set to standard MFC hook function";
  130.     else
  131.         dc << "\nhook function set to non-standard hook function";
  132.  
  133.     dc << "\n";
  134. }
  135. #endif //_DEBUG
  136.  
  137. #ifdef AFX_INIT_SEG
  138. #pragma code_seg(AFX_INIT_SEG)
  139. #endif
  140.  
  141. IMPLEMENT_DYNAMIC(CColorDialog, CDialog)
  142.  
  143. #pragma warning(disable: 4074)
  144. #pragma init_seg(lib)
  145.  
  146. PROCESS_LOCAL(_AFX_COLOR_STATE, _afxClrState)
  147.  
  148. ////////////////////////////////////////////////////////////////////////////
  149.