home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / ole / wordpad / splash.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  3KB  |  128 lines

  1. // splash.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "wordpad.h"
  15.  
  16. #ifdef _DEBUG
  17. #undef THIS_FILE
  18. static char BASED_CODE THIS_FILE[] = __FILE__;
  19. #endif
  20.  
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CSplashWnd dialog
  23.  
  24. BOOL CSplashWnd::Create(CWnd* pParent)
  25. {
  26.     //{{AFX_DATA_INIT(CSplashWnd)
  27.         // NOTE: the ClassWizard will add member initialization here
  28.     //}}AFX_DATA_INIT
  29.  
  30.     if (!CDialog::Create(CSplashWnd::IDD, pParent))
  31.     {
  32.         TRACE0("Warning: creation of CSplashWnd dialog failed\n");
  33.         return FALSE;
  34.     }
  35.  
  36.     return TRUE;
  37. }
  38.  
  39. BOOL CSplashWnd::OnInitDialog()
  40. {
  41.     CDialog::OnInitDialog();
  42.     CenterWindow();
  43.  
  44.     // initialize the big icon control
  45.     m_icon.SubclassDlgItem(IDC_BIGICON, this);
  46.     m_icon.SizeToContent();
  47.  
  48.     return TRUE;  // return TRUE  unless you set the focus to a control
  49. }
  50.  
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CSplashWnd message handlers
  53.  
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CBigIcon
  56.  
  57. BEGIN_MESSAGE_MAP(CBigIcon, CButton)
  58.     //{{AFX_MSG_MAP(CBigIcon)
  59.     ON_WM_DRAWITEM()
  60.     ON_WM_ERASEBKGND()
  61.     //}}AFX_MSG_MAP
  62. END_MESSAGE_MAP()
  63.  
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CBigIcon message handlers
  66.  
  67. #define CY_SHADOW   4
  68. #define CX_SHADOW   4
  69.  
  70. void CBigIcon::SizeToContent()
  71. {
  72.     m_bitmap.LoadBitmap(IDB_BITMAP48);
  73.     BITMAP bm;
  74.     m_bitmap.GetObject(sizeof(bm), &bm);
  75.     m_sizeBitmap = CSize(bm.bmWidth, bm.bmHeight);
  76.     // get system icon size
  77.  
  78.     // a big icon should be twice the size of an icon + shadows
  79.     SetWindowPos(NULL, 0, 0, bm.bmWidth + CX_SHADOW + 4, bm.bmHeight + CY_SHADOW + 4,
  80.         SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER);
  81. }
  82.  
  83. void CBigIcon::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
  84. {
  85.     CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
  86.     ASSERT(pDC != NULL);
  87.  
  88.     CRect rect;
  89.     GetClientRect(rect);
  90.     int cxClient = rect.Width();
  91.     int cyClient = rect.Height();
  92.  
  93.     // draw border around icon
  94.     CPen pen;
  95.     pen.CreateStockObject(BLACK_PEN);
  96.     CPen* pPenOld = pDC->SelectObject(&pen);
  97.     pDC->Rectangle(0, 0, cxClient-CX_SHADOW, cyClient-CY_SHADOW);
  98.     if (pPenOld)
  99.         pDC->SelectObject(pPenOld);
  100.  
  101.     // draw shadows around icon
  102.     CBrush br;
  103.     br.CreateStockObject(DKGRAY_BRUSH);
  104.     rect.SetRect(cxClient-CX_SHADOW, CY_SHADOW, cxClient, cyClient);
  105.     pDC->FillRect(rect, &br);
  106.     rect.SetRect(CX_SHADOW, cyClient-CY_SHADOW, cxClient, cyClient);
  107.     pDC->FillRect(rect, &br);
  108.  
  109.     // draw the bitmap contents
  110.     CDC dcMem;
  111.     if (!dcMem.CreateCompatibleDC(pDC))
  112.         return;
  113.     CBitmap* pBitmapOld = dcMem.SelectObject(&m_bitmap);
  114.     if (pBitmapOld == NULL)
  115.         return;
  116.  
  117.     pDC->BitBlt(2, 2, m_sizeBitmap.cx, m_sizeBitmap.cy, &dcMem, 0, 0, SRCCOPY);
  118.  
  119.     dcMem.SelectObject(pBitmapOld);
  120. }
  121.  
  122. BOOL CBigIcon::OnEraseBkgnd(CDC*)
  123. {
  124.     return TRUE;    // we don't do any erasing...
  125. }
  126.  
  127. /////////////////////////////////////////////////////////////////////////////
  128.