other-licenses/7zstub/src/Windows/Window.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/other-licenses/7zstub/src/Windows/Window.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,211 @@
     1.4 +// Windows/Window.h
     1.5 +
     1.6 +#ifndef __WINDOWS_WINDOW_H
     1.7 +#define __WINDOWS_WINDOW_H
     1.8 +
     1.9 +#include "Windows/Defs.h"
    1.10 +#include "Common/String.h"
    1.11 +
    1.12 +namespace NWindows {
    1.13 +
    1.14 +inline ATOM MyRegisterClass(CONST WNDCLASS *wndClass)
    1.15 +  { return ::RegisterClass(wndClass); }
    1.16 +
    1.17 +#ifndef _UNICODE
    1.18 +ATOM MyRegisterClass(CONST WNDCLASSW *wndClass);
    1.19 +#endif
    1.20 +
    1.21 +#ifdef _UNICODE
    1.22 +inline bool MySetWindowText(HWND wnd, LPCWSTR s) { return BOOLToBool(::SetWindowText(wnd, s)); }
    1.23 +#else
    1.24 +bool MySetWindowText(HWND wnd, LPCWSTR s);
    1.25 +#endif
    1.26 +
    1.27 +
    1.28 +
    1.29 +class CWindow
    1.30 +{
    1.31 +private:
    1.32 +   // bool ModifyStyleBase(int styleOffset, DWORD remove, DWORD add, UINT flags);
    1.33 +protected:
    1.34 +  HWND _window;
    1.35 +public:
    1.36 +  CWindow(HWND newWindow = NULL): _window(newWindow){};
    1.37 +  CWindow& operator=(HWND newWindow)
    1.38 +  {
    1.39 +    _window = newWindow;
    1.40 +    return *this;
    1.41 +  }
    1.42 +  operator HWND() const { return _window; }
    1.43 +  void Attach(HWND newWindow) { _window = newWindow; }
    1.44 +  HWND Detach()
    1.45 +  {
    1.46 +    HWND window = _window;
    1.47 +    _window = NULL;
    1.48 +    return window;
    1.49 +  }
    1.50 +
    1.51 +  HWND GetParent() const { return ::GetParent(_window); }
    1.52 +  bool GetWindowRect(LPRECT rect) const { return BOOLToBool(::GetWindowRect(_window,rect )); }
    1.53 +  bool IsZoomed() const { return BOOLToBool(::IsZoomed(_window)); }
    1.54 +  bool ClientToScreen(LPPOINT point) const { return BOOLToBool(::ClientToScreen(_window, point)); }
    1.55 +  bool ScreenToClient(LPPOINT point) const { return BOOLToBool(::ScreenToClient(_window, point)); }
    1.56 +
    1.57 +  bool CreateEx(DWORD exStyle, LPCTSTR className,
    1.58 +      LPCTSTR windowName, DWORD style,
    1.59 +      int x, int y, int width, int height,
    1.60 +      HWND parentWindow, HMENU idOrHMenu, 
    1.61 +      HINSTANCE instance, LPVOID createParam)
    1.62 +  {
    1.63 +    _window = ::CreateWindowEx(exStyle, className, windowName,
    1.64 +      style, x, y, width, height, parentWindow, 
    1.65 +      idOrHMenu, instance, createParam);
    1.66 +    return (_window != NULL);
    1.67 +  }
    1.68 +
    1.69 +  bool Create(LPCTSTR className,
    1.70 +      LPCTSTR windowName, DWORD style,
    1.71 +      int x, int y, int width, int height,
    1.72 +      HWND parentWindow, HMENU idOrHMenu, 
    1.73 +      HINSTANCE instance, LPVOID createParam)
    1.74 +  {
    1.75 +    _window = ::CreateWindow(className, windowName,
    1.76 +      style, x, y, width, height, parentWindow, 
    1.77 +      idOrHMenu, instance, createParam);
    1.78 +    return (_window != NULL);
    1.79 +  }
    1.80 +
    1.81 +  #ifndef _UNICODE
    1.82 +  bool Create(LPCWSTR className,
    1.83 +      LPCWSTR windowName, DWORD style,
    1.84 +      int x, int y, int width, int height,
    1.85 +      HWND parentWindow, HMENU idOrHMenu, 
    1.86 +      HINSTANCE instance, LPVOID createParam);
    1.87 +  bool CreateEx(DWORD exStyle, LPCWSTR className,
    1.88 +      LPCWSTR windowName, DWORD style,
    1.89 +      int x, int y, int width, int height,
    1.90 +      HWND parentWindow, HMENU idOrHMenu, 
    1.91 +      HINSTANCE instance, LPVOID createParam);
    1.92 +  #endif
    1.93 +
    1.94 +
    1.95 +  bool Destroy()
    1.96 +  {
    1.97 +    if (_window == NULL)
    1.98 +      return true;
    1.99 +    bool result = BOOLToBool(::DestroyWindow(_window));
   1.100 +    if(result)
   1.101 +      _window = NULL;
   1.102 +    return result;
   1.103 +  }
   1.104 +  bool IsWindow() {  return BOOLToBool(::IsWindow(_window)); }
   1.105 +  bool Move(int x, int y, int width, int height, bool repaint = true)
   1.106 +    { return BOOLToBool(::MoveWindow(_window, x, y, width, height, BoolToBOOL(repaint))); }
   1.107 +  bool GetClientRect(LPRECT rect) { return BOOLToBool(::GetClientRect(_window, rect)); }
   1.108 +  bool Show(int cmdShow) { return BOOLToBool(::ShowWindow(_window, cmdShow)); }
   1.109 +  bool SetPlacement(CONST WINDOWPLACEMENT *placement) { return BOOLToBool(::SetWindowPlacement(_window, placement)); }
   1.110 +  bool GetPlacement(WINDOWPLACEMENT *placement) { return BOOLToBool(::GetWindowPlacement(_window, placement)); }
   1.111 +  bool Update() { return BOOLToBool(::UpdateWindow(_window)); }
   1.112 +  bool InvalidateRect(LPCRECT rect, bool backgroundErase = true)
   1.113 +    { return BOOLToBool(::InvalidateRect(_window, rect, BoolToBOOL(backgroundErase))); }
   1.114 +  void SetRedraw(bool redraw = true) { SendMessage(WM_SETREDRAW, BoolToBOOL(redraw), 0); }
   1.115 +
   1.116 +  #ifndef _WIN32_WCE
   1.117 +  LONG SetStyle(LONG_PTR style)
   1.118 +    { return SetLongPtr(GWL_STYLE, style); }
   1.119 +  DWORD GetStyle( ) const
   1.120 +    { return GetLongPtr(GWL_STYLE); }
   1.121 +  #else
   1.122 +  LONG SetStyle(LONG_PTR style)
   1.123 +    { return SetLong(GWL_STYLE, style); }
   1.124 +  DWORD GetStyle( ) const
   1.125 +    { return GetLong(GWL_STYLE); }
   1.126 +  #endif
   1.127 +
   1.128 +  LONG_PTR SetLong(int index, LONG_PTR newLongPtr )
   1.129 +    { return ::SetWindowLong(_window, index, newLongPtr); }
   1.130 +  LONG_PTR GetLong(int index) const
   1.131 +    { return ::GetWindowLong(_window, index ); }
   1.132 +  LONG_PTR SetUserDataLong(LONG_PTR newLongPtr )
   1.133 +    { return SetLong(GWLP_USERDATA, newLongPtr); } 
   1.134 +  LONG_PTR GetUserDataLong() const
   1.135 +    { return GetLong(GWLP_USERDATA); }
   1.136 +
   1.137 +  #ifndef _WIN32_WCE
   1.138 +  LONG_PTR SetLongPtr(int index, LONG_PTR newLongPtr )
   1.139 +    { return ::SetWindowLongPtr(_window, index, newLongPtr); }
   1.140 +  #ifndef _UNICODE
   1.141 +  LONG_PTR SetLongPtrW(int index, LONG_PTR newLongPtr )
   1.142 +    { return ::SetWindowLongPtrW(_window, index, newLongPtr); }
   1.143 +  #endif
   1.144 +
   1.145 +  LONG_PTR GetLongPtr(int index) const
   1.146 +    { return ::GetWindowLongPtr(_window, index ); }
   1.147 +  LONG_PTR SetUserDataLongPtr(LONG_PTR newLongPtr )
   1.148 +    { return SetLongPtr(GWLP_USERDATA, newLongPtr); }
   1.149 +  LONG_PTR GetUserDataLongPtr() const
   1.150 +    { return GetLongPtr(GWLP_USERDATA); }
   1.151 +  #endif
   1.152 +  
   1.153 +  /*
   1.154 +  bool ModifyStyle(HWND hWnd, DWORD remove, DWORD add, UINT flags = 0)
   1.155 +    {  return ModifyStyleBase(GWL_STYLE, remove, add, flags); }
   1.156 +  bool ModifyStyleEx(HWND hWnd, DWORD remove, DWORD add, UINT flags = 0)
   1.157 +    { return ModifyStyleBase(GWL_EXSTYLE, remove, add, flags); }
   1.158 +  */
   1.159 + 
   1.160 +  HWND SetFocus() { return ::SetFocus(_window); }
   1.161 +
   1.162 +  LRESULT SendMessage(UINT message, WPARAM wParam = 0, LPARAM lParam = 0)
   1.163 +    { return ::SendMessage(_window, message, wParam, lParam) ;}
   1.164 +  #ifndef _UNICODE
   1.165 +  LRESULT SendMessageW(UINT message, WPARAM wParam = 0, LPARAM lParam = 0)
   1.166 +    { return ::SendMessageW(_window, message, wParam, lParam) ;}
   1.167 +  #endif
   1.168 +
   1.169 +  bool PostMessage(UINT message, WPARAM wParam = 0, LPARAM lParam = 0)
   1.170 +    {  return BOOLToBool(::PostMessage(_window, message, wParam, lParam)) ;}
   1.171 +  #ifndef _UNICODE
   1.172 +  LRESULT PostMessageW(UINT message, WPARAM wParam = 0, LPARAM lParam = 0)
   1.173 +    { return ::PostMessageW(_window, message, wParam, lParam) ;}
   1.174 +  #endif
   1.175 +
   1.176 +  bool SetText(LPCTSTR s) { return BOOLToBool(::SetWindowText(_window, s)); }
   1.177 +  #ifndef _UNICODE
   1.178 +  bool CWindow::SetText(LPCWSTR s) { return MySetWindowText(_window, s); }
   1.179 +  #endif
   1.180 +
   1.181 +  int GetTextLength() const 
   1.182 +    { return GetWindowTextLength(_window); }
   1.183 +  UINT GetText(LPTSTR string, int maxCount) const
   1.184 +    { return GetWindowText(_window, string, maxCount); }
   1.185 +  bool GetText(CSysString &s);
   1.186 +  #ifndef _UNICODE
   1.187 +  /*
   1.188 +  UINT GetText(LPWSTR string, int maxCount) const
   1.189 +    { return GetWindowTextW(_window, string, maxCount); }
   1.190 +  */
   1.191 +  bool GetText(UString &s);
   1.192 +  #endif
   1.193 +
   1.194 +  bool Enable(bool enable)
   1.195 +    { return BOOLToBool(::EnableWindow(_window, BoolToBOOL(enable))); }
   1.196 +  
   1.197 +  bool IsEnabled()
   1.198 +    { return BOOLToBool(::IsWindowEnabled(_window)); }
   1.199 +  
   1.200 +  #ifndef _WIN32_WCE
   1.201 +  HMENU GetSystemMenu(bool revert)
   1.202 +    { return ::GetSystemMenu(_window, BoolToBOOL(revert)); }
   1.203 +  #endif
   1.204 +
   1.205 +  UINT_PTR SetTimer(UINT_PTR idEvent, UINT elapse, TIMERPROC timerFunc = 0)
   1.206 +    { return ::SetTimer(_window, idEvent, elapse, timerFunc); }
   1.207 +  bool KillTimer(UINT_PTR idEvent)
   1.208 +    {return BOOLToBool(::KillTimer(_window, idEvent)); }
   1.209 +};
   1.210 +
   1.211 +}
   1.212 +
   1.213 +#endif
   1.214 +

mercurial