- // SingleScreen.cpp : Defines the class behaviors for the application.
- //
- #include "stdafx.h"
- #include "SingleScreen.h"
- #include "SingleScreenDlg.h"
- #include "SaverWindow.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CSingleScreenApp
- BEGIN_MESSAGE_MAP(CSingleScreenApp, CWinApp)
- //{{AFX_MSG_MAP(CSingleScreenApp)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG
- ON_COMMAND(ID_HELP, CWinApp::OnHelp)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CSingleScreenApp construction
- CSingleScreenApp::CSingleScreenApp()
- {
- // TODO: add construction code here,
- // Place all significant initialization in InitInstance
- }
- /////////////////////////////////////////////////////////////////////////////
- // The one and only CSingleScreenApp object
- CSingleScreenApp theApp;
- /////////////////////////////////////////////////////////////////////////////
- // CSingleScreenApp initialization
- BOOL CSingleScreenApp::InitInstance()
- {
- // Command line arguments for a screen saver are:
- // /s run as screen saver
- // /c configuration dialog
- // /p <hwnd> Is running in the preview window
- // /a password, not used in demo app
- if (!AfxSocketInit())
- {
- AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
- return FALSE;
- }
- #ifdef _AFXDLL
- Enable3dControls(); // Call this when using MFC in a shared DLL
- #else
- Enable3dControlsStatic(); // Call this when linking to MFC statically
- #endif
- CString csCmdLine = m_lpCmdLine;
- csCmdLine.MakeLower();
- // Get the command line flags
- int nFwdSlash = csCmdLine.FindOneOf( "/-" );
- HWND hwndParent = NULL;
- #ifdef _DEBUG
- TCHAR cFlag = 's';
- #else
- TCHAR cFlag = 'C';
- #endif
- if ( nFwdSlash > -1 && csCmdLine.GetLength() > nFwdSlash+1 )
- cFlag = csCmdLine[nFwdSlash+1];
- if ( cFlag == 'p' && csCmdLine.GetLength() > nFwdSlash + 3 )
- hwndParent = (HWND)atoi( &((LPCTSTR)csCmdLine)[nFwdSlash+2] );
- if ( tolower(cFlag) == 'c' )
- {
- // Run configuration dialog
- CWnd* pParent = (cFlag=='c')?CWnd::GetActiveWindow():NULL;
- CSingleScreenDlg dlg( pParent );
- m_pMainWnd = &dlg;
- int nResponse = dlg.DoModal();
- if (nResponse == IDOK)
- {
- }
- else if (nResponse == IDCANCEL)
- {
- }
- }
- else
- {
- // Run screen saver either desktop or preview
- CSaverWindow* pSaverWindow = new CSaverWindow;
- if ( pSaverWindow->Create(hwndParent) )
- {
- m_pMainWnd = pSaverWindow;
- return TRUE;
- }
- }
- return FALSE;
- }