00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #if defined(G4INTY_BUILD_WIN32) || defined(G4INTY_USE_WIN32)
00032
00033
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) {
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