ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4Win32.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4Win32.cc
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 //
28 // G.Barrand
29 
30 #if defined(G4INTY_BUILD_WIN32) || defined(G4INTY_USE_WIN32)
31 
32 // this :
33 #include "G4Win32.hh"
34 
35 #include "G4ios.hh"
36 
37 static char className[] = "G4Win32";
38 
39 G4Win32* G4Win32::instance = NULL;
40 
41 static G4bool Win32Inited = FALSE;
42 static HWND topWindow = NULL;
43 /***************************************************************************/
44 G4Win32* G4Win32::getInstance (
45 )
46 /***************************************************************************/
48 {
49  if (instance==NULL) {
50  instance = new G4Win32();
51  }
52  return instance;
53 }
54 /***************************************************************************/
55 G4Win32::G4Win32 (
56 )
57 /***************************************************************************/
59 {
60  if(Win32Inited==FALSE) { // Should be Done once.
61 
62  WNDCLASS wc;
63  wc.style = CS_HREDRAW | CS_VREDRAW;
64  wc.lpfnWndProc = (WNDPROC)DefWindowProc;
65  wc.cbClsExtra = 0;
66  wc.cbWndExtra = 0;
67  wc.hInstance = ::GetModuleHandle(NULL);
68  wc.hIcon = LoadIcon (NULL,IDI_APPLICATION);
69  wc.hCursor = LoadCursor(NULL,IDC_ARROW);
70  wc.hbrBackground = GetStockBrush(BLACK_BRUSH);
71  wc.lpszMenuName = className;
72  wc.lpszClassName = className;
73  ::RegisterClass (&wc);
74 
75  topWindow = ::CreateWindow(className,className,
76  WS_OVERLAPPEDWINDOW,
77  CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
78  NULL, NULL,
79  ::GetModuleHandle(NULL),
80  NULL);
81 
82  if(topWindow==NULL) {
83  G4cout << "G4Win32 : Unable to create Win32 window." << G4endl;
84  }
85 
86  Win32Inited = TRUE;
87  }
88 
89  AddDispatcher((G4DispatchFunction)G4Win32::DispatchWin32Event);
90  SetMainInteractor(topWindow);
91 }
92 /***************************************************************************/
93 G4Win32::~G4Win32 (
94 )
95 /***************************************************************************/
97 {
98  if(this==instance) {
99  instance = NULL;
100  }
101 }
102 /***************************************************************************/
103 G4bool G4Win32::Inited (
104 )
105 /***************************************************************************/
107 {
108  return Win32Inited;
109 }
110 /***************************************************************************/
111 void* G4Win32::GetEvent (
112 )
113 /***************************************************************************/
115 {
116  static MSG event;
117  BOOL status = ::GetMessage(&event, NULL, 0, 0);
118  if(status==FALSE) return NULL;
119  return &event;
120 }
121 /***************************************************************************/
122 void G4Win32::FlushAndWaitExecution (
123 )
124 /***************************************************************************/
126 {
127  MSG event;
128  while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
129  ::TranslateMessage(&event);
130  ::DispatchMessage (&event);
131  }
132 }
133 /***************************************************************************/
134 G4bool G4Win32::DispatchWin32Event (
135  void* a_event
136 )
137 /***************************************************************************/
139 {
140  ::TranslateMessage((MSG*)a_event);
141  ::DispatchMessage ((MSG*)a_event);
142  return TRUE;
143 }
144 
145 #endif //HAS_WIN32
146