Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

G4Win32.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id: G4Win32.cc,v 1.9 2006/06/29 19:10:26 gunter Exp $
00028 // GEANT4 tag $Name: geant4-08-01-patch-01 $
00029 //
00030 // G.Barrand
00031 
00032 #if defined(G4INTY_BUILD_WIN32) || defined(G4INTY_USE_WIN32)
00033 
00034 // this :
00035 #include "G4Win32.hh"
00036 
00037 #include "G4ios.hh"
00038 
00039 static char className[] = "G4Win32";
00040 
00041 G4Win32* G4Win32::instance  = NULL;
00042 
00043 static G4bool    Win32Inited   = FALSE;
00044 static HWND      topWindow     = NULL;
00045 /***************************************************************************/
00046 G4Win32* G4Win32::getInstance (
00047 ) 
00048 /***************************************************************************/
00050 {
00051   if (instance==NULL) {
00052     instance = new G4Win32();
00053   }
00054   return instance;
00055 }
00056 /***************************************************************************/
00057 G4Win32::G4Win32 (
00058 ) 
00059 /***************************************************************************/
00061 {
00062   if(Win32Inited==FALSE) { // Should be Done once.
00063 
00064     WNDCLASS         wc;
00065     wc.style         = CS_HREDRAW | CS_VREDRAW;
00066     wc.lpfnWndProc   = (WNDPROC)DefWindowProc;
00067     wc.cbClsExtra    = 0;
00068     wc.cbWndExtra    = 0;
00069     wc.hInstance     = ::GetModuleHandle(NULL);
00070     wc.hIcon         = LoadIcon  (NULL,IDI_APPLICATION);
00071     wc.hCursor       = LoadCursor(NULL,IDC_ARROW);
00072     wc.hbrBackground = GetStockBrush(BLACK_BRUSH);
00073     wc.lpszMenuName  = className;
00074     wc.lpszClassName = className;
00075     ::RegisterClass  (&wc);
00076     
00077     topWindow   = ::CreateWindow(className,className, 
00078                                  WS_OVERLAPPEDWINDOW,
00079                                  CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 
00080                                  NULL, NULL, 
00081                                  ::GetModuleHandle(NULL),
00082                                  NULL);
00083     
00084     if(topWindow==NULL) {
00085       G4cout << "G4Win32 : Unable to create Win32 window." << G4endl;
00086     }
00087 
00088     Win32Inited = TRUE;
00089   }
00090 
00091   AddDispatcher((G4DispatchFunction)G4Win32::dispatchWin32Event);
00092   SetMainInteractor(topWindow);
00093 }
00094 /***************************************************************************/
00095 G4Win32::~G4Win32 (
00096 ) 
00097 /***************************************************************************/
00099 {
00100   if(this==instance) {
00101     instance = NULL;
00102   }
00103 }
00104 /***************************************************************************/
00105 G4bool G4Win32::Inited (
00106 )
00107 /***************************************************************************/
00109 {
00110   return Win32Inited;
00111 }
00112 /***************************************************************************/
00113 void* G4Win32::GetEvent (
00114 ) 
00115 /***************************************************************************/
00117 {
00118   static MSG event;
00119   BOOL status = ::GetMessage(&event, NULL, 0, 0);
00120   if(status==FALSE) return NULL;
00121   return &event;
00122 }
00123 /***************************************************************************/
00124 void G4Win32::FlushAndWaitExecution (
00125 )
00126 /***************************************************************************/
00128 {
00129   MSG event;
00130   while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
00131     ::TranslateMessage(&event);
00132     ::DispatchMessage (&event);
00133   }
00134 }
00135 /***************************************************************************/
00136 G4bool G4Win32::dispatchWin32Event  (
00137  void* a_event
00138 )
00139 /***************************************************************************/
00141 {
00142   ::TranslateMessage((MSG*)a_event);
00143   ::DispatchMessage ((MSG*)a_event);
00144   return TRUE;
00145 }
00146 
00147 #endif //HAS_WIN32
00148 

Generated on Fri Jun 22 11:07:02 2007 by doxygen 1.3.4