Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Magic.cpp
Go to the documentation of this file.
1 /* Project Magic 2.0
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: Magic.exe
6  FILE: Magic.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Implementation of the main application class
13 */
14 
15 #include "stdafx.h"
16 #include "Magic.h"
17 
18 #include "MainFrm.h"
19 #include "MagicDoc.h"
20 #include "MagicView.h"
21 
22 #include "MachineInfo.h"
23 
24 #ifdef _DEBUG
25 #define new DEBUG_NEW
26 #undef THIS_FILE
27 static char THIS_FILE[] = __FILE__;
28 #endif
29 
30 // +--------------------------------------------------------------------+
31 
32 BEGIN_MESSAGE_MAP(Magic, CWinApp)
33  //{{AFX_MSG_MAP(Magic)
34  ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
35  // NOTE - the ClassWizard will add and remove mapping macros here.
36  // DO NOT EDIT what you see in these blocks of generated code!
37  //}}AFX_MSG_MAP
38  // Standard file based document commands
39  ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
40  ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
41  // Standard print setup command
42  ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
43 END_MESSAGE_MAP()
44 
45 // +--------------------------------------------------------------------+
46 
47 extern FILE* ErrLog;
48 extern int VD3D_describe_things;
49 void Print(const char* msg, ...);
50 
51 static void PrintLogHeader()
52 {
53  ErrLog = fopen("errlog.txt", "w");
54  Print("+====================================================================+\n");
55  Print("| Magic 2.0 |\n");
56 
57  VD3D_describe_things = 4;
59 }
60 
61 // +--------------------------------------------------------------------+
62 
64 {
65  PrintLogHeader();
66 }
67 
69 {
70  Print("+====================================================================+\n");
71  Print(" END OF LINE.\n");
72 
73  fclose(ErrLog);
74 }
75 
76 // +--------------------------------------------------------------------+
77 //
78 // The one and only Magic object
79 
81 
82 // +--------------------------------------------------------------------+
83 //
84 // Magic initialization
85 
87 {
88  AfxEnableControlContainer();
89 
90  // Standard initialization
91  // If you are not using these features and wish to reduce the size
92  // of your final executable, you should remove from the following
93  // the specific initialization routines you do not need.
94 
95 //#ifdef _AFXDLL
96 // Enable3dControls(); // Call this when using MFC in a shared DLL
97 //#else
98 // Enable3dControlsStatic(); // Call this when linking to MFC statically
99 //#endif
100 
101  // Change the registry key under which our settings are stored.
102  // TODO: You should modify this string to be something appropriate
103  // such as the name of your company or organization.
104  SetRegistryKey(_T("Local AppWizard-Generated Applications"));
105 
106  LoadStdProfileSettings(); // Load standard INI file options (including MRU)
107 
108  // Register the application's document templates. Document templates
109  // serve as the connection between documents, frame windows and views.
110 
111  CSingleDocTemplate* pDocTemplate;
112  pDocTemplate = new CSingleDocTemplate(
114  RUNTIME_CLASS(MagicDoc),
115  RUNTIME_CLASS(MainFrame), // main SDI frame window
116  RUNTIME_CLASS(MagicView));
117  AddDocTemplate(pDocTemplate);
118 
119  // Parse command line for standard shell commands, DDE, file open
120  CCommandLineInfo cmdInfo;
121  ParseCommandLine(cmdInfo);
122 
123  // Dispatch commands specified on the command line
124  if (!ProcessShellCommand(cmdInfo))
125  return FALSE;
126 
127  // The one and only window has been initialized, so show and update it.
128  m_pMainWnd->ShowWindow(SW_SHOW);
129  m_pMainWnd->UpdateWindow();
130 
131  return TRUE;
132 }
133 
134 
135 // +--------------------------------------------------------------------+
136 //
137 // CAboutDlg dialog used for App About
138 
139 class CAboutDlg : public CDialog
140 {
141 public:
142  CAboutDlg();
143 
144 // Dialog Data
145  //{{AFX_DATA(CAboutDlg)
146  enum { IDD = IDD_ABOUTBOX };
147  //}}AFX_DATA
148 
149  // ClassWizard generated virtual function overrides
150  //{{AFX_VIRTUAL(CAboutDlg)
151  protected:
152  virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
153  //}}AFX_VIRTUAL
154 
155 // Implementation
156 protected:
157  //{{AFX_MSG(CAboutDlg)
158  // No message handlers
159  //}}AFX_MSG
160  DECLARE_MESSAGE_MAP()
161 };
162 
164 {
165  //{{AFX_DATA_INIT(CAboutDlg)
166  //}}AFX_DATA_INIT
167 }
168 
169 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
170 {
172  //{{AFX_DATA_MAP(CAboutDlg)
173  //}}AFX_DATA_MAP
174 }
175 
176 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
177  //{{AFX_MSG_MAP(CAboutDlg)
178  // No message handlers
179  //}}AFX_MSG_MAP
180 END_MESSAGE_MAP()
181 
182 // App command to run the dialog
183 void Magic::OnAppAbout()
184 {
185  CAboutDlg aboutDlg;
186  aboutDlg.DoModal();
187 }
188 
189 // +--------------------------------------------------------------------+
190 //
191 // Magic message handlers
192 
193 BOOL Magic::OnIdle(LONG lCount)
194 {
195  CWinApp::OnIdle(lCount);
196 
197  if (!app_active)
198  Sleep(50);
199 
200  m_pMainWnd->SendMessage(WM_COMMAND, ID_VIEW_RENDER);
201  return TRUE; // always request more time
202 }