tiny_app.cpp

Go to the documentation of this file.
00001 #ifndef TINY_APP_IMPLEMENTATION_FILE
00002 #define TINY_APP_IMPLEMENTATION_FILE
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : tiny_application                                                  *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 1995-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #ifdef __WIN32__
00019 
00020 #include "tiny_app.h"
00021 #include "tiny_shell.h"
00022 
00023 template <class instantiation_window_type>
00024 tiny_application<instantiation_window_type>::tiny_application()
00025 : CWinApp(),
00026   _new_main(NIL),
00027   _local_result(0)
00028 {}
00029 
00030 template <class instantiation_window_type>
00031 tiny_application<instantiation_window_type>::~tiny_application()
00032 {}
00033 
00034 template <class instantiation_window_type>
00035 BOOL tiny_application<instantiation_window_type>::InitInstance()
00036 {
00037   SET_INSTANCE_HANDLE(m_hInstance);
00038     // store the instance in our static handle variable.
00039 
00040 #if COMPILER_VERSION==6
00041  #ifdef _AFXDLL
00042   Enable3dControls();  // Call this when using MFC in a shared DLL.
00043  #else
00044   Enable3dControlsStatic();  // Call this when linking to MFC statically.
00045  #endif
00046 #endif
00047 
00048   _new_main = new instantiation_window_type;
00049   if (!_new_main) return false;
00050 
00051   tiny_shell *casted_main = dynamic_cast<tiny_shell *>(_new_main);
00052   if (casted_main) {
00053     // we can rely on this as being a tiny_shell based window.
00054     if (!casted_main->good_version()) return false;
00055 
00056     ASSERT_VALID(casted_main);  // check window health.
00057 
00058     // invoke the tiny_shell creator.
00059     if (!casted_main->Create()) return false;
00060 
00061     // assign the main window pointer to our new window.
00062     m_pMainWnd = casted_main;
00063 
00064     // The main window has been initialized, so show and update it.
00065     casted_main->ShowWindow(m_nCmdShow);
00066     casted_main->UpdateWindow();
00067   } else {
00068     SET_DEFAULT_FILE_LOGGER;
00069     _local_result = _new_main->execute();
00070   }
00071 
00072   return true;
00073 }
00074 
00075 template <class instantiation_window_type>
00076 int tiny_application<instantiation_window_type>::ExitInstance()
00077 {
00078   int initial_ret = CWinApp::ExitInstance(); 
00079   if (initial_ret != 0) return initial_ret;
00080   tiny_shell *casted_main = dynamic_cast<tiny_shell *>(_new_main);
00081   if (casted_main) return casted_main->execute_returned();
00082   else return _local_result;
00083 }
00084 
00085 #endif
00086 
00087 
00088 #endif //TINY_APP_IMPLEMENTATION_FILE
00089 

Generated on Fri Nov 28 04:28:59 2008 for HOOPLE Libraries by  doxygen 1.5.1