home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / MS_VC.50 / VC / MFC / SRC / APPGRAY.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-30  |  2.3 KB  |  72 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_INIT_SEG
  14. #pragma code_seg(AFX_INIT_SEG)
  15. #endif
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // Support for gray background in dialogs (and message boxes)
  24.  
  25. LRESULT CALLBACK
  26. _AfxCbtFilterHook(int code, WPARAM wParam, LPARAM lParam);
  27.  
  28. void CWinApp::SetDialogBkColor(COLORREF clrCtlBk, COLORREF clrCtlText)
  29. {
  30.     if (!afxContextIsDLL)
  31.     {
  32.         _AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
  33.         if (pThreadState->m_hHookOldCbtFilter == NULL)
  34.         {
  35.             pThreadState->m_hHookOldCbtFilter = ::SetWindowsHookEx(WH_CBT,
  36.                 _AfxCbtFilterHook, NULL, ::GetCurrentThreadId());
  37.             if (pThreadState->m_hHookOldCbtFilter == NULL)
  38.                 AfxThrowMemoryException();
  39.         }
  40.     }
  41.  
  42.     // set up for grey backgrounds for dialogs
  43.     _AFX_WIN_STATE* pWinState = _afxWinState;
  44.     AfxDeleteObject((HGDIOBJ*)&pWinState->m_hDlgBkBrush);
  45.  
  46. #ifdef _MAC
  47.     // MFC's default gray color is available in the VGA palette but not in
  48.     // the standard Mac 4- or 8-bit color tables, so we will remap it to
  49.     // the closest available solid color. We also want to use 3DLIGHT or BTNFACE
  50.     // as the background color rather than the darker gray that Win32 MFC uses.
  51.     if (clrCtlBk == RGB(192, 192, 192))
  52.     {
  53.         DWORD dwFlags;
  54.         SystemParametersInfo(SPI_GET3D, 0, (LPVOID) &dwFlags, 0);
  55.         UINT nColor = (dwFlags & F3D_OFFICE3D) ? COLOR_3DFACE : COLOR_3DLIGHT;
  56.         HDC hdc = ::GetDC(NULL);
  57.         clrCtlBk = GetNearestColor(hdc, GetSysColor(nColor));
  58.         ::ReleaseDC(NULL, hdc);
  59.     }
  60.  
  61.     // save the requested background color
  62.     pWinState->m_crDlgBkClr = clrCtlBk;
  63. #endif
  64.  
  65.     pWinState->m_hDlgBkBrush = ::CreateSolidBrush(clrCtlBk);
  66.     pWinState->m_crDlgTextClr = clrCtlText;
  67.     if (pWinState->m_hDlgBkBrush == NULL)
  68.         AfxThrowResourceException();
  69. }
  70.  
  71. /////////////////////////////////////////////////////////////////////////////
  72.