home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 December / PCWKCD1296.iso / vjplusb / activex / inetsdk / samples / urlpad / aboutbox.cpp next >
Encoding:
C/C++ Source or Header  |  1996-05-29  |  6.1 KB  |  229 lines

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