michael@0: // Windows/Window.h michael@0: michael@0: #ifndef __WINDOWS_WINDOW_H michael@0: #define __WINDOWS_WINDOW_H michael@0: michael@0: #include "Windows/Defs.h" michael@0: #include "Common/String.h" michael@0: michael@0: namespace NWindows { michael@0: michael@0: inline ATOM MyRegisterClass(CONST WNDCLASS *wndClass) michael@0: { return ::RegisterClass(wndClass); } michael@0: michael@0: #ifndef _UNICODE michael@0: ATOM MyRegisterClass(CONST WNDCLASSW *wndClass); michael@0: #endif michael@0: michael@0: #ifdef _UNICODE michael@0: inline bool MySetWindowText(HWND wnd, LPCWSTR s) { return BOOLToBool(::SetWindowText(wnd, s)); } michael@0: #else michael@0: bool MySetWindowText(HWND wnd, LPCWSTR s); michael@0: #endif michael@0: michael@0: michael@0: michael@0: class CWindow michael@0: { michael@0: private: michael@0: // bool ModifyStyleBase(int styleOffset, DWORD remove, DWORD add, UINT flags); michael@0: protected: michael@0: HWND _window; michael@0: public: michael@0: CWindow(HWND newWindow = NULL): _window(newWindow){}; michael@0: CWindow& operator=(HWND newWindow) michael@0: { michael@0: _window = newWindow; michael@0: return *this; michael@0: } michael@0: operator HWND() const { return _window; } michael@0: void Attach(HWND newWindow) { _window = newWindow; } michael@0: HWND Detach() michael@0: { michael@0: HWND window = _window; michael@0: _window = NULL; michael@0: return window; michael@0: } michael@0: michael@0: HWND GetParent() const { return ::GetParent(_window); } michael@0: bool GetWindowRect(LPRECT rect) const { return BOOLToBool(::GetWindowRect(_window,rect )); } michael@0: bool IsZoomed() const { return BOOLToBool(::IsZoomed(_window)); } michael@0: bool ClientToScreen(LPPOINT point) const { return BOOLToBool(::ClientToScreen(_window, point)); } michael@0: bool ScreenToClient(LPPOINT point) const { return BOOLToBool(::ScreenToClient(_window, point)); } michael@0: michael@0: bool CreateEx(DWORD exStyle, LPCTSTR className, michael@0: LPCTSTR windowName, DWORD style, michael@0: int x, int y, int width, int height, michael@0: HWND parentWindow, HMENU idOrHMenu, michael@0: HINSTANCE instance, LPVOID createParam) michael@0: { michael@0: _window = ::CreateWindowEx(exStyle, className, windowName, michael@0: style, x, y, width, height, parentWindow, michael@0: idOrHMenu, instance, createParam); michael@0: return (_window != NULL); michael@0: } michael@0: michael@0: bool Create(LPCTSTR className, michael@0: LPCTSTR windowName, DWORD style, michael@0: int x, int y, int width, int height, michael@0: HWND parentWindow, HMENU idOrHMenu, michael@0: HINSTANCE instance, LPVOID createParam) michael@0: { michael@0: _window = ::CreateWindow(className, windowName, michael@0: style, x, y, width, height, parentWindow, michael@0: idOrHMenu, instance, createParam); michael@0: return (_window != NULL); michael@0: } michael@0: michael@0: #ifndef _UNICODE michael@0: bool Create(LPCWSTR className, michael@0: LPCWSTR windowName, DWORD style, michael@0: int x, int y, int width, int height, michael@0: HWND parentWindow, HMENU idOrHMenu, michael@0: HINSTANCE instance, LPVOID createParam); michael@0: bool CreateEx(DWORD exStyle, LPCWSTR className, michael@0: LPCWSTR windowName, DWORD style, michael@0: int x, int y, int width, int height, michael@0: HWND parentWindow, HMENU idOrHMenu, michael@0: HINSTANCE instance, LPVOID createParam); michael@0: #endif michael@0: michael@0: michael@0: bool Destroy() michael@0: { michael@0: if (_window == NULL) michael@0: return true; michael@0: bool result = BOOLToBool(::DestroyWindow(_window)); michael@0: if(result) michael@0: _window = NULL; michael@0: return result; michael@0: } michael@0: bool IsWindow() { return BOOLToBool(::IsWindow(_window)); } michael@0: bool Move(int x, int y, int width, int height, bool repaint = true) michael@0: { return BOOLToBool(::MoveWindow(_window, x, y, width, height, BoolToBOOL(repaint))); } michael@0: bool GetClientRect(LPRECT rect) { return BOOLToBool(::GetClientRect(_window, rect)); } michael@0: bool Show(int cmdShow) { return BOOLToBool(::ShowWindow(_window, cmdShow)); } michael@0: bool SetPlacement(CONST WINDOWPLACEMENT *placement) { return BOOLToBool(::SetWindowPlacement(_window, placement)); } michael@0: bool GetPlacement(WINDOWPLACEMENT *placement) { return BOOLToBool(::GetWindowPlacement(_window, placement)); } michael@0: bool Update() { return BOOLToBool(::UpdateWindow(_window)); } michael@0: bool InvalidateRect(LPCRECT rect, bool backgroundErase = true) michael@0: { return BOOLToBool(::InvalidateRect(_window, rect, BoolToBOOL(backgroundErase))); } michael@0: void SetRedraw(bool redraw = true) { SendMessage(WM_SETREDRAW, BoolToBOOL(redraw), 0); } michael@0: michael@0: #ifndef _WIN32_WCE michael@0: LONG SetStyle(LONG_PTR style) michael@0: { return SetLongPtr(GWL_STYLE, style); } michael@0: DWORD GetStyle( ) const michael@0: { return GetLongPtr(GWL_STYLE); } michael@0: #else michael@0: LONG SetStyle(LONG_PTR style) michael@0: { return SetLong(GWL_STYLE, style); } michael@0: DWORD GetStyle( ) const michael@0: { return GetLong(GWL_STYLE); } michael@0: #endif michael@0: michael@0: LONG_PTR SetLong(int index, LONG_PTR newLongPtr ) michael@0: { return ::SetWindowLong(_window, index, newLongPtr); } michael@0: LONG_PTR GetLong(int index) const michael@0: { return ::GetWindowLong(_window, index ); } michael@0: LONG_PTR SetUserDataLong(LONG_PTR newLongPtr ) michael@0: { return SetLong(GWLP_USERDATA, newLongPtr); } michael@0: LONG_PTR GetUserDataLong() const michael@0: { return GetLong(GWLP_USERDATA); } michael@0: michael@0: #ifndef _WIN32_WCE michael@0: LONG_PTR SetLongPtr(int index, LONG_PTR newLongPtr ) michael@0: { return ::SetWindowLongPtr(_window, index, newLongPtr); } michael@0: #ifndef _UNICODE michael@0: LONG_PTR SetLongPtrW(int index, LONG_PTR newLongPtr ) michael@0: { return ::SetWindowLongPtrW(_window, index, newLongPtr); } michael@0: #endif michael@0: michael@0: LONG_PTR GetLongPtr(int index) const michael@0: { return ::GetWindowLongPtr(_window, index ); } michael@0: LONG_PTR SetUserDataLongPtr(LONG_PTR newLongPtr ) michael@0: { return SetLongPtr(GWLP_USERDATA, newLongPtr); } michael@0: LONG_PTR GetUserDataLongPtr() const michael@0: { return GetLongPtr(GWLP_USERDATA); } michael@0: #endif michael@0: michael@0: /* michael@0: bool ModifyStyle(HWND hWnd, DWORD remove, DWORD add, UINT flags = 0) michael@0: { return ModifyStyleBase(GWL_STYLE, remove, add, flags); } michael@0: bool ModifyStyleEx(HWND hWnd, DWORD remove, DWORD add, UINT flags = 0) michael@0: { return ModifyStyleBase(GWL_EXSTYLE, remove, add, flags); } michael@0: */ michael@0: michael@0: HWND SetFocus() { return ::SetFocus(_window); } michael@0: michael@0: LRESULT SendMessage(UINT message, WPARAM wParam = 0, LPARAM lParam = 0) michael@0: { return ::SendMessage(_window, message, wParam, lParam) ;} michael@0: #ifndef _UNICODE michael@0: LRESULT SendMessageW(UINT message, WPARAM wParam = 0, LPARAM lParam = 0) michael@0: { return ::SendMessageW(_window, message, wParam, lParam) ;} michael@0: #endif michael@0: michael@0: bool PostMessage(UINT message, WPARAM wParam = 0, LPARAM lParam = 0) michael@0: { return BOOLToBool(::PostMessage(_window, message, wParam, lParam)) ;} michael@0: #ifndef _UNICODE michael@0: LRESULT PostMessageW(UINT message, WPARAM wParam = 0, LPARAM lParam = 0) michael@0: { return ::PostMessageW(_window, message, wParam, lParam) ;} michael@0: #endif michael@0: michael@0: bool SetText(LPCTSTR s) { return BOOLToBool(::SetWindowText(_window, s)); } michael@0: #ifndef _UNICODE michael@0: bool CWindow::SetText(LPCWSTR s) { return MySetWindowText(_window, s); } michael@0: #endif michael@0: michael@0: int GetTextLength() const michael@0: { return GetWindowTextLength(_window); } michael@0: UINT GetText(LPTSTR string, int maxCount) const michael@0: { return GetWindowText(_window, string, maxCount); } michael@0: bool GetText(CSysString &s); michael@0: #ifndef _UNICODE michael@0: /* michael@0: UINT GetText(LPWSTR string, int maxCount) const michael@0: { return GetWindowTextW(_window, string, maxCount); } michael@0: */ michael@0: bool GetText(UString &s); michael@0: #endif michael@0: michael@0: bool Enable(bool enable) michael@0: { return BOOLToBool(::EnableWindow(_window, BoolToBOOL(enable))); } michael@0: michael@0: bool IsEnabled() michael@0: { return BOOLToBool(::IsWindowEnabled(_window)); } michael@0: michael@0: #ifndef _WIN32_WCE michael@0: HMENU GetSystemMenu(bool revert) michael@0: { return ::GetSystemMenu(_window, BoolToBOOL(revert)); } michael@0: #endif michael@0: michael@0: UINT_PTR SetTimer(UINT_PTR idEvent, UINT elapse, TIMERPROC timerFunc = 0) michael@0: { return ::SetTimer(_window, idEvent, elapse, timerFunc); } michael@0: bool KillTimer(UINT_PTR idEvent) michael@0: {return BOOLToBool(::KillTimer(_window, idEvent)); } michael@0: }; michael@0: michael@0: } michael@0: michael@0: #endif michael@0: