home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / general / saver / saver.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  3.9 KB  |  133 lines

  1. // Saver.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Saver.h"
  6. #include "drawwnd.h"
  7. #include "Saverdlg.h"
  8. #include "saverwnd.h"
  9.  
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static char BASED_CODE THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CSaverApp
  17.  
  18. BEGIN_MESSAGE_MAP(CSaverApp, CWinApp)
  19.     //{{AFX_MSG_MAP(CSaverApp)
  20.         // NOTE - the ClassWizard will add and remove mapping macros here.
  21.         //    DO NOT EDIT what you see in these blocks of generated code!
  22.     //}}AFX_MSG
  23.     ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  24. END_MESSAGE_MAP()
  25.  
  26. TCHAR szConfig[]=_T("Config");
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CSaverApp construction
  30.  
  31. CSaverApp::CSaverApp()
  32. {
  33.     // TODO: add construction code here,
  34.     // Place all significant initialization in InitInstance
  35. }
  36.  
  37. /////////////////////////////////////////////////////////////////////////////
  38. // The one and only CSaverApp object
  39.  
  40. CSaverApp theApp;
  41.  
  42. BOOL MatchOption(LPTSTR lpsz, LPTSTR lpszOption)
  43. {
  44.     if (lpsz[0] == '-' || lpsz[0] == '/')
  45.         lpsz++;
  46.     if (lstrcmpi(lpsz, lpszOption) == 0)
  47.         return TRUE;
  48.     return FALSE;
  49. }
  50.  
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CSaverApp initialization
  53.  
  54. BOOL CSaverApp::InitInstance()
  55. {
  56.     // Standard initialization
  57.     // If you are not using these features and wish to reduce the size
  58.     //  of your final executable, you should remove from the following
  59.     //  the specific initialization routines you do not need.
  60.  
  61.     Enable3dControls();
  62.     SetRegistryKey(_T("MFC Screen Savers Inc."));
  63.  
  64.     if (__argc == 1 || MatchOption(__argv[1], _T("c")))
  65.         DoConfig();
  66.     else if (MatchOption(__argv[1], _T("p")))
  67.     {
  68.         CWnd* pParent = CWnd::FromHandle((HWND)atol(__argv[2]));
  69.         ASSERT(pParent != NULL);
  70.         CDrawWnd* pWnd = new CDrawWnd();
  71.         CRect rect;
  72.         pParent->GetClientRect(&rect);
  73.         pWnd->Create(NULL, WS_VISIBLE|WS_CHILD, rect, pParent, NULL);
  74.         m_pMainWnd = pWnd;
  75.         return TRUE;
  76.     }
  77.     else if (MatchOption(__argv[1], _T("s")))
  78.     {
  79.         CSaverWnd* pWnd = new CSaverWnd;
  80.         pWnd->Create();
  81.         m_pMainWnd = pWnd;
  82.         return TRUE;
  83.     }
  84.     return FALSE;
  85. }
  86.  
  87. void CSaverApp::DoConfig()
  88. {
  89.     CSaverDlg dlg;
  90.     dlg.m_nWidth = GetProfileInt(szConfig, _T("Width"), 10);
  91.     int nStyle = GetProfileInt(szConfig, _T("Style"), 0);
  92.     dlg.m_nCapStyle = 0;
  93.     if ((nStyle & PS_ENDCAP_MASK) == PS_ENDCAP_SQUARE)
  94.         dlg.m_nCapStyle = 1;
  95.     else if ((nStyle & PS_ENDCAP_MASK) == PS_ENDCAP_FLAT)
  96.         dlg.m_nCapStyle = 2;
  97.     dlg.m_nJoinStyle = 0;
  98.     if ((nStyle & PS_JOIN_MASK) == PS_JOIN_BEVEL)
  99.         dlg.m_nJoinStyle = 1;
  100.     else if ((nStyle & PS_JOIN_MASK) == PS_JOIN_MITER)
  101.         dlg.m_nJoinStyle = 2;
  102.  
  103.     dlg.m_nResolution = GetProfileInt(szConfig, _T("Resolution"), 10);
  104.     dlg.m_nSpeed = GetProfileInt(szConfig, _T("Speed"), 100);
  105.     dlg.m_color = RGB(GetProfileInt(szConfig, _T("ColorRed"), 255),
  106.         GetProfileInt(szConfig, _T("ColorGreen"), 0),
  107.         GetProfileInt(szConfig, _T("ColorBlue"), 0));
  108.     m_pMainWnd = &dlg;
  109.     if (dlg.DoModal() == IDOK)
  110.     {
  111.         WriteProfileInt(szConfig, _T("ColorRed"), GetRValue(dlg.m_color));
  112.         WriteProfileInt(szConfig, _T("ColorGreen"), GetGValue(dlg.m_color));
  113.         WriteProfileInt(szConfig, _T("ColorBlue"), GetBValue(dlg.m_color));
  114.         WriteProfileInt(szConfig, _T("Width"), dlg.m_nWidth);
  115.         int nStyle = 0;
  116.         if (dlg.m_nCapStyle == 0)
  117.             nStyle = PS_ENDCAP_ROUND;
  118.         else if (dlg.m_nCapStyle == 1)
  119.             nStyle = PS_ENDCAP_SQUARE;
  120.         else if (dlg.m_nCapStyle == 2)
  121.             nStyle = PS_ENDCAP_FLAT;
  122.         if (dlg.m_nJoinStyle == 0)
  123.             nStyle |= PS_JOIN_ROUND;
  124.         else if (dlg.m_nJoinStyle == 1)
  125.             nStyle |= PS_JOIN_BEVEL;
  126.         else if (dlg.m_nJoinStyle == 2)
  127.             nStyle |= PS_JOIN_MITER;
  128.         WriteProfileInt(szConfig, _T("Style"), nStyle);
  129.         WriteProfileInt(szConfig, _T("Resolution"), dlg.m_nResolution);
  130.         WriteProfileInt(szConfig, _T("Speed"), dlg.m_nSpeed);
  131.     }
  132. }
  133.