00001 #ifndef WINOSTREAM_H 00002 #define WINOSTREAM_H 00003 #include <abuse/abuse.h> 00004 #include <string> 00005 #include <sstream> 00006 #include <abuse/abuse.h> 00007 #include <abuse/VirtStream.h> 00008 00009 00010 class winostream:public VirtStream 00011 { 00012 public: 00013 winostream(HWND hWnd):m_hWnd(hWnd){} 00014 virtual VirtStream& operator<<(end e) 00015 { 00016 return e(*this); 00017 } 00018 virtual VirtStream& operator<<(const char* c) 00019 { 00020 if(IsWindow(m_hWnd)) 00021 { 00022 SendMessage(m_hWnd,EM_SETSEL,(DWORD)-1,GetWindowTextLength(m_hWnd)); 00023 SendMessage(m_hWnd,EM_REPLACESEL,(WPARAM)FALSE,(LPARAM)c); 00024 } 00025 return *this; 00026 } 00027 virtual VirtStream& operator<<(const std::string& s) 00028 { 00029 return print(s); 00030 } 00031 virtual VirtStream& operator<<(int n) 00032 { 00033 return print(n); 00034 } 00035 virtual VirtStream& operator<<(double n) 00036 { 00037 return print(n); 00038 } 00039 virtual VirtStream& operator<<(char c) 00040 { 00041 static char buf[2]="\0"; 00042 buf[0]=c; 00043 return operator<<((const char*)buf); 00044 } 00045 00046 virtual VirtStream* clone() 00047 { 00048 return new winostream(*this); 00049 } 00050 protected: 00051 00052 template<typename T> 00053 VirtStream& print(T t) 00054 { 00055 std::ostringstream oss; 00056 oss<<t; 00057 std::string s=oss.str(); 00058 size_t pos=0; 00059 while((pos=s.find('\n',pos+1))!=std::string::npos) 00060 { 00061 s.insert(pos++,"\r"); 00062 } 00063 return operator<<((const char*)(s.c_str())); 00064 } 00065 VirtStream& endl(); 00066 private: 00067 HWND m_hWnd; 00068 }; 00069 00070 00071 00072 #endif //WINOSTREAM_H