home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / Epoc / Palmtime / files / FrotzCE2_src.ZIP / FrotzCE / FrotzCE.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-15  |  4.5 KB  |  162 lines

  1. // FrotzCE.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "FrotzCE.h"
  6.  
  7. #include "MainFrm.h"
  8. #include "FrotzCEDoc.h"
  9. #include "FrotzCEView.h"
  10. #include "ZThread.h"
  11. #include "About.h"
  12.  
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CFrotzCEApp
  21.  
  22. BEGIN_MESSAGE_MAP(CFrotzCEApp, CWinApp)
  23.     //{{AFX_MSG_MAP(CFrotzCEApp)
  24.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  25.         // NOTE - the ClassWizard will add and remove mapping macros here.
  26.         //    DO NOT EDIT what you see in these blocks of generated code!
  27.     //}}AFX_MSG_MAP
  28.     // Standard file based document commands
  29.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  30.     ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
  31. END_MESSAGE_MAP()
  32.  
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CFrotzCEApp construction
  35.  
  36. CFrotzCEApp::CFrotzCEApp(LPCTSTR lpszAppName, LPCTSTR lpszHelpName)
  37.     : CWinApp(lpszAppName, lpszHelpName)
  38. {
  39.     m_bZmachineRunning = FALSE;
  40.  
  41.     m_nFontHeight = 0;
  42.     m_nFontWidth = 0;
  43.  
  44.     m_nDefaultStyle = NORMAL_STYLE;
  45.  
  46.     m_bUseStyles = FALSE;
  47.  
  48.     m_bUseColours = TRUE;
  49.  
  50.     m_bUseEuroChars = TRUE;
  51.  
  52.     m_bTandy = FALSE;
  53.  
  54.     m_bInitialised = FALSE;
  55. }
  56.  
  57. /////////////////////////////////////////////////////////////////////////////
  58. // The one and only CFrotzCEApp object
  59.  
  60. // WCE MFC apps require the application name to be specified in the CWinApp 
  61. // constructor. A help contents filename may also be specified.
  62.  
  63. CFrotzCEApp theApp(_T("FrotzCE"), _T("FrotzCE.htc"));
  64.  
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CFrotzCEApp initialization
  67.  
  68. BOOL CFrotzCEApp::InitInstance()
  69. {
  70.     // Standard initialization
  71.     SetRegistryKey(_T("Frotz"));
  72.  
  73.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  74.  
  75.     // Get defaults from registry
  76.     m_strDefaultDir = 
  77.         GetProfileString( TEXT( "Defaults" ), TEXT( "CurrentDir" ), TEXT( "\\" ) );
  78.     m_nFontHeight =
  79.         GetProfileInt( TEXT( "Defaults" ), TEXT( "FontHeight" ), 0 );
  80.     m_nFontWidth =         
  81.         GetProfileInt( TEXT( "Defaults" ), TEXT( "FontWidth" ), 0 );
  82.     m_nDefaultStyle = 
  83.         GetProfileInt( TEXT( "Defaults" ), TEXT( "Style" ), NORMAL_STYLE );
  84.     m_bUseStyles = 
  85.         GetProfileInt( TEXT( "Defaults" ), TEXT( "UseStyles" ), FALSE );
  86.     m_bUseColours = 
  87.         GetProfileInt( TEXT( "Defaults" ), TEXT( "UseCols" ), TRUE );
  88.  
  89.     // Register the application's document templates.  Document templates
  90.     //  serve as the connection between documents, frame windows and views.
  91.     CSingleDocTemplate* pDocTemplate;
  92.     pDocTemplate = new CSingleDocTemplate(
  93.         IDR_MAINFRAME,
  94.         RUNTIME_CLASS(CFrotzCEDoc),
  95.         RUNTIME_CLASS(CMainFrame),       // main SDI frame window
  96.         RUNTIME_CLASS(CFrotzCEView));
  97.     AddDocTemplate(pDocTemplate);
  98.  
  99.     // Parse command line for standard shell commands, DDE, file open
  100.     CCommandLineInfo cmdInfo;
  101.     ParseCommandLine(cmdInfo);
  102.  
  103.     // Dispatch commands specified on the command line
  104.     if (!ProcessShellCommand(cmdInfo))
  105.         return FALSE;
  106.  
  107.     // The one and only window has been initialized, so show and update it.
  108.     m_pMainWnd->SetIcon( LoadIcon( IDI_APPICON ), FALSE );
  109.     m_pMainWnd->ShowWindow(SW_SHOW);
  110.     m_pMainWnd->UpdateWindow();
  111.  
  112.     return TRUE;
  113. }
  114.  
  115. int CFrotzCEApp::ExitInstance() 
  116. {
  117.     // Write defaults to registry
  118.     WriteProfileString( TEXT( "Defaults" ), TEXT( "CurrentDir" ), m_strDefaultDir );
  119.     WriteProfileInt( TEXT( "Defaults" ), TEXT( "FontHeight" ), m_nFontHeight );
  120.     WriteProfileInt( TEXT( "Defaults" ), TEXT( "FontWidth" ), m_nFontWidth );
  121.     WriteProfileInt( TEXT( "Defaults" ), TEXT( "Style" ), m_nDefaultStyle );
  122.     WriteProfileInt( TEXT( "Defaults" ), TEXT( "UseStyles" ), m_bUseStyles );
  123.     WriteProfileInt( TEXT( "Defaults" ), TEXT( "UseCols" ), m_bUseColours );
  124.  
  125.     return CWinApp::ExitInstance();
  126. }
  127.  
  128. void CFrotzCEApp::StartZMachine( LPVOID pParam )
  129. {
  130.     // Start ZMachine thread
  131.     m_pcZThread = AfxBeginThread( ZMachineThreadFunction, pParam );
  132. }
  133.  
  134. void CFrotzCEApp::OnFileOpen()
  135. {
  136.     // Z machine not running?
  137.     if (!m_bZmachineRunning)
  138.     {
  139.     CFileDialog dlgFile( TRUE );
  140.  
  141.         // Set initial directory
  142.         dlgFile.m_ofn.lpstrInitialDir = 
  143.             m_strDefaultDir.GetBuffer( m_strDefaultDir.GetLength() + 1 );
  144.  
  145.         // Process file dialog
  146.         if (dlgFile.DoModal() == IDOK)
  147.         {
  148.             m_strDefaultDir.ReleaseBuffer();
  149.             OpenDocumentFile( dlgFile.GetPathName() );
  150.         }
  151.         else m_strDefaultDir.ReleaseBuffer();
  152.     }
  153. }
  154.  
  155. // App command to run the dialog
  156. void CFrotzCEApp::OnAppAbout()
  157. {
  158.     CAboutDlg aboutDlg;
  159.     aboutDlg.DoModal();
  160. }
  161.  
  162.