home *** CD-ROM | disk | FTP | other *** search
/ distrib.akp.su/Programming/Vb-6+Rus/ / distrib.akp.su.tar / distrib.akp.su / Programming / Vb-6+Rus / COMMON / MSDEV98 / BIN / IDE / DEVGAL.PKG / TEMPLATE / 22332 < prev    next >
Text File  |  1998-06-18  |  15KB  |  599 lines

  1. // $$VAL:BaseDocCpp$$ : implementation of the $$VAL:BaseDocClass$$ class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "$$VAL:ResInclude$$"
  6.  
  7. #include "$$VAL:BaseDocHeader$$"
  8.  
  9. #ifdef _DEBUG
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // $$VAL:BaseDocClass$$
  16.  
  17. IMPLEMENT_DYNCREATE($$VAL:BaseDocClass$$, CDocument)
  18.  
  19. BEGIN_MESSAGE_MAP($$VAL:BaseDocClass$$, CDocument)
  20.     //{{AFX_MSG_MAP($$VAL:BaseDocClass$$)
  21.         // NOTE - the ClassWizard will add and remove mapping macros here.
  22.         //    DO NOT EDIT what you see in these blocks of generated code!
  23.     //}}AFX_MSG_MAP
  24. END_MESSAGE_MAP()
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // $$VAL:BaseDocClass$$ construction/destruction
  28.  
  29. $$VAL:BaseDocClass$$::$$VAL:BaseDocClass$$()
  30. {
  31. }
  32.  
  33. $$VAL:BaseDocClass$$::~$$VAL:BaseDocClass$$()
  34. {
  35. }
  36.  
  37. BOOL $$VAL:BaseDocClass$$::OnNewDocument()
  38. {
  39.     if (!CDocument::OnNewDocument())
  40.         return FALSE;
  41.  
  42.     // TODO: add reinitialization code here
  43.     // (SDI documents will reuse this document)
  44.  
  45.     return TRUE;
  46. }
  47.  
  48. /////////////////////////////////////////////////////////////////////////////
  49. // $$VAL:BaseDocClass$$ serialization
  50.  
  51. void $$VAL:BaseDocClass$$::Serialize(CArchive& ar)
  52. {
  53.     if (ar.IsStoring())
  54.     {
  55.         // TODO: add storing code here
  56.     }
  57.     else
  58.     {
  59.         // TODO: add loading code here
  60.     }
  61. }
  62.  
  63. /////////////////////////////////////////////////////////////////////////////
  64. // $$VAL:BaseDocClass$$ diagnostics
  65.  
  66. #ifdef _DEBUG
  67. void $$VAL:BaseDocClass$$::AssertValid() const
  68. {
  69.     CDocument::AssertValid();
  70. }
  71.  
  72. void $$VAL:BaseDocClass$$::Dump(CDumpContext& dc) const
  73. {
  74.     CDocument::Dump(dc);
  75. }
  76. #endif //_DEBUG
  77.  
  78. /////////////////////////////////////////////////////////////////////////////
  79. // $$VAL:BaseDocClass$$ commands
  80.  
  81. // NOTE: To change the standard colors, change these values:
  82. static RGBQUAD rgbStdColors[] =
  83. {
  84.     {   0,  0,  0, 0 },
  85.     {   0,  0,128, 0 },
  86.     {   0,128,  0, 0 },
  87.     {   0,128,128, 0 },
  88.     { 128,  0,  0, 0 },
  89.     { 128,  0,128, 0 },
  90.     { 128,128,  0, 0 },
  91.     { 192,192,192, 0 },
  92.     { 192,220,192, 0 },
  93.     { 240,202,166, 0 },
  94.     { 238,238,238, 0 },
  95.     { 221,221,221, 0 },
  96.     { 204,204,204, 0 },
  97.     { 187,187,187, 0 },
  98.     { 170,170,170, 0 },
  99.     { 153,153,153, 0 },
  100.     { 136,136,136, 0 },
  101.     { 119,119,119, 0 },
  102.     { 102,102,102, 0 },
  103.     {  85, 85, 85, 0 },
  104.     {  68, 68, 68, 0 },
  105.     {  51, 51, 51, 0 },
  106.     {  34, 34, 34, 0 },
  107.     {  17, 17, 17, 0 },
  108.     { 204,255,255, 0 },
  109.     { 153,255,255, 0 },
  110.     { 102,255,255, 0 },
  111.     {  51,255,255, 0 },
  112.     { 255,204,255, 0 },
  113.     { 204,204,255, 0 },
  114.     { 153,204,255, 0 },
  115.     { 102,204,255, 0 },
  116.     {  51,204,255, 0 },
  117.     {   0,204,255, 0 },
  118.     { 255,153,255, 0 },
  119.     { 204,153,255, 0 },
  120.     { 153,153,255, 0 },
  121.     { 102,153,255, 0 },
  122.     {  51,153,255, 0 },
  123.     {   0,153,255, 0 },
  124.     { 255,102,255, 0 },
  125.     { 204,102,255, 0 },
  126.     { 153,102,255, 0 },
  127.     { 102,102,255, 0 },
  128.     {  51,102,255, 0 },
  129.     {   0,102,255, 0 },
  130.     { 255, 51,255, 0 },
  131.     { 204, 51,255, 0 },
  132.     { 153, 51,255, 0 },
  133.     { 102, 51,255, 0 },
  134.     {  51, 51,255, 0 },
  135.     {   0, 51,255, 0 },
  136.     { 204,  0,255, 0 },
  137.     { 153,  0,255, 0 },
  138.     { 102,  0,255, 0 },
  139.     {  51,  0,255, 0 },
  140.     { 255,255,204, 0 },
  141.     { 204,255,204, 0 },
  142.     { 153,255,204, 0 },
  143.     { 102,255,204, 0 },
  144.     {  51,255,204, 0 },
  145.     {   0,255,204, 0 },
  146.     { 255,204,204, 0 },
  147.     { 153,204,204, 0 },
  148.     { 102,204,204, 0 },
  149.     {  51,204,204, 0 },
  150.     {   0,204,204, 0 },
  151.     { 255,153,204, 0 },
  152.     { 204,153,204, 0 },
  153.     { 153,153,204, 0 },
  154.     { 102,153,204, 0 },
  155.     {  51,153,204, 0 },
  156.     {   0,153,204, 0 },
  157.     { 255,102,204, 0 },
  158.     { 204,102,204, 0 },
  159.     { 153,102,204, 0 },
  160.     { 102,102,204, 0 },
  161.     {  51,102,204, 0 },
  162.     {   0,102,204, 0 },
  163.     { 255, 51,204, 0 },
  164.     { 204, 51,204, 0 },
  165.     { 153, 51,204, 0 },
  166.     { 102, 51,204, 0 },
  167.     {  51, 51,204, 0 },
  168.     {   0, 51,204, 0 },
  169.     { 255,  0,204, 0 },
  170.     { 204,  0,204, 0 },
  171.     { 153,  0,204, 0 },
  172.     { 102,  0,204, 0 },
  173.     {  51,  0,204, 0 },
  174.     { 255,255,153, 0 },
  175.     { 204,255,153, 0 },
  176.     { 153,255,153, 0 },
  177.     { 102,255,153, 0 },
  178.     {  51,255,153, 0 },
  179.     {   0,255,153, 0 },
  180.     { 255,204,153, 0 },
  181.     { 204,204,153, 0 },
  182.     { 153,204,153, 0 },
  183.     { 102,204,153, 0 },
  184.     {  51,204,153, 0 },
  185.     {   0,204,153, 0 },
  186.     { 255,153,153, 0 },
  187.     { 204,153,153, 0 },
  188.     { 102,153,153, 0 },
  189.     {  51,153,153, 0 },
  190.     {   0,153,153, 0 },
  191.     { 255,102,153, 0 },
  192.     { 204,102,153, 0 },
  193.     { 153,102,153, 0 },
  194.     { 102,102,153, 0 },
  195.     {  51,102,153, 0 },
  196.     {   0,102,153, 0 },
  197.     { 255, 51,153, 0 },
  198.     { 204, 51,153, 0 },
  199.     { 153, 51,153, 0 },
  200.     { 102, 51,153, 0 },
  201.     {  51, 51,153, 0 },
  202.     {   0, 51,153, 0 },
  203.     { 255,  0,153, 0 },
  204.     { 204,  0,153, 0 },
  205.     { 153,  0,153, 0 },
  206.     { 102,  0,153, 0 },
  207.     {  51,  0,153, 0 },
  208.     { 255,255,102, 0 },
  209.     { 204,255,102, 0 },
  210.     { 153,255,102, 0 },
  211.     { 102,255,102, 0 },
  212.     {  51,255,102, 0 },
  213.     {   0,255,102, 0 },
  214.     { 255,204,102, 0 },
  215.     { 204,204,102, 0 },
  216.     { 153,204,102, 0 },
  217.     { 102,204,102, 0 },
  218.     {  51,204,102, 0 },
  219.     {   0,204,102, 0 },
  220.     { 255,153,102, 0 },
  221.     { 204,153,102, 0 },
  222.     { 153,153,102, 0 },
  223.     { 102,153,102, 0 },
  224.     {  51,153,102, 0 },
  225.     {   0,153,102, 0 },
  226.     { 255,102,102, 0 },
  227.     { 204,102,102, 0 },
  228.     { 153,102,102, 0 },
  229.     {  51,102,102, 0 },
  230.     {   0,102,102, 0 },
  231.     { 255, 51,102, 0 },
  232.     { 204, 51,102, 0 },
  233.     { 153, 51,102, 0 },
  234.     { 102, 51,102, 0 },
  235.     {  51, 51,102, 0 },
  236.     {   0, 51,102, 0 },
  237.     { 255,  0,102, 0 },
  238.     { 204,  0,102, 0 },
  239.     { 153,  0,102, 0 },
  240.     { 102,  0,102, 0 },
  241.     {  51,  0,102, 0 },
  242.     { 255,255, 51, 0 },
  243.     { 204,255, 51, 0 },
  244.     { 153,255, 51, 0 },
  245.     { 102,255, 51, 0 },
  246.     {  51,255, 51, 0 },
  247.     {   0,255, 51, 0 },
  248.     { 255,204, 51, 0 },
  249.     { 204,204, 51, 0 },
  250.     { 153,204, 51, 0 },
  251.     { 102,204, 51, 0 },
  252.     {  51,204, 51, 0 },
  253.     {   0,204, 51, 0 },
  254.     { 255,153, 51, 0 },
  255.     { 204,153, 51, 0 },
  256.     { 153,153, 51, 0 },
  257.     { 102,153, 51, 0 },
  258.     {  51,153, 51, 0 },
  259.     {   0,153, 51, 0 },
  260.     { 255,102, 51, 0 },
  261.     { 204,102, 51, 0 },
  262.     { 153,102, 51, 0 },
  263.     { 102,102, 51, 0 },
  264.     {  51,102, 51, 0 },
  265.     {   0,102, 51, 0 },
  266.     { 255, 51, 51, 0 },
  267.     { 204, 51, 51, 0 },
  268.     { 153, 51, 51, 0 },
  269.     { 102, 51, 51, 0 },
  270.     {   0, 51, 51, 0 },
  271.     { 255,  0, 51, 0 },
  272.     { 204,  0, 51, 0 },
  273.     { 153,  0, 51, 0 },
  274.     { 102,  0, 51, 0 },
  275.     {  51,  0, 51, 0 },
  276.     { 204,255,  0, 0 },
  277.     { 153,255,  0, 0 },
  278.     { 102,255,  0, 0 },
  279.     {  51,255,  0, 0 },
  280.     { 255,204,  0, 0 },
  281.     { 204,204,  0, 0 },
  282.     { 153,204,  0, 0 },
  283.     { 102,204,  0, 0 },
  284.     {  51,204,  0, 0 },
  285.     { 255,153,  0, 0 },
  286.     { 204,153,  0, 0 },
  287.     { 153,153,  0, 0 },
  288.     { 102,153,  0, 0 },
  289.     {   0,  0,238, 0 },
  290.     {   0,  0,221, 0 },
  291.     {   0,  0,204, 0 },
  292.     {   0,  0,187, 0 },
  293.     {   0,  0,170, 0 },
  294.     {   0,  0,153, 0 },
  295.     {   0,  0,136, 0 },
  296.     {   0,  0,119, 0 },
  297.     {   0,  0,102, 0 },
  298.     {   0,  0, 85, 0 },
  299.     {   0,  0, 68, 0 },
  300.     {   0,  0, 51, 0 },
  301.     {   0,  0, 34, 0 },
  302.     {   0,  0, 17, 0 },
  303.     {   0,238,  0, 0 },
  304.     {   0,221,  0, 0 },
  305.     {   0,204,  0, 0 },
  306.     {   0,187,  0, 0 },
  307.     {   0,170,  0, 0 },
  308.     {   0,153,  0, 0 },
  309.     {   0,136,  0, 0 },
  310.     {   0,119,  0, 0 },
  311.     {   0,102,  0, 0 },
  312.     {   0, 85,  0, 0 },
  313.     {   0, 68,  0, 0 },
  314.     {   0, 51,  0, 0 },
  315.     {   0, 34,  0, 0 },
  316.     {   0, 17,  0, 0 },
  317.     { 238,  0,  0, 0 },
  318.     { 221,  0,  0, 0 },
  319.     { 204,  0,  0, 0 },
  320.     { 187,  0,  0, 0 },
  321.     { 170,  0,  0, 0 },
  322.     { 153,  0,  0, 0 },
  323.     { 136,  0,  0, 0 },
  324.     { 119,  0,  0, 0 },
  325.     { 102,  0,  0, 0 },
  326.     {  85,  0,  0, 0 },
  327.     {  68,  0,  0, 0 },
  328.     {  51,  0,  0, 0 },
  329.     {  34,  0,  0, 0 },
  330.     { 240,251,255, 0 },
  331.     { 164,160,160, 0 },
  332.     { 128,128,128, 0 },
  333.     {   0,  0,255, 0 },
  334.     {   0,255,  0, 0 },
  335.     {   0,255,255, 0 },
  336.     { 255,  0,  0, 0 },
  337.     { 255,  0,255, 0 },
  338.     { 255,255,  0, 0 },
  339.     { 255,255,255, 0 }
  340. };
  341.  
  342. BOOL $$VAL:BaseDocClass$$::NormalizeColors(LPBITMAPINFO lpbiDest, LPBITMAPINFO lpbiSrc)
  343. {
  344.     // If we have too few colors, put our entries in the middle, and use colors
  345.     // from the standard palette to fill in the beginning and end of the palette.
  346.     // If we have too many colors, use the first (cColorsWanted / 2) and the last
  347.     // (cColorsWanted / 2) colors from the palette.
  348.  
  349.     UINT cColorsWanted = 1 << lpbiDest->bmiHeader.biBitCount;
  350.     ASSERT(cColorsWanted == 2 || cColorsWanted == 16 || cColorsWanted == 256);
  351.     UINT cHaveColors = 1 << lpbiSrc->bmiHeader.biBitCount;
  352.     if (cColorsWanted < cHaveColors)
  353.     {
  354.         // we know cColorsWanted will be even, so this is ok
  355.         ASSERT(cColorsWanted % 2 == 0);
  356.  
  357.         // copy the first half
  358.         memcpy(&lpbiDest->bmiColors[0],
  359.             &lpbiSrc->bmiColors[0],
  360.             (cColorsWanted / 2) * sizeof(RGBQUAD));
  361.  
  362.         // copy the second half
  363.         memcpy(&lpbiDest->bmiColors[cColorsWanted / 2],
  364.             &lpbiSrc->bmiColors[cHaveColors - (cColorsWanted / 2)],
  365.             (cColorsWanted / 2) * sizeof(RGBQUAD));
  366.     }
  367.     else
  368.     {
  369.         // cHaveColors might not be even...
  370.         UINT cNeedColors = cColorsWanted - cHaveColors;
  371.         UINT cFirstColors = cNeedColors / 2;
  372.         UINT cLastColors = cNeedColors - cFirstColors;
  373.  
  374.         // insert cFirstColors standard colors into our palette
  375.         memcpy(&lpbiDest->bmiColors[0],
  376.             &rgbStdColors[0],
  377.             cFirstColors * sizeof(RGBQUAD));
  378.  
  379.         // set the middle colors equal to the old colors
  380.         memcpy(&lpbiDest->bmiColors[cFirstColors],
  381.             &lpbiSrc->bmiColors[0],
  382.             cHaveColors * sizeof(RGBQUAD));
  383.  
  384.         // and set the last cLastColors to standard colors
  385.         memcpy(&lpbiDest->bmiColors[cColorsWanted - cLastColors],
  386.             &rgbStdColors[256 - cLastColors],
  387.             cLastColors * sizeof(RGBQUAD));
  388.     }
  389.  
  390.     return TRUE;
  391. }
  392.  
  393. #define WIDTHBYTES(bits) ((((bits) + 31) / 32) * 4)
  394. BOOL $$VAL:BaseDocClass$$::OnOpenDocument(LPCTSTR lpszPathName) 
  395. {
  396.     // Read the DIB in, and create a DIBSECTION.
  397.     SECURITY_ATTRIBUTES sa;
  398.     sa.nLength = sizeof(SECURITY_ATTRIBUTES);
  399.     sa.lpSecurityDescriptor = NULL;
  400.     sa.bInheritHandle = FALSE;
  401.  
  402.     // Open the file
  403.     HANDLE hFile = CreateFile(lpszPathName,
  404.         GENERIC_READ, FILE_SHARE_READ, &sa, OPEN_EXISTING,
  405.         FILE_ATTRIBUTE_NORMAL, NULL);
  406.     if (hFile == NULL)
  407.     {
  408.         DoMessageBox(CString(_T("OnOpenDocument: Cannot open file")));
  409.         return FALSE;
  410.     }
  411.  
  412.     // Create a mapping
  413.     HANDLE hMap = CreateFileMapping(hFile, &sa, PAGE_READONLY, 
  414.         0, 0, NULL);
  415.     if (hMap == NULL)
  416.     {
  417.         VERIFY(CloseHandle(hFile));
  418.         DoMessageBox(CString(_T("OnOpenDocument: Cannot create file mapping")));
  419.         return FALSE;
  420.     }
  421.  
  422.     // Map a view of the file
  423.     LPVOID lpFile = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0);
  424.     if (lpFile == NULL)
  425.     {
  426.         VERIFY(CloseHandle(hMap));
  427.         VERIFY(CloseHandle(hFile));
  428.         DoMessageBox(CString(_T("OnOpenDocument: Cannot map view of file")));
  429.         return FALSE;
  430.     }
  431.  
  432.     // Convert the Bitmap file into a DIB Section
  433.     // BLOCK: Verify the file header
  434.     LPVOID lpBits;
  435.     {
  436.         LPBITMAPFILEHEADER lpfh = (LPBITMAPFILEHEADER) lpFile;
  437.         if (lpfh->bfType != ((WORD) 'B' | ('M' << 8)))
  438.         {
  439.             VERIFY(UnmapViewOfFile(lpFile));
  440.             VERIFY(CloseHandle(hMap));
  441.             VERIFY(CloseHandle(hFile));
  442.             DoMessageBox(CString(_T("OnOpenDocument: Unrecognized file type")));
  443.             return FALSE;
  444.         }
  445.  
  446.         lpBits = (LPBYTE) lpFile + lpfh->bfOffBits;
  447.     }
  448.  
  449.     LPBITMAPINFO lpbi = (LPBITMAPINFO) ((LPBITMAPFILEHEADER)lpFile + 1);
  450.     // BLOCK: This code only supports 2, 16, and 256 color bitmaps
  451.     {
  452.         if (lpbi->bmiHeader.biBitCount != 1 &&
  453.             lpbi->bmiHeader.biBitCount != 4 &&
  454.                 lpbi->bmiHeader.biBitCount != 8)
  455.         {
  456.             VERIFY( UnmapViewOfFile( lpFile ) );
  457.             VERIFY( CloseHandle( hMap ) );
  458.             VERIFY( CloseHandle( hFile ) );
  459.             DoMessageBox(CString(_T("OnOpenDocument: Unsupported number of colors")));
  460.             return FALSE;
  461.         }
  462.     }
  463.  
  464.     // Get the size of the bits
  465.     DWORD dwBits = lpbi->bmiHeader.biHeight *
  466.         WIDTHBYTES(lpbi->bmiHeader.biWidth * lpbi->bmiHeader.biBitCount);
  467.     if (lpbi->bmiHeader.biSizeImage != 0)
  468.         dwBits = lpbi->bmiHeader.biSizeImage;
  469.  
  470.     // Get the size of the color table
  471.     UINT cColors = 1 << lpbi->bmiHeader.biBitCount;
  472.     if (lpbi->bmiHeader.biClrUsed != 0)
  473.         cColors = lpbi->bmiHeader.biClrUsed;
  474.  
  475.     // BLOCK: Create a DIB section
  476.     LPVOID lpDest;
  477.     HBITMAP hDib;
  478.     LPBITMAPINFO lpbiNew;
  479.     {
  480.         lpbiNew = (LPBITMAPINFO) new
  481.             BYTE[sizeof(BITMAPINFOHEADER) + (sizeof(RGBQUAD) * 256)];
  482.  
  483.         // NOTE: If you want to change the memory format of the DIB,
  484.         // change this code:
  485.         lpbiNew->bmiHeader = lpbi->bmiHeader;
  486.         lpbiNew->bmiHeader.biBitCount = 8;
  487.         lpbiNew->bmiHeader.biCompression = BI_RGB;
  488.         lpbiNew->bmiHeader.biSizeImage = 0;
  489.         NormalizeColors( lpbiNew, lpbi );
  490.  
  491.         hDib = CreateDIBSection( NULL, lpbiNew, DIB_RGB_COLORS, &lpDest, NULL, 0);
  492.         if (hDib == NULL)
  493.         {
  494.             delete [] (BYTE *)lpbiNew;
  495.             VERIFY( UnmapViewOfFile( lpFile ) );
  496.             VERIFY( CloseHandle( hMap ) );
  497.             VERIFY( CloseHandle( hFile ) );
  498.             DoMessageBox(CString(_T("OnOpenDocument: Cannot create DIB format")));
  499.             return FALSE;
  500.         }
  501.         ASSERT( lpDest != NULL );
  502.     }
  503.  
  504.     // BLOCK: Set the DIB sections bits from the DIB we are loading
  505.     {
  506.         CWindowDC dc(NULL);
  507.         VERIFY( SetDIBits( dc.m_hDC, hDib,
  508.             0, lpbi->bmiHeader.biHeight,
  509.             lpBits, lpbi, DIB_RGB_COLORS ) == lpbi->bmiHeader.biHeight );
  510.     }
  511.  
  512.     // Attach the new bitmap to our document, and inform our views of the change
  513.     DeleteContents();
  514.     m_Bitmap.Attach( hDib );
  515.     UpdateAllViews( NULL );
  516.  
  517.     // Create a palette
  518.     CWindowDC dc(NULL);
  519.     if (dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE)
  520.     {
  521.         LPLOGPALETTE lpLogPal;
  522.         lpLogPal = (LPLOGPALETTE) new
  523.             BYTE[sizeof(LOGPALETTE) + ((255) * sizeof(PALETTEENTRY))];
  524.  
  525.         lpLogPal->palVersion = 0x0300;
  526.         lpLogPal->palNumEntries = 256;
  527.  
  528.         for (UINT i = 0; i < cColors; i++)
  529.         {
  530.             lpLogPal->palPalEntry[i].peRed = lpbiNew->bmiColors[i].rgbRed;
  531.             lpLogPal->palPalEntry[i].peGreen = lpbiNew->bmiColors[i].rgbGreen;
  532.             lpLogPal->palPalEntry[i].peBlue = lpbiNew->bmiColors[i].rgbBlue;
  533.             lpLogPal->palPalEntry[i].peFlags = 0;
  534.         }
  535.  
  536.         VERIFY( m_Palette.CreatePalette( lpLogPal ) );
  537.         delete [] (BYTE *)lpLogPal;
  538.  
  539.         // BLOCK: Reset the active palette
  540.         {
  541.             CWnd* pActiveWnd = CWnd::GetActiveWindow();
  542.             if (pActiveWnd != NULL)
  543.                 pActiveWnd->SendMessage(WM_QUERYNEWPALETTE);
  544.         }
  545.     }
  546.  
  547.     // Put stuff back
  548.     delete [] (BYTE *)lpbiNew;
  549.     VERIFY( UnmapViewOfFile( lpFile ) );
  550.     VERIFY( CloseHandle( hMap ) );
  551.     VERIFY( CloseHandle( hFile ) );
  552.  
  553.     return TRUE;
  554. }
  555.  
  556. void $$VAL:BaseDocClass$$::DoMessageBox(CString str)
  557. {
  558.     CWnd* pActiveWnd = CWnd::GetActiveWindow();
  559.     if (pActiveWnd != NULL)
  560.         pActiveWnd->MessageBox(str);
  561. }
  562.  
  563.  
  564. BOOL $$VAL:BaseDocClass$$::OnSaveDocument(LPCTSTR lpszPathName) 
  565. {
  566.     // this class doesn't implement saving anything
  567.     ASSERT(FALSE);
  568.     return FALSE;
  569. }
  570.  
  571. CSize $$VAL:BaseDocClass$$::GetSize() const
  572. {
  573.     if (m_Bitmap.m_hObject == NULL)
  574.         return CSize(0,0);
  575.  
  576.     BITMAP bm;
  577.     m_Bitmap.GetObject( sizeof(BITMAP), &bm );
  578.     return CSize(bm.bmWidth, bm.bmHeight);
  579. }
  580.  
  581. CPalette* $$VAL:BaseDocClass$$::GetPalette()
  582. {
  583.     if (m_Palette.m_hObject == NULL)
  584.         return NULL;
  585.  
  586.     return &m_Palette;
  587. }
  588.  
  589.  
  590. void $$VAL:BaseDocClass$$::DeleteContents() 
  591. {
  592.     if (m_Bitmap.m_hObject != NULL)
  593.         m_Bitmap.DeleteObject();
  594.     if (m_Palette.m_hObject != NULL)
  595.         m_Palette.DeleteObject();
  596.  
  597.     CDocument::DeleteContents();
  598. }
  599.