EditorMFC.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. // EditorMFC.cpp : Defines the class behaviors for the application.
  5. //
  6. #include "stdafx.h"
  7. #include "EditorMFC.h"
  8. #include "MainFrm.h"
  9. #include "MFCPlatform.hpp"
  10. /////////////////////////////////////////////////////////////////////////////
  11. // EditorMFCApp
  12. BEGIN_MESSAGE_MAP(EditorMFCApp, CWinApp)
  13. //{{AFX_MSG_MAP(EditorMFCApp)
  14. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  15. //}}AFX_MSG_MAP
  16. END_MESSAGE_MAP()
  17. /////////////////////////////////////////////////////////////////////////////
  18. // EditorMFCApp construction
  19. EditorMFCApp::EditorMFCApp()
  20. {
  21. }
  22. /////////////////////////////////////////////////////////////////////////////
  23. // The one and only EditorMFCApp object
  24. EditorMFCApp theApp;
  25. /////////////////////////////////////////////////////////////////////////////
  26. // EditorMFCApp initialization
  27. BOOL EditorMFCApp::InitInstance()
  28. {
  29. // Standard initialization
  30. #ifdef _AFXDLL
  31. Enable3dControls(); // Call this when using MFC in a shared DLL
  32. #else
  33. Enable3dControlsStatic(); // Call this when linking to MFC statically
  34. #endif
  35. // Change the registry key under which our settings are stored.
  36. SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  37. MainFrame* pFrame = new MainFrame;
  38. m_pMainWnd = pFrame;
  39. // create and load the frame with its resources
  40. pFrame->LoadFrame(IDR_EDITOR_MENU/*, WS_OVERLAPPED |WS_CAPTION | WS_SYSMENU | FWS_ADDTOTITLE*/ );
  41. HICON editorIco = LoadIcon(IDI_ICON1);
  42. pFrame->SetIcon(editorIco,true);
  43. pFrame->ShowWindow(SW_SHOW);
  44. pFrame->UpdateWindow();
  45. InitGameOS( m_hInstance, EditorInterface::instance()->m_hWnd, m_lpCmdLine );
  46. pFrame->SetFocus();
  47. return TRUE;
  48. }
  49. /////////////////////////////////////////////////////////////////////////////
  50. // EditorMFCApp message handlers
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CAboutDlg dialog used for App About
  53. class CAboutDlg : public CDialog
  54. {
  55. public:
  56. CAboutDlg();
  57. // Dialog Data
  58. //{{AFX_DATA(CAboutDlg)
  59. enum { IDD = IDD_FOG };
  60. //}}AFX_DATA
  61. // ClassWizard generated virtual function overrides
  62. //{{AFX_VIRTUAL(CAboutDlg)
  63. protected:
  64. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  65. //}}AFX_VIRTUAL
  66. // Implementation
  67. protected:
  68. //{{AFX_MSG(CAboutDlg)
  69. // No message handlers
  70. //}}AFX_MSG
  71. DECLARE_MESSAGE_MAP()
  72. };
  73. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  74. {
  75. //{{AFX_DATA_INIT(CAboutDlg)
  76. //}}AFX_DATA_INIT
  77. }
  78. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  79. {
  80. CDialog::DoDataExchange(pDX);
  81. //{{AFX_DATA_MAP(CAboutDlg)
  82. //}}AFX_DATA_MAP
  83. }
  84. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  85. //{{AFX_MSG_MAP(CAboutDlg)
  86. // No message handlers
  87. //}}AFX_MSG_MAP
  88. END_MESSAGE_MAP()
  89. // App command to run the dialog
  90. void EditorMFCApp::OnAppAbout()
  91. {
  92. CAboutDlg aboutDlg;
  93. aboutDlg.DoModal();
  94. }
  95. /////////////////////////////////////////////////////////////////////////////
  96. // EditorMFCApp message handlers
  97. BOOL EditorMFCApp::OnIdle(LONG lCount)
  98. {
  99. const CWnd *pW1 = this->GetMainWnd();
  100. const CWnd *pW2 = EditorInterface::instance();
  101. const CWnd *pW3 = CWnd::GetForegroundWindow();
  102. const CWnd *pW4 = CWnd::GetActiveWindow();
  103. const CWnd *pW5 = CWnd::GetFocus();
  104. if (pW1 == pW3)
  105. {
  106. EditorInterface::instance()->InvalidateRect(NULL, FALSE);
  107. }
  108. Sleep(2/*milliseconds*/); /* limits the framerate to 500fps */
  109. CWinApp::OnIdle(lCount);
  110. return 1;
  111. }
  112. int EditorMFCApp::ExitInstance()
  113. {
  114. {
  115. Environment.TerminateGameEngine();
  116. gos_PushCurrentHeap(0); // TerminateGameEngine() forgets to do this
  117. }
  118. if (false) {
  119. ExitGameOS();
  120. if (!EditorInterface::instance()->m_hWnd)
  121. {
  122. /* ExitGameOS() shuts down directX which has the side effect of killing the
  123. EditorInterface window, so we recreate the window here. The editor window
  124. may not be referenced after this function is executed, but this is not the correct
  125. place for the EditorInterface window to be destroyed. */
  126. EditorInterface::instance()->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW | WS_VSCROLL | WS_HSCROLL,
  127. CRect(0, 0, 0, 0), m_pMainWnd, AFX_IDW_PANE_FIRST, NULL);
  128. }
  129. }
  130. delete m_pMainWnd;
  131. m_pMainWnd = 0;
  132. return CWinApp::ExitInstance();
  133. }