Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4Win32.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4Win32.cc 66892 2013-01-17 10:57:59Z gunter $
28 //
29 // G.Barrand
30 
31 #if defined(G4INTY_BUILD_WIN32) || defined(G4INTY_USE_WIN32)
32 
33 // this :
34 #include "G4Win32.hh"
35 
36 #include "G4ios.hh"
37 
38 static char className[] = "G4Win32";
39 
40 G4Win32* G4Win32::instance = NULL;
41 
42 static G4bool Win32Inited = FALSE;
43 static HWND topWindow = NULL;
44 /***************************************************************************/
45 G4Win32* G4Win32::getInstance (
46 )
47 /***************************************************************************/
49 {
50  if (instance==NULL) {
51  instance = new G4Win32();
52  }
53  return instance;
54 }
55 /***************************************************************************/
56 G4Win32::G4Win32 (
57 )
58 /***************************************************************************/
60 {
61  if(Win32Inited==FALSE) { // Should be Done once.
62 
63  WNDCLASS wc;
64  wc.style = CS_HREDRAW | CS_VREDRAW;
65  wc.lpfnWndProc = (WNDPROC)DefWindowProc;
66  wc.cbClsExtra = 0;
67  wc.cbWndExtra = 0;
68  wc.hInstance = ::GetModuleHandle(NULL);
69  wc.hIcon = LoadIcon (NULL,IDI_APPLICATION);
70  wc.hCursor = LoadCursor(NULL,IDC_ARROW);
71  wc.hbrBackground = GetStockBrush(BLACK_BRUSH);
72  wc.lpszMenuName = className;
73  wc.lpszClassName = className;
74  ::RegisterClass (&wc);
75 
76  topWindow = ::CreateWindow(className,className,
77  WS_OVERLAPPEDWINDOW,
78  CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
79  NULL, NULL,
80  ::GetModuleHandle(NULL),
81  NULL);
82 
83  if(topWindow==NULL) {
84  G4cout << "G4Win32 : Unable to create Win32 window." << G4endl;
85  }
86 
87  Win32Inited = TRUE;
88  }
89 
90  AddDispatcher((G4DispatchFunction)G4Win32::DispatchWin32Event);
91  SetMainInteractor(topWindow);
92 }
93 /***************************************************************************/
94 G4Win32::~G4Win32 (
95 )
96 /***************************************************************************/
98 {
99  if(this==instance) {
100  instance = NULL;
101  }
102 }
103 /***************************************************************************/
104 G4bool G4Win32::Inited (
105 )
106 /***************************************************************************/
108 {
109  return Win32Inited;
110 }
111 /***************************************************************************/
112 void* G4Win32::GetEvent (
113 )
114 /***************************************************************************/
116 {
117  static MSG event;
118  BOOL status = ::GetMessage(&event, NULL, 0, 0);
119  if(status==FALSE) return NULL;
120  return &event;
121 }
122 /***************************************************************************/
123 void G4Win32::FlushAndWaitExecution (
124 )
125 /***************************************************************************/
127 {
128  MSG event;
129  while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
130  ::TranslateMessage(&event);
131  ::DispatchMessage (&event);
132  }
133 }
134 /***************************************************************************/
135 G4bool G4Win32::DispatchWin32Event (
136  void* a_event
137 )
138 /***************************************************************************/
140 {
141  ::TranslateMessage((MSG*)a_event);
142  ::DispatchMessage ((MSG*)a_event);
143  return TRUE;
144 }
145 
146 #endif //HAS_WIN32
147 
G4bool(* G4DispatchFunction)(void *)
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
#define FALSE
Definition: globals.hh:52
#define TRUE
Definition: globals.hh:55
#define G4endl
Definition: G4ios.hh:61
static MCTruthManager * instance