home *** CD-ROM | disk | FTP | other *** search
/ Learn 3D Graphics Programming on the PC / Learn_3D_Graphics_Programming_on_the_PC_Ferraro.iso / rwwin / rwmfc.cp_ / rwmfc.bin
Text File  |  1995-11-14  |  8KB  |  301 lines

  1. // rwmfc.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "rwmfc.h"
  6.  
  7. #include "mainfrm.h"
  8. #include "rwmfcdoc.h"
  9. #include "rwmfcvw.h"
  10.  
  11. #include <rwlib.h>
  12. #include <rwwin31.h>
  13.  
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char BASED_CODE THIS_FILE[] = __FILE__;
  17. #endif
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CRwApp
  21.  
  22. BEGIN_MESSAGE_MAP(CRwApp, CWinApp)
  23.     //{{AFX_MSG_MAP(CRwApp)
  24.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  25.     ON_UPDATE_COMMAND_UI(ID_DEBUGGING_APIS, OnUpdateDebuggingApis)
  26.     ON_UPDATE_COMMAND_UI(ID_DEBUGGING_ASSERTIONS, OnUpdateDebuggingAssertions)
  27.     ON_UPDATE_COMMAND_UI(ID_DEBUGGING_MESSAGES, OnUpdateDebuggingMessages)
  28.     ON_UPDATE_COMMAND_UI(ID_DEBUGGING_SCRIPTS, OnUpdateDebuggingScripts)
  29.     ON_COMMAND(ID_DEBUGGING_APIS, OnDebuggingApis)
  30.     ON_COMMAND(ID_DEBUGGING_ASSERTIONS, OnDebuggingAssertions)
  31.     ON_COMMAND(ID_DEBUGGING_MESSAGES, OnDebuggingMessages)
  32.     ON_COMMAND(ID_DEBUGGING_SCRIPTS, OnDebuggingScripts)
  33.     //}}AFX_MSG_MAP
  34.     // Standard file based document commands
  35.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  36.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  37.     // Standard print setup command
  38.     ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  39. END_MESSAGE_MAP()
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CRwApp construction
  43.  
  44. CRwApp::CRwApp()
  45. {
  46.     // TODO: add construction code here,
  47.     // Place all significant initialization in InitInstance
  48. }
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // The one and only CRwApp object
  52.  
  53. CRwApp NEAR theApp;
  54.  
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CRwApp initialization
  57.  
  58. BOOL CRwApp::InitInstance()
  59. {
  60.     // Open RenderWare first as there is little point doint anything else if
  61.     // RenderWare is not available.
  62.     if (!::RwOpen("MSWindows", NULL))
  63.     {
  64.         // Should really do some error handling here to discover why, but for
  65.         // now we will just flag the error and quit.
  66.         AfxMessageBox("RenderWare could not be opened", MB_OK | MB_APPLMODAL | MB_ICONSTOP);
  67.         return FALSE;
  68.     }
  69.     
  70.     // Standard initialization
  71.     // If you are not using these features and wish to reduce the size
  72.     //  of your final executable, you should remove from the following
  73.     //  the specific initialization routines you do not need.
  74.  
  75.     SetDialogBkColor();        // Set dialog background color to gray
  76.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  77.  
  78.     // Register the application's document templates.  Document templates
  79.     //  serve as the connection between documents, frame windows and views.
  80.  
  81.     CMultiDocTemplate* pDocTemplate;
  82.     pDocTemplate = new CMultiDocTemplate(
  83.         IDR_RWXTYPE,
  84.         RUNTIME_CLASS(CRwDoc),
  85.         RUNTIME_CLASS(CMDIChildWnd),        // standard MDI child frame
  86.         RUNTIME_CLASS(CRwView));
  87.     AddDocTemplate(pDocTemplate);
  88.  
  89.     // create main MDI Frame window
  90.     CMainFrame* pMainFrame = new CMainFrame;
  91.     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  92.         return FALSE;
  93.     m_pMainWnd = pMainFrame;
  94.  
  95.     // enable file manager drag/drop and DDE Execute open
  96.     EnableShellOpen();
  97.     RegisterShellFileTypes();
  98.  
  99.     // simple command line parsing
  100.     if (m_lpCmdLine[0] == '\0')
  101.     {
  102.         // create a new (empty) document
  103.         OnFileNew();
  104.     }
  105.     else
  106.     {
  107.         // open an existing document
  108.         OpenDocumentFile(m_lpCmdLine);
  109.     }
  110.  
  111.     m_pMainWnd->DragAcceptFiles();
  112.     // The main window has been initialized, so show and update it.
  113.     pMainFrame->ShowWindow(m_nCmdShow);
  114.     pMainFrame->UpdateWindow();
  115.  
  116.     return TRUE;
  117. }
  118.  
  119. int CRwApp::ExitInstance()
  120. {
  121.     // Close RenderWare down.
  122.     ::RwClose();
  123.     
  124.     return 0;
  125. }
  126.  
  127. /////////////////////////////////////////////////////////////////////////////
  128. // CAboutDlg dialog used for App About
  129.  
  130. class CAboutDlg : public CDialog
  131. {
  132. public:
  133.     CAboutDlg();
  134.  
  135. // Dialog Data
  136.     //{{AFX_DATA(CAboutDlg)
  137.     enum { IDD = IDD_ABOUTBOX };
  138.     //}}AFX_DATA
  139.  
  140. // Implementation
  141. protected:
  142.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  143.     //{{AFX_MSG(CAboutDlg)
  144.     virtual BOOL OnInitDialog();
  145.     //}}AFX_MSG
  146.     DECLARE_MESSAGE_MAP()
  147. };
  148.  
  149. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  150. {
  151.     //{{AFX_DATA_INIT(CAboutDlg)
  152.     //}}AFX_DATA_INIT
  153. }
  154.  
  155. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  156. {
  157.     CDialog::DoDataExchange(pDX);
  158.     //{{AFX_DATA_MAP(CAboutDlg)
  159.     //}}AFX_DATA_MAP
  160. }
  161.  
  162. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  163.     //{{AFX_MSG_MAP(CAboutDlg)
  164.     //}}AFX_MSG_MAP
  165. END_MESSAGE_MAP()
  166.  
  167. // App command to run the dialog
  168. void CRwApp::OnAppAbout()
  169. {
  170.     CAboutDlg aboutDlg;
  171.     aboutDlg.DoModal();
  172. }
  173.  
  174. /////////////////////////////////////////////////////////////////////////////
  175. // CRwApp commands
  176.  
  177. BOOL CAboutDlg::OnInitDialog()
  178. {
  179.     CDialog::OnInitDialog();
  180.     
  181.     
  182.     
  183.     return TRUE;
  184. }
  185.  
  186. void CRwApp::OnUpdateDebuggingApis(CCmdUI* pCmdUI)
  187. {
  188.     RwBool isDebugging;
  189.     
  190.     ::RwGetSystemInfo(rwDEBUGGINGLIB, &isDebugging, sizeof(isDebugging));
  191.     if (isDebugging)
  192.     {
  193.         pCmdUI->Enable();
  194.         if (::RwGetDebugTraceState() == rwENABLE)
  195.             pCmdUI->SetCheck(1);
  196.         else
  197.             pCmdUI->SetCheck(0);
  198.     }
  199.     else
  200.     {
  201.         pCmdUI->Enable(FALSE);
  202.         pCmdUI->SetCheck(0);
  203.     }
  204. }
  205.  
  206. void CRwApp::OnUpdateDebuggingAssertions(CCmdUI* pCmdUI)
  207. {
  208.     RwBool isDebugging;
  209.     
  210.     ::RwGetSystemInfo(rwDEBUGGINGLIB, &isDebugging, sizeof(isDebugging));
  211.     if (isDebugging)
  212.     {
  213.         pCmdUI->Enable();
  214.         if (::RwGetDebugAssertionState() == rwENABLE)
  215.             pCmdUI->SetCheck(1);
  216.         else
  217.             pCmdUI->SetCheck(0);
  218.     }
  219.     else
  220.     {
  221.         pCmdUI->Enable(FALSE);
  222.         pCmdUI->SetCheck(0);
  223.     }
  224. }
  225.  
  226. void CRwApp::OnUpdateDebuggingMessages(CCmdUI* pCmdUI)
  227. {
  228.     RwBool isDebugging;
  229.     
  230.     ::RwGetSystemInfo(rwDEBUGGINGLIB, &isDebugging, sizeof(isDebugging));
  231.     if (isDebugging)
  232.     {
  233.         pCmdUI->Enable();
  234.         if (::RwGetDebugMessageState() == rwENABLE)
  235.             pCmdUI->SetCheck(1);
  236.         else
  237.             pCmdUI->SetCheck(0);
  238.     }
  239.     else
  240.     {
  241.         pCmdUI->Enable(FALSE);
  242.         pCmdUI->SetCheck(0);
  243.     }
  244. }
  245.  
  246. void CRwApp::OnUpdateDebuggingScripts(CCmdUI* pCmdUI)
  247. {
  248.     RwBool isDebugging;
  249.     
  250.     ::RwGetSystemInfo(rwDEBUGGINGLIB, &isDebugging, sizeof(isDebugging));
  251.     if (isDebugging)
  252.     {
  253.         pCmdUI->Enable();
  254.         if (::RwGetDebugScriptState() == rwENABLE)
  255.             pCmdUI->SetCheck(1);
  256.         else
  257.             pCmdUI->SetCheck(0);
  258.     }
  259.     else
  260.     {
  261.         pCmdUI->Enable(FALSE);
  262.         pCmdUI->SetCheck(0);
  263.     }
  264. }
  265.  
  266. void CRwApp::OnDebuggingApis()
  267. {
  268.     // Toggle API level function tracing.
  269.     if (::RwGetDebugTraceState() == rwENABLE)
  270.         ::RwSetDebugTraceState(rwDISABLE);
  271.     else
  272.         ::RwSetDebugTraceState(rwENABLE);
  273. }
  274.  
  275. void CRwApp::OnDebuggingAssertions()
  276. {
  277.     // Toggle assertion failure messages.
  278.     if (::RwGetDebugAssertionState() == rwENABLE)
  279.         ::RwSetDebugAssertionState(rwDISABLE);
  280.     else
  281.         ::RwSetDebugAssertionState(rwENABLE);
  282. }
  283.  
  284. void CRwApp::OnDebuggingMessages()
  285. {
  286.     // Toggle informational messages.
  287.     if (::RwGetDebugMessageState() == rwENABLE)
  288.         ::RwSetDebugMessageState(rwDISABLE);
  289.     else
  290.         ::RwSetDebugMessageState(rwENABLE);
  291. }
  292.  
  293. void CRwApp::OnDebuggingScripts()
  294. {
  295.     // Toggle script trace messages.
  296.     if (::RwGetDebugScriptState() == rwENABLE)
  297.         ::RwSetDebugScriptState(rwDISABLE);
  298.     else
  299.         ::RwSetDebugScriptState(rwENABLE);
  300. }
  301.