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