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

  1. // aboutbox.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.  
  14.  
  15. #include "stdafx.h"
  16. #include "resource.h"
  17. #include "aboutbox.h"
  18. #include <dos.h>
  19. #include <direct.h>
  20.  
  21. #ifdef _DEBUG
  22. #undef THIS_FILE
  23. static char BASED_CODE THIS_FILE[] = __FILE__;
  24. #endif
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CAboutBox dialog
  28.  
  29. BEGIN_MESSAGE_MAP(CAboutBox, CDialog)
  30.     //{{AFX_MSG_MAP(CAboutBox)
  31.     //}}AFX_MSG_MAP
  32. END_MESSAGE_MAP()
  33.  
  34. CAboutBox::CAboutBox(CWnd* pParent /*=NULL*/)
  35.     : CDialog(CAboutBox::IDD, pParent)
  36. {
  37.     //{{AFX_DATA_INIT(CAboutBox)
  38.         // NOTE: the ClassWizard will add member initialization here
  39.     //}}AFX_DATA_INIT
  40. }
  41.  
  42. void CAboutBox::DoDataExchange(CDataExchange* pDX)
  43. {
  44.     CDialog::DoDataExchange(pDX);
  45.     //{{AFX_DATA_MAP(CAboutBox)
  46.         // NOTE: the ClassWizard will add DDX and DDV calls here
  47.     //}}AFX_DATA_MAP
  48. }
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CAboutBox message handlers
  52.  
  53. BOOL CAboutBox::OnInitDialog()
  54. {
  55.     CDialog::OnInitDialog();
  56.  
  57.     // initialize the big icon control
  58.     m_icon.SubclassDlgItem(IDC_BIGICON, this);
  59.     m_icon.SizeToContent();
  60.  
  61.     // fill available memory
  62.     CString str, strFmt;
  63.     strFmt.LoadString(IDS_PHYSICAL_MEM);
  64.  
  65.     MEMORYSTATUS MemStat;
  66.     MemStat.dwLength = sizeof(MEMORYSTATUS);
  67.     GlobalMemoryStatus(&MemStat);
  68.     wsprintf(str.GetBuffer(80), strFmt, MemStat.dwTotalPhys / 1024L);
  69.     str.ReleaseBuffer();
  70.     SetDlgItemText(IDC_PHYSICAL_MEM, str);
  71.  
  72.     // fill disk free information
  73.     struct _diskfree_t diskfree;
  74.     if (_getdiskfree(_getdrive(), &diskfree) == 0)
  75.     {
  76.         strFmt.LoadString(IDS_DISK_SPACE);
  77.         wsprintf(str.GetBuffer(80), strFmt,
  78.             (DWORD)diskfree.avail_clusters *
  79.             (DWORD)diskfree.sectors_per_cluster *
  80.             (DWORD)diskfree.bytes_per_sector / (DWORD)1024L);
  81.         str.ReleaseBuffer();
  82.     }
  83.     else
  84.         str.LoadString(IDS_DISK_SPACE_UNAVAIL);
  85.     SetDlgItemText(IDC_DISK_SPACE, str);
  86.  
  87.     return TRUE;  // return TRUE  unless you set the focus to a control
  88. }
  89.  
  90. /////////////////////////////////////////////////////////////////////////////
  91. // CSplashWnd dialog
  92.  
  93. BEGIN_MESSAGE_MAP(CSplashWnd, CDialog)
  94.     //{{AFX_MSG_MAP(CSplashWnd)
  95.     //}}AFX_MSG_MAP
  96. END_MESSAGE_MAP()
  97.  
  98. void CSplashWnd::DoDataExchange(CDataExchange* pDX)
  99. {
  100.     CDialog::DoDataExchange(pDX);
  101.     //{{AFX_DATA_MAP(CSplashWnd)
  102.         // NOTE: the ClassWizard will add DDX and DDV calls here
  103.     //}}AFX_DATA_MAP
  104. }
  105.  
  106. BOOL CSplashWnd::Create(CWnd* pParent)
  107. {
  108.     //{{AFX_DATA_INIT(CSplashWnd)
  109.         // NOTE: the ClassWizard will add member initialization here
  110.     //}}AFX_DATA_INIT
  111.  
  112.     if (!CDialog::Create(CSplashWnd::IDD, pParent))
  113.     {
  114.         TRACE0("Warning: creation of CSplashWnd dialog failed\n");
  115.         return FALSE;
  116.     }
  117.  
  118.     return TRUE;
  119. }
  120.  
  121. BOOL CSplashWnd::OnInitDialog()
  122. {
  123.     CDialog::OnInitDialog();
  124.     CenterWindow();
  125.  
  126.     // initialize the big icon control
  127.     m_icon.SubclassDlgItem(IDC_BIGICON, this);
  128.     m_icon.SizeToContent();
  129.  
  130.     return TRUE;  // return TRUE  unless you set the focus to a control
  131. }
  132.  
  133. /////////////////////////////////////////////////////////////////////////////
  134. // CSplashWnd message handlers
  135.  
  136. /////////////////////////////////////////////////////////////////////////////
  137. // CBigIcon
  138.  
  139. BEGIN_MESSAGE_MAP(CBigIcon, CButton)
  140.     //{{AFX_MSG_MAP(CBigIcon)
  141.     ON_WM_DRAWITEM()
  142.     ON_WM_ERASEBKGND()
  143.     //}}AFX_MSG_MAP
  144. END_MESSAGE_MAP()
  145.  
  146. /////////////////////////////////////////////////////////////////////////////
  147. // CBigIcon message handlers
  148.  
  149. #define CY_SHADOW   4
  150. #define CX_SHADOW   4
  151.  
  152. void CBigIcon::SizeToContent()
  153. {
  154.     // get system icon size
  155.     int cxIcon = ::GetSystemMetrics(SM_CXICON);
  156.     int cyIcon = ::GetSystemMetrics(SM_CYICON);
  157.  
  158.     // a big icon should be twice the size of an icon + shadows
  159.     SetWindowPos(NULL, 0, 0, cxIcon*2 + CX_SHADOW + 4, cyIcon*2 + CY_SHADOW + 4,
  160.         SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER);
  161. }
  162.  
  163. void CBigIcon::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
  164. {
  165.     CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
  166.     ASSERT(pDC != NULL);
  167.  
  168.     CRect rect;
  169.     GetClientRect(rect);
  170.     int cxClient = rect.Width();
  171.     int cyClient = rect.Height();
  172.  
  173.     // load icon
  174.     HICON hicon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  175.     if (hicon == NULL)
  176.         return;
  177.  
  178.     // draw icon into off-screen bitmap
  179.     int cxIcon = ::GetSystemMetrics(SM_CXICON);
  180.     int cyIcon = ::GetSystemMetrics(SM_CYICON);
  181.  
  182.     CBitmap bitmap;
  183.     if (!bitmap.CreateCompatibleBitmap(pDC, cxIcon, cyIcon))
  184.         return;
  185.     CDC dcMem;
  186.     if (!dcMem.CreateCompatibleDC(pDC))
  187.         return;
  188.     CBitmap* pBitmapOld = dcMem.SelectObject(&bitmap);
  189.     if (pBitmapOld == NULL)
  190.         return;
  191.  
  192.     // blt the bits already on the window onto the off-screen bitmap
  193.     dcMem.StretchBlt(0, 0, cxIcon, cyIcon, pDC,
  194.         2, 2, cxClient-CX_SHADOW-4, cyClient-CY_SHADOW-4, SRCCOPY);
  195.  
  196.     // draw the icon on the background
  197.     dcMem.DrawIcon(0, 0, hicon);
  198.  
  199.     // draw border around icon
  200.     CPen pen;
  201.     pen.CreateStockObject(BLACK_PEN);
  202.     CPen* pPenOld = pDC->SelectObject(&pen);
  203.     pDC->Rectangle(0, 0, cxClient-CX_SHADOW, cyClient-CY_SHADOW);
  204.     if (pPenOld)
  205.         pDC->SelectObject(pPenOld);
  206.  
  207.     // draw shadows around icon
  208.     CBrush br;
  209.     br.CreateStockObject(DKGRAY_BRUSH);
  210.     rect.SetRect(cxClient-CX_SHADOW, CY_SHADOW, cxClient, cyClient);
  211.     pDC->FillRect(rect, &br);
  212.     rect.SetRect(CX_SHADOW, cyClient-CY_SHADOW, cxClient, cyClient);
  213.     pDC->FillRect(rect, &br);
  214.  
  215.     // draw the icon contents
  216.     pDC->StretchBlt(2, 2, cxClient-CX_SHADOW-4, cyClient-CY_SHADOW-4,
  217.         &dcMem, 0, 0, cxIcon, cyIcon, SRCCOPY);
  218. }
  219.  
  220. BOOL CBigIcon::OnEraseBkgnd(CDC*)
  221. {
  222.     return TRUE;    // we don't do any erasing...
  223. }
  224.  
  225. /////////////////////////////////////////////////////////////////////////////
  226.