Alientech 0.01
An extendable game engine
C:/Alientech/AlienPlanets/MainFrm.cpp
Go to the documentation of this file.
00001 
00002 // MainFrm.cpp : implementation of the CMainFrame class
00003 //
00004 
00005 #include "stdafx.h"
00006 #include "AlienPlanets.h"
00007 
00008 #include "MainFrm.h"
00009 
00010 #ifdef _DEBUG
00011 #define new DEBUG_NEW
00012 #endif
00013 
00014 // CMainFrame
00015 
00016 IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWndEx)
00017 
00018 BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWndEx)
00019         ON_WM_CREATE()
00020         ON_COMMAND(ID_WINDOW_MANAGER, &CMainFrame::OnWindowManager)
00021         ON_COMMAND(ID_VIEW_CUSTOMIZE, &CMainFrame::OnViewCustomize)
00022         ON_REGISTERED_MESSAGE(AFX_WM_CREATETOOLBAR, &CMainFrame::OnToolbarCreateNew)
00023         ON_WM_SETTINGCHANGE()
00024 END_MESSAGE_MAP()
00025 
00026 static UINT indicators[] =
00027 {
00028         ID_SEPARATOR,           // status line indicator
00029         ID_INDICATOR_CAPS,
00030         ID_INDICATOR_NUM,
00031         ID_INDICATOR_SCRL,
00032 };
00033 
00034 // CMainFrame construction/destruction
00035 
00036 CMainFrame::CMainFrame()
00037 {
00038         // TODO: add member initialization code here
00039 }
00040 
00041 CMainFrame::~CMainFrame()
00042 {
00043 }
00044 
00045 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
00046 {
00047         if (CMDIFrameWndEx::OnCreate(lpCreateStruct) == -1)
00048                 return -1;
00049 
00050         BOOL bNameValid;
00051 
00052         // set the visual manager used to draw all user interface elements
00053         CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007));
00054 
00055         // set the visual style to be used the by the visual manager
00056         CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_ObsidianBlack);
00057 
00058         CMDITabInfo mdiTabParams;
00059         mdiTabParams.m_style = CMFCTabCtrl::STYLE_3D_ONENOTE; // other styles available...
00060         mdiTabParams.m_bActiveTabCloseButton = TRUE;      // set to FALSE to place close button at right of tab area
00061         mdiTabParams.m_bTabIcons = FALSE;    // set to TRUE to enable document icons on MDI taba
00062         mdiTabParams.m_bAutoColor = TRUE;    // set to FALSE to disable auto-coloring of MDI tabs
00063         mdiTabParams.m_bDocumentMenu = TRUE; // enable the document menu at the right edge of the tab area
00064         EnableMDITabbedGroups(TRUE, mdiTabParams);
00065 
00066         if (!m_wndMenuBar.Create(this))
00067         {
00068                 TRACE0("Failed to create menubar\n");
00069                 return -1;      // fail to create
00070         }
00071 
00072         m_wndMenuBar.SetPaneStyle(m_wndMenuBar.GetPaneStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY);
00073 
00074         // prevent the menu bar from taking the focus on activation
00075         CMFCPopupMenu::SetForceMenuFocus(FALSE);
00076 
00077         if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
00078                 !m_wndToolBar.LoadToolBar(theApp.m_bHiColorIcons ? IDR_MAINFRAME_256 : IDR_MAINFRAME))
00079         {
00080                 TRACE0("Failed to create toolbar\n");
00081                 return -1;      // fail to create
00082         }
00083 
00084         CString strToolBarName;
00085         bNameValid = strToolBarName.LoadString(IDS_TOOLBAR_STANDARD);
00086         ASSERT(bNameValid);
00087         m_wndToolBar.SetWindowText(strToolBarName);
00088 
00089         CString strCustomize;
00090         bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);
00091         ASSERT(bNameValid);
00092         m_wndToolBar.EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);
00093 
00094         if (!m_wndStatusBar.Create(this))
00095         {
00096                 TRACE0("Failed to create status bar\n");
00097                 return -1;      // fail to create
00098         }
00099         m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT));
00100 
00101         // TODO: Delete these five lines if you don't want the toolbar and menubar to be dockable
00102         m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
00103         m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
00104         EnableDocking(CBRS_ALIGN_ANY);
00105         DockPane(&m_wndMenuBar);
00106         DockPane(&m_wndToolBar);
00107 
00108 
00109         // enable Visual Studio 2005 style docking window behavior
00110         CDockingManager::SetDockingMode(DT_SMART);
00111         // enable Visual Studio 2005 style docking window auto-hide behavior
00112         EnableAutoHidePanes(CBRS_ALIGN_ANY);
00113 
00114         // Load menu item image (not placed on any standard toolbars):
00115         CMFCToolBar::AddToolBarForImageCollection(IDR_MENU_IMAGES, theApp.m_bHiColorIcons ? IDB_MENU_IMAGES_24 : 0);
00116 
00117         // create docking windows
00118         if (!CreateDockingWindows())
00119         {
00120                 TRACE0("Failed to create docking windows\n");
00121                 return -1;
00122         }
00123 
00124         m_wndFileView.EnableDocking(CBRS_ALIGN_ANY);
00125         m_wndClassView.EnableDocking(CBRS_ALIGN_ANY);
00126         DockPane(&m_wndFileView);
00127         CDockablePane* pTabbedBar = NULL;
00128         m_wndClassView.AttachToTabWnd(&m_wndFileView, DM_SHOW, TRUE, &pTabbedBar);
00129         m_wndOutput.EnableDocking(CBRS_ALIGN_ANY);
00130         DockPane(&m_wndOutput);
00131         m_wndProperties.EnableDocking(CBRS_ALIGN_ANY);
00132         DockPane(&m_wndProperties);
00133 
00134 
00135         // Enable enhanced windows management dialog
00136         EnableWindowsDialog(ID_WINDOW_MANAGER, ID_WINDOW_MANAGER, TRUE);
00137 
00138         // Enable toolbar and docking window menu replacement
00139         EnablePaneMenu(TRUE, ID_VIEW_CUSTOMIZE, strCustomize, ID_VIEW_TOOLBAR);
00140 
00141         // enable quick (Alt+drag) toolbar customization
00142         CMFCToolBar::EnableQuickCustomization();
00143 
00144         // Switch the order of document name and application name on the window title bar. This
00145         // improves the usability of the taskbar because the document name is visible with the thumbnail.
00146         ModifyStyle(0, FWS_PREFIXTITLE);
00147 
00148         return 0;
00149 }
00150 
00151 BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
00152 {
00153         if( !CMDIFrameWndEx::PreCreateWindow(cs) )
00154                 return FALSE;
00155         // TODO: Modify the Window class or styles here by modifying
00156         //  the CREATESTRUCT cs
00157 
00158         return TRUE;
00159 }
00160 
00161 BOOL CMainFrame::CreateDockingWindows()
00162 {
00163         BOOL bNameValid;
00164 
00165         // Create class view
00166         CString strClassView;
00167         bNameValid = strClassView.LoadString(IDS_CLASS_VIEW);
00168         ASSERT(bNameValid);
00169         if (!m_wndClassView.Create(strClassView, this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_CLASSVIEW, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
00170         {
00171                 TRACE0("Failed to create Class View window\n");
00172                 return FALSE; // failed to create
00173         }
00174 
00175         // Create file view
00176         CString strFileView;
00177         bNameValid = strFileView.LoadString(IDS_FILE_VIEW);
00178         ASSERT(bNameValid);
00179         if (!m_wndFileView.Create(strFileView, this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_FILEVIEW, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT| CBRS_FLOAT_MULTI))
00180         {
00181                 TRACE0("Failed to create File View window\n");
00182                 return FALSE; // failed to create
00183         }
00184 
00185         // Create output window
00186         CString strOutputWnd;
00187         bNameValid = strOutputWnd.LoadString(IDS_OUTPUT_WND);
00188         ASSERT(bNameValid);
00189         if (!m_wndOutput.Create(strOutputWnd, this, CRect(0, 0, 100, 100), TRUE, ID_VIEW_OUTPUTWND, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI))
00190         {
00191                 TRACE0("Failed to create Output window\n");
00192                 return FALSE; // failed to create
00193         }
00194 
00195         // Create properties window
00196         CString strPropertiesWnd;
00197         bNameValid = strPropertiesWnd.LoadString(IDS_PROPERTIES_WND);
00198         ASSERT(bNameValid);
00199         if (!m_wndProperties.Create(strPropertiesWnd, this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_PROPERTIESWND, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_RIGHT | CBRS_FLOAT_MULTI))
00200         {
00201                 TRACE0("Failed to create Properties window\n");
00202                 return FALSE; // failed to create
00203         }
00204 
00205         SetDockingWindowIcons(theApp.m_bHiColorIcons);
00206         return TRUE;
00207 }
00208 
00209 void CMainFrame::SetDockingWindowIcons(BOOL bHiColorIcons)
00210 {
00211         HICON hFileViewIcon = (HICON) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons ? IDI_FILE_VIEW_HC : IDI_FILE_VIEW), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);
00212         m_wndFileView.SetIcon(hFileViewIcon, FALSE);
00213 
00214         HICON hClassViewIcon = (HICON) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons ? IDI_CLASS_VIEW_HC : IDI_CLASS_VIEW), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);
00215         m_wndClassView.SetIcon(hClassViewIcon, FALSE);
00216 
00217         HICON hOutputBarIcon = (HICON) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons ? IDI_OUTPUT_WND_HC : IDI_OUTPUT_WND), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);
00218         m_wndOutput.SetIcon(hOutputBarIcon, FALSE);
00219 
00220         HICON hPropertiesBarIcon = (HICON) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons ? IDI_PROPERTIES_WND_HC : IDI_PROPERTIES_WND), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);
00221         m_wndProperties.SetIcon(hPropertiesBarIcon, FALSE);
00222 
00223         UpdateMDITabbedBarsIcons();
00224 }
00225 
00226 // CMainFrame diagnostics
00227 
00228 #ifdef _DEBUG
00229 void CMainFrame::AssertValid() const
00230 {
00231         CMDIFrameWndEx::AssertValid();
00232 }
00233 
00234 void CMainFrame::Dump(CDumpContext& dc) const
00235 {
00236         CMDIFrameWndEx::Dump(dc);
00237 }
00238 #endif //_DEBUG
00239 
00240 
00241 // CMainFrame message handlers
00242 
00243 void CMainFrame::OnWindowManager()
00244 {
00245         ShowWindowsDialog();
00246 }
00247 
00248 void CMainFrame::OnViewCustomize()
00249 {
00250         CMFCToolBarsCustomizeDialog* pDlgCust = new CMFCToolBarsCustomizeDialog(this, TRUE /* scan menus */);
00251         pDlgCust->Create();
00252 }
00253 
00254 LRESULT CMainFrame::OnToolbarCreateNew(WPARAM wp,LPARAM lp)
00255 {
00256         LRESULT lres = CMDIFrameWndEx::OnToolbarCreateNew(wp,lp);
00257         if (lres == 0)
00258         {
00259                 return 0;
00260         }
00261 
00262         CMFCToolBar* pUserToolbar = (CMFCToolBar*)lres;
00263         ASSERT_VALID(pUserToolbar);
00264 
00265         BOOL bNameValid;
00266         CString strCustomize;
00267         bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);
00268         ASSERT(bNameValid);
00269 
00270         pUserToolbar->EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);
00271         return lres;
00272 }
00273 
00274 void CMainFrame::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)
00275 {
00276         CMDIFrameWndEx::OnSettingChange(uFlags, lpszSection);
00277         m_wndOutput.UpdateFonts();
00278 }