Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/toolx/Windows/session is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef toolx_Windows_session
0005 #define toolx_Windows_session
0006 
0007 #include <windows.h>
0008 #include <windowsx.h>
0009 
0010 #include <ostream>
0011 #include <cstdlib>
0012 
0013 namespace toolx {
0014 namespace Windows {
0015 
0016 class session {
0017 public:
0018   session(std::ostream& a_out):m_out(a_out){}
0019   virtual ~session() {}
0020 protected:
0021   session(const session& a_from):m_out(a_from.m_out){}
0022   session& operator=(const session&){return *this;}
0023 public:
0024   std::ostream& out() const {return m_out;}
0025 
0026   bool is_valid() const {return true;}
0027 
0028   bool steer() {
0029     while(true) {
0030       MSG event;
0031       BOOL status = ::GetMessage(&event,NULL,0,0);
0032       if(status == -1) { // This may happen (dixit Microsoft doc).
0033         break;
0034       } else if(status == 0) { //WM_QUIT
0035         break;
0036       } else {
0037         ::TranslateMessage(&event);
0038         ::DispatchMessage (&event);
0039       }
0040     }
0041     return true;
0042   }
0043 
0044   bool sync() {
0045     MSG event;
0046     while(::PeekMessage(&event,NULL,0,0,PM_REMOVE)) {
0047       if(event.message==WM_QUIT) return false;
0048       ::TranslateMessage(&event);
0049       ::DispatchMessage(&event);
0050     }
0051     return true;
0052   }
0053 
0054   void show_window(HWND a_hwnd){
0055     ::SetForegroundWindow(a_hwnd);
0056     ::ShowWindow(a_hwnd,SW_SHOWDEFAULT);
0057     ::UpdateWindow(a_hwnd);
0058     ::DrawMenuBar(a_hwnd);
0059   }
0060 
0061   void set_size(HWND a_hwnd,unsigned int a_width,unsigned int a_height) {
0062     ::MoveWindow(a_hwnd,0,0,a_width,a_height,TRUE);
0063   }
0064 
0065   //void post(HWND a_hwnd,LPARAM a_msg){
0066   //  ::PostMessage(a_hwnd,WM_USER,(WPARAM)0,a_msg);
0067   //}
0068 public:
0069   bool tmp_dir(std::string& a_dir) {
0070     char* env = ::getenv("TEMP");
0071     if(!env) {a_dir.clear();return false;}
0072     a_dir = env;
0073     return true;
0074   }
0075 protected:
0076   std::ostream& m_out;
0077 };
0078 
0079 }}
0080 
0081 
0082 #endif