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$
00028 //
00029 // G.Barrand
00030 
00031 #if defined(G4INTY_BUILD_WIN32) || defined(G4INTY_USE_WIN32)
00032 
00033 // this :
00034 #include "G4Win32.hh"
00035 
00036 #include "G4ios.hh"
00037 
00038 static char className[] = "G4Win32";
00039 
00040 G4Win32* G4Win32::instance  = NULL;
00041 
00042 static G4bool    Win32Inited   = FALSE;
00043 static HWND      topWindow     = NULL;
00044 /***************************************************************************/
00045 G4Win32* G4Win32::getInstance (
00046 ) 
00047 /***************************************************************************/
00049 {
00050   if (instance==NULL) {
00051     instance = new G4Win32();
00052   }
00053   return instance;
00054 }
00055 /***************************************************************************/
00056 G4Win32::G4Win32 (
00057 ) 
00058 /***************************************************************************/
00060 {
00061   if(Win32Inited==FALSE) { // Should be Done once.
00062 
00063     WNDCLASS         wc;
00064     wc.style         = CS_HREDRAW | CS_VREDRAW;
00065     wc.lpfnWndProc   = (WNDPROC)DefWindowProc;
00066     wc.cbClsExtra    = 0;
00067     wc.cbWndExtra    = 0;
00068     wc.hInstance     = ::GetModuleHandle(NULL);
00069     wc.hIcon         = LoadIcon  (NULL,IDI_APPLICATION);
00070     wc.hCursor       = LoadCursor(NULL,IDC_ARROW);
00071     wc.hbrBackground = GetStockBrush(BLACK_BRUSH);
00072     wc.lpszMenuName  = className;
00073     wc.lpszClassName = className;
00074     ::RegisterClass  (&wc);
00075     
00076     topWindow   = ::CreateWindow(className,className, 
00077                                  WS_OVERLAPPEDWINDOW,
00078                                  CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 
00079                                  NULL, NULL, 
00080                                  ::GetModuleHandle(NULL),
00081                                  NULL);
00082     
00083     if(topWindow==NULL) {
00084       G4cout << "G4Win32 : Unable to create Win32 window." << G4endl;
00085     }
00086 
00087     Win32Inited = TRUE;
00088   }
00089 
00090   AddDispatcher((G4DispatchFunction)G4Win32::DispatchWin32Event);
00091   SetMainInteractor(topWindow);
00092 }
00093 /***************************************************************************/
00094 G4Win32::~G4Win32 (
00095 ) 
00096 /***************************************************************************/
00098 {
00099   if(this==instance) {
00100     instance = NULL;
00101   }
00102 }
00103 /***************************************************************************/
00104 G4bool G4Win32::Inited (
00105 )
00106 /***************************************************************************/
00108 {
00109   return Win32Inited;
00110 }
00111 /***************************************************************************/
00112 void* G4Win32::GetEvent (
00113 ) 
00114 /***************************************************************************/
00116 {
00117   static MSG event;
00118   BOOL status = ::GetMessage(&event, NULL, 0, 0);
00119   if(status==FALSE) return NULL;
00120   return &event;
00121 }
00122 /***************************************************************************/
00123 void G4Win32::FlushAndWaitExecution (
00124 )
00125 /***************************************************************************/
00127 {
00128   MSG event;
00129   while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
00130     ::TranslateMessage(&event);
00131     ::DispatchMessage (&event);
00132   }
00133 }
00134 /***************************************************************************/
00135 G4bool G4Win32::DispatchWin32Event  (
00136  void* a_event
00137 )
00138 /***************************************************************************/
00140 {
00141   ::TranslateMessage((MSG*)a_event);
00142   ::DispatchMessage ((MSG*)a_event);
00143   return TRUE;
00144 }
00145 
00146 #endif //HAS_WIN32
00147 

Generated on Mon May 27 17:50:25 2013 for Geant4 by  doxygen 1.4.7