home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / MS_VC.50 / VC / MFC / SRC / DLGCLR.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-30  |  3.7 KB  |  155 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1997 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. BEGIN_MESSAGE_MAP(CColorDialog, CCommonDialog)
  44.     //{{AFX_MSG_MAP(CColorDialog)
  45.     ON_WM_CTLCOLOR()
  46.     //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48.  
  49. EXTERN_PROCESS_LOCAL(_AFX_COLOR_STATE, _afxClrState)
  50.  
  51. CColorDialog::CColorDialog(COLORREF clrInit, DWORD dwFlags,
  52.     CWnd* pParentWnd) : CCommonDialog(pParentWnd)
  53. {
  54. #ifdef _MAC
  55.     UNUSED_ALWAYS(dwFlags);
  56. #endif
  57.  
  58.     memset(&m_cc, 0, sizeof(m_cc));
  59.     m_nIDHelp = AFX_IDD_COLOR;
  60.  
  61.     m_cc.lStructSize = sizeof(m_cc);
  62.     m_cc.lpCustColors = GetSavedCustomColors();
  63. #ifndef _MAC
  64.     m_cc.Flags = dwFlags | CC_ENABLEHOOK;
  65. #endif
  66.     if (!afxData.bWin4 && AfxHelpEnabled())
  67.         m_cc.Flags |= CC_SHOWHELP;
  68. #ifndef _MAC
  69.     m_cc.lpfnHook = (COMMDLGPROC)_AfxCommDlgProc;
  70. #endif
  71.  
  72.     if ((m_cc.rgbResult = clrInit) != 0)
  73.         m_cc.Flags |= CC_RGBINIT;
  74. }
  75.  
  76. int CColorDialog::DoModal()
  77. {
  78.     ASSERT_VALID(this);
  79. #ifndef _MAC
  80.     ASSERT(m_cc.Flags & CC_ENABLEHOOK);
  81.     ASSERT(m_cc.lpfnHook != NULL); // can still be a user hook
  82. #endif
  83.  
  84.     m_cc.hwndOwner = PreModal();
  85.     int nResult = ::ChooseColor(&m_cc);
  86.     PostModal();
  87.     return nResult ? nResult : IDCANCEL;
  88. }
  89.  
  90. BOOL CColorDialog::OnColorOK()
  91. {
  92.     ASSERT_VALID(this);
  93.     // Do not call Default() if you override
  94.     return FALSE;
  95. }
  96.  
  97. void CColorDialog::SetCurrentColor(COLORREF clr)
  98. {
  99.     ASSERT_VALID(this);
  100.     ASSERT(m_hWnd != NULL);
  101.  
  102.     SendMessage(_afxNMsgSETRGB, 0, (DWORD)clr);
  103. }
  104.  
  105. COLORREF* PASCAL CColorDialog::GetSavedCustomColors()
  106. {
  107.     return &_afxClrState->m_crSavedCustom[0];
  108. }
  109.  
  110. // The color tracker in the COMMDLG.DLL can't handle grey backgrounds,
  111. //  so we force the default with this override.
  112.  
  113. HBRUSH CColorDialog::OnCtlColor(CDC*, CWnd*, UINT)
  114. {
  115.     return (HBRUSH)Default();
  116. }
  117.  
  118. ////////////////////////////////////////////////////////////////////////////
  119. // CColorDialog diagnostics
  120.  
  121. #ifdef _DEBUG
  122. void CColorDialog::Dump(CDumpContext& dc) const
  123. {
  124.     CDialog::Dump(dc);
  125.  
  126.     dc << "m_cc.hwndOwner = " << (UINT)m_cc.hwndOwner;
  127.     dc << "\nm_cc.rgbResult = " << (LPVOID)m_cc.rgbResult;
  128.     dc << "\nm_cc.Flags = " << (LPVOID)m_cc.Flags;
  129.     dc << "\nm_cc.lpCustColors ";
  130.  
  131.     for (int iClr = 0; iClr < 16; iClr++)
  132.         dc << "\n\t" << (LPVOID)m_cc.lpCustColors[iClr];
  133.  
  134.     if (m_cc.lpfnHook == (COMMDLGPROC)_AfxCommDlgProc)
  135.         dc << "\nhook function set to standard MFC hook function";
  136.     else
  137.         dc << "\nhook function set to non-standard hook function";
  138.  
  139.     dc << "\n";
  140. }
  141. #endif //_DEBUG
  142.  
  143. #ifdef AFX_INIT_SEG
  144. #pragma code_seg(AFX_INIT_SEG)
  145. #endif
  146.  
  147. IMPLEMENT_DYNAMIC(CColorDialog, CDialog)
  148.  
  149. #pragma warning(disable: 4074)
  150. #pragma init_seg(lib)
  151.  
  152. PROCESS_LOCAL(_AFX_COLOR_STATE, _afxClrState)
  153.  
  154. ////////////////////////////////////////////////////////////////////////////
  155.