Files
geant4/source/externals/g4tools/include/tools/Windows/session
T
2021-06-25 16:12:29 +02:00

74 lines
1.6 KiB
Plaintext

// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_Windows_session
#define tools_Windows_session
#include <windows.h>
#include <windowsx.h>
#include <ostream>
namespace tools {
namespace Windows {
class session {
public:
session(std::ostream& a_out):m_out(a_out){}
virtual ~session() {}
protected:
session(const session& a_from):m_out(a_from.m_out){}
session& operator=(const session&){return *this;}
public:
std::ostream& out() const {return m_out;}
bool is_valid() const {return true;}
bool steer() {
while(true) {
MSG event;
BOOL status = ::GetMessage(&event,NULL,0,0);
if(status == -1) { // This may happen (dixit Microsoft doc).
break;
} else if(status == 0) { //WM_QUIT
break;
} else {
::TranslateMessage(&event);
::DispatchMessage (&event);
}
}
return true;
}
bool sync() {
MSG event;
while(::PeekMessage(&event,NULL,0,0,PM_REMOVE)) {
if(event.message==WM_QUIT) return false;
::TranslateMessage(&event);
::DispatchMessage(&event);
}
return true;
}
void show_window(HWND a_hwnd){
::SetForegroundWindow(a_hwnd);
::ShowWindow(a_hwnd,SW_SHOWDEFAULT);
::UpdateWindow(a_hwnd);
::DrawMenuBar(a_hwnd);
}
void set_size(HWND a_hwnd,unsigned int a_width,unsigned int a_height) {
::MoveWindow(a_hwnd,0,0,a_width,a_height,TRUE);
}
//void post(HWND a_hwnd,LPARAM a_msg){
// ::PostMessage(a_hwnd,WM_USER,(WPARAM)0,a_msg);
//}
protected:
std::ostream& m_out;
};
}}
#endif