IvfMfcApplication.h

00001 //
00002 // Copyright 1999-2006 by Structural Mechanics, Lund University.
00003 //
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Library General Public
00006 // License as published by the Free Software Foundation; either
00007 // version 2 of the License, or (at your option) any later version.
00008 //
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // Library General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Library General Public
00015 // License along with this library; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00017 // USA.
00018 //
00019 // Please report all bugs and problems to "ivf@byggmek.lth.se".
00020 //
00021 //
00022 // Written by Jonas Lindemann
00023 //
00024 
00025 #ifndef _CIvfMfcApplication_h_
00026 #define _CIvfMfcApplication_h_
00027 
00028 #include <afxwin.h>
00029 
00030 #include <ivfdef/IvfPointer.h>
00031 
00038 class CIvfMfcApplicationBase {
00039 private:
00040         int m_idleProcessing;
00041 public:
00043         virtual BOOL InitInstance()
00044         {
00045                 m_idleProcessing = 0;
00046                 return true;
00047         }
00048 
00050         void disableIdleProcessing()
00051         {
00052                 if (m_idleProcessing>0)
00053                         m_idleProcessing--;
00054         }
00055 
00057         void enableIdleProcessing()
00058         {
00059                 m_idleProcessing++;
00060         }
00061 
00063         bool isIdleProcessing()
00064         {
00065                 return m_idleProcessing>0;
00066         }
00067 };
00068 
00075 template<class T>
00076 class CIvfMfcApplication: public CIvfMfcApplicationBase, public CWinApp {
00077 private:
00078         T* m_mfcWindow;
00079 public:
00085         virtual BOOL InitInstance()
00086         {
00087                 CWinApp::InitInstance();
00088                 m_mfcWindow = new T(0,0,640,480);
00089                 m_mfcWindow->setApplication(this);
00090                 m_pMainWnd = m_mfcWindow;
00091                 m_pMainWnd -> ShowWindow(m_nCmdShow);
00092                 m_pMainWnd -> UpdateWindow();
00093                 return true;
00094         }
00095 
00097         virtual int Run()
00098         {
00099                 MSG             msg;
00100                 BOOL    bRet;
00101                 bool running = true;
00102                 while (running)
00103                 {
00104                         if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
00105                         {
00106                                 if ((bRet = GetMessage(&msg, NULL, 0, 0)) == 0)
00107                                         return 0;
00108                                 else
00109                                 {
00110                                         TranslateMessage(&msg);
00111                                         DispatchMessage(&msg);
00112                                 }
00113                         }
00114                         else
00115                         {
00116                                 if (isIdleProcessing())
00117                                 {
00118                                         if (m_mfcWindow->isIdleProcessing())
00119                                                 m_mfcWindow->doIdle();
00120                                 }
00121                                 else
00122                                 {
00123                                         WaitMessage();
00124                                 }
00125                         }
00126                 }
00127                 return 0;
00128         }
00129 };
00136 #endif

Generated on Fri Sep 1 15:36:47 2006 for Interactive Visualisation Framework - Ivf++ by  doxygen 1.4.6-NO