preview.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 4k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. /////////////////////////////////////////////////////////////////////////////
  2. // PREVIEW.CPP
  3. //
  4. // Implementation of CPreviewWindow
  5. //
  6. // History:
  7. //
  8. // Author   Date        Description
  9. // ------   ----        -----------
  10. // jaym     08/26/96    Created
  11. // jaym     02/03/97    Updated to use new CDIB class
  12. /////////////////////////////////////////////////////////////////////////////
  13. #include "precomp.h"
  14. #include "dib.h"
  15. #include "resource.h"
  16. #include "preview.h"
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CPreviewWindow
  19. /////////////////////////////////////////////////////////////////////////////
  20. CPreviewWindow::CPreviewWindow
  21. (
  22. )
  23. {
  24.     m_pDIB = NULL;
  25. }
  26. CPreviewWindow::~CPreviewWindow
  27. (
  28. )
  29. {
  30.     if (m_pDIB != NULL)
  31.         delete m_pDIB;
  32. }
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CPreviewWindow::Create
  35. /////////////////////////////////////////////////////////////////////////////
  36. BOOL CPreviewWindow::Create
  37. (
  38.     const RECT &    rect,
  39.     HWND            hwndParent
  40. )
  41. {
  42.     BOOL bResult = FALSE;
  43.     for (;;)
  44.     {
  45.         m_pDIB = new CDIB;
  46.         if (m_pDIB == NULL)
  47.             break;
  48.         if (!m_pDIB->LoadFromResource(  _pModule->GetResourceInstance(),
  49.                                         IDB_PREVIEW))
  50.         {
  51.             break;
  52.         }
  53.         bResult = CWindow::Create(  NULL,
  54.                                     ((hwndParent != NULL) ? WS_CHILD
  55.                                                           : WS_POPUP),
  56.                                     rect,
  57.                                     hwndParent,
  58.                                     0);
  59.         break;
  60.     }
  61.     if (!bResult)
  62.     {
  63.         // Cleanup
  64.         if (m_pDIB != NULL)
  65.             delete m_pDIB;
  66.     }
  67.     else
  68.         ShowWindow(SW_SHOWNORMAL);
  69.     return bResult;
  70. }
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CPreviewWindow::OnDestroy
  73. /////////////////////////////////////////////////////////////////////////////
  74. void CPreviewWindow::OnDestroy
  75. (
  76. )
  77. {
  78.     CWindow::OnDestroy();
  79.     PostQuitMessage(0);
  80. }
  81. /////////////////////////////////////////////////////////////////////////////
  82. // CPreviewWindow::OnPaint
  83. /////////////////////////////////////////////////////////////////////////////
  84.  void CPreviewWindow::OnPaint
  85. (
  86.     HDC             hDC,
  87.     PAINTSTRUCT *   ps
  88. )
  89. {
  90.     if (m_pDIB != NULL)
  91.     {
  92.         RECT rectDraw;
  93.         GetClientRect(&rectDraw);
  94.         m_pDIB->Draw(hDC, NULL, &rectDraw);
  95.     }
  96. }
  97. /////////////////////////////////////////////////////////////////////////////
  98. // CPreviewWindow::OnPaletteChanged
  99. /////////////////////////////////////////////////////////////////////////////
  100. void CPreviewWindow::OnPaletteChanged
  101. (
  102.     HWND hwndPalChng
  103. )
  104. {
  105.     // If we caused the palette change, do nothing.
  106.     if (hwndPalChng == m_hWnd)
  107.         return;
  108.     // Re-realize the palette.
  109.     OnQueryNewPalette();
  110. }
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CPreviewWindow::OnQueryNewPalette
  113. /////////////////////////////////////////////////////////////////////////////
  114. BOOL CPreviewWindow::OnQueryNewPalette
  115. (
  116. )
  117. {
  118.     HDC         hDC;
  119.     HPALETTE    hPalOld;
  120.     UINT        uRemapCount;
  121.     if ((hDC = GetDC()) == NULL)
  122.         return FALSE;
  123.     hPalOld = SelectPalette(hDC, m_pDIB->m_hPalette, FALSE);
  124.     uRemapCount = RealizePalette(hDC);
  125.     if (hPalOld != NULL)
  126.         SelectPalette(hDC, hPalOld, TRUE);
  127.     if (uRemapCount != 0)
  128.         SysPalChanged();
  129.     ReleaseDC(hDC);
  130.     return (BOOL)uRemapCount;
  131. }