[476] | 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,v 1.9 2006/06/29 19:10:26 gunter Exp $ |
---|
[483] | 28 | // GEANT4 tag $Name: geant4-08-01-patch-01 $ |
---|
[476] | 29 | // |
---|
| 30 | // G.Barrand |
---|
| 31 | |
---|
| 32 | #if defined(G4INTY_BUILD_WIN32) || defined(G4INTY_USE_WIN32) |
---|
| 33 | |
---|
| 34 | // this : |
---|
| 35 | #include "G4Win32.hh" |
---|
| 36 | |
---|
| 37 | #include "G4ios.hh" |
---|
| 38 | |
---|
| 39 | static char className[] = "G4Win32"; |
---|
| 40 | |
---|
| 41 | G4Win32* G4Win32::instance = NULL; |
---|
| 42 | |
---|
| 43 | static G4bool Win32Inited = FALSE; |
---|
| 44 | static HWND topWindow = NULL; |
---|
| 45 | /***************************************************************************/ |
---|
| 46 | G4Win32* G4Win32::getInstance ( |
---|
| 47 | ) |
---|
| 48 | /***************************************************************************/ |
---|
| 49 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 50 | { |
---|
| 51 | if (instance==NULL) { |
---|
| 52 | instance = new G4Win32(); |
---|
| 53 | } |
---|
| 54 | return instance; |
---|
| 55 | } |
---|
| 56 | /***************************************************************************/ |
---|
| 57 | G4Win32::G4Win32 ( |
---|
| 58 | ) |
---|
| 59 | /***************************************************************************/ |
---|
| 60 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 61 | { |
---|
| 62 | if(Win32Inited==FALSE) { // Should be Done once. |
---|
| 63 | |
---|
| 64 | WNDCLASS wc; |
---|
| 65 | wc.style = CS_HREDRAW | CS_VREDRAW; |
---|
| 66 | wc.lpfnWndProc = (WNDPROC)DefWindowProc; |
---|
| 67 | wc.cbClsExtra = 0; |
---|
| 68 | wc.cbWndExtra = 0; |
---|
| 69 | wc.hInstance = ::GetModuleHandle(NULL); |
---|
| 70 | wc.hIcon = LoadIcon (NULL,IDI_APPLICATION); |
---|
| 71 | wc.hCursor = LoadCursor(NULL,IDC_ARROW); |
---|
| 72 | wc.hbrBackground = GetStockBrush(BLACK_BRUSH); |
---|
| 73 | wc.lpszMenuName = className; |
---|
| 74 | wc.lpszClassName = className; |
---|
| 75 | ::RegisterClass (&wc); |
---|
| 76 | |
---|
| 77 | topWindow = ::CreateWindow(className,className, |
---|
| 78 | WS_OVERLAPPEDWINDOW, |
---|
| 79 | CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, |
---|
| 80 | NULL, NULL, |
---|
| 81 | ::GetModuleHandle(NULL), |
---|
| 82 | NULL); |
---|
| 83 | |
---|
| 84 | if(topWindow==NULL) { |
---|
| 85 | G4cout << "G4Win32 : Unable to create Win32 window." << G4endl; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | Win32Inited = TRUE; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | AddDispatcher((G4DispatchFunction)G4Win32::dispatchWin32Event); |
---|
| 92 | SetMainInteractor(topWindow); |
---|
| 93 | } |
---|
| 94 | /***************************************************************************/ |
---|
| 95 | G4Win32::~G4Win32 ( |
---|
| 96 | ) |
---|
| 97 | /***************************************************************************/ |
---|
| 98 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 99 | { |
---|
| 100 | if(this==instance) { |
---|
| 101 | instance = NULL; |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | /***************************************************************************/ |
---|
| 105 | G4bool G4Win32::Inited ( |
---|
| 106 | ) |
---|
| 107 | /***************************************************************************/ |
---|
| 108 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 109 | { |
---|
| 110 | return Win32Inited; |
---|
| 111 | } |
---|
| 112 | /***************************************************************************/ |
---|
| 113 | void* G4Win32::GetEvent ( |
---|
| 114 | ) |
---|
| 115 | /***************************************************************************/ |
---|
| 116 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 117 | { |
---|
| 118 | static MSG event; |
---|
| 119 | BOOL status = ::GetMessage(&event, NULL, 0, 0); |
---|
| 120 | if(status==FALSE) return NULL; |
---|
| 121 | return &event; |
---|
| 122 | } |
---|
| 123 | /***************************************************************************/ |
---|
| 124 | void G4Win32::FlushAndWaitExecution ( |
---|
| 125 | ) |
---|
| 126 | /***************************************************************************/ |
---|
| 127 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 128 | { |
---|
| 129 | MSG event; |
---|
| 130 | while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) { |
---|
| 131 | ::TranslateMessage(&event); |
---|
| 132 | ::DispatchMessage (&event); |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | /***************************************************************************/ |
---|
| 136 | G4bool G4Win32::dispatchWin32Event ( |
---|
| 137 | void* a_event |
---|
| 138 | ) |
---|
| 139 | /***************************************************************************/ |
---|
| 140 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 141 | { |
---|
| 142 | ::TranslateMessage((MSG*)a_event); |
---|
| 143 | ::DispatchMessage ((MSG*)a_event); |
---|
| 144 | return TRUE; |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | #endif //HAS_WIN32 |
---|
| 148 | |
---|