home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / mslang / ttips2 / splash.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-13  |  6.0 KB  |  233 lines

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