1 // Windows/Handle.h 2 3 #ifndef __WINDOWS_HANDLE_H 4 #define __WINDOWS_HANDLE_H 5 6 #include "../Common/MyTypes.h" 7 8 namespace NWindows { 9 10 class CHandle MY_UNCOPYABLE 11 { 12 protected: 13 HANDLE _handle; 14 public: HANDLE()15 operator HANDLE() { return _handle; } CHandle()16 CHandle(): _handle(NULL) {} ~CHandle()17 ~CHandle() { Close(); } IsCreated()18 bool IsCreated() const { return (_handle != NULL); } Close()19 bool Close() 20 { 21 if (_handle == NULL) 22 return true; 23 if (!::CloseHandle(_handle)) 24 return false; 25 _handle = NULL; 26 return true; 27 } Attach(HANDLE handle)28 void Attach(HANDLE handle) { _handle = handle; } Detach()29 HANDLE Detach() 30 { 31 HANDLE handle = _handle; 32 _handle = NULL; 33 return handle; 34 } 35 }; 36 37 } 38 39 #endif 40