1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/other-licenses/7zstub/src/Windows/Window.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,169 @@ 1.4 +// Windows/Window.cpp 1.5 + 1.6 +#include "StdAfx.h" 1.7 + 1.8 +#ifndef _UNICODE 1.9 +#include "Common/StringConvert.h" 1.10 +#endif 1.11 +#include "Windows/Window.h" 1.12 + 1.13 +#ifndef _UNICODE 1.14 +extern bool g_IsNT; 1.15 +#endif 1.16 + 1.17 +namespace NWindows { 1.18 + 1.19 +#ifndef _UNICODE 1.20 +ATOM MyRegisterClass(CONST WNDCLASSW *wndClass) 1.21 +{ 1.22 + if (g_IsNT) 1.23 + return RegisterClassW(wndClass); 1.24 + WNDCLASSA wndClassA; 1.25 + wndClassA.style = wndClass->style; 1.26 + wndClassA.lpfnWndProc = wndClass->lpfnWndProc; 1.27 + wndClassA.cbClsExtra = wndClass->cbClsExtra; 1.28 + wndClassA.cbWndExtra = wndClass->cbWndExtra; 1.29 + wndClassA.hInstance = wndClass->hInstance; 1.30 + wndClassA.hIcon = wndClass->hIcon; 1.31 + wndClassA.hCursor = wndClass->hCursor; 1.32 + wndClassA.hbrBackground = wndClass->hbrBackground; 1.33 + AString menuName; 1.34 + AString className; 1.35 + if (IS_INTRESOURCE(wndClass->lpszMenuName)) 1.36 + wndClassA.lpszMenuName = (LPCSTR)wndClass->lpszMenuName; 1.37 + else 1.38 + { 1.39 + menuName = GetSystemString(wndClass->lpszMenuName); 1.40 + wndClassA.lpszMenuName = menuName; 1.41 + } 1.42 + if (IS_INTRESOURCE(wndClass->lpszClassName)) 1.43 + wndClassA.lpszClassName = (LPCSTR)wndClass->lpszClassName; 1.44 + else 1.45 + { 1.46 + className = GetSystemString(wndClass->lpszClassName); 1.47 + wndClassA.lpszClassName = className; 1.48 + } 1.49 + return RegisterClassA(&wndClassA); 1.50 +} 1.51 + 1.52 +bool CWindow::Create(LPCWSTR className, 1.53 + LPCWSTR windowName, DWORD style, 1.54 + int x, int y, int width, int height, 1.55 + HWND parentWindow, HMENU idOrHMenu, 1.56 + HINSTANCE instance, LPVOID createParam) 1.57 +{ 1.58 + if (g_IsNT) 1.59 + { 1.60 + _window = ::CreateWindowW(className, windowName, 1.61 + style, x, y, width, height, parentWindow, 1.62 + idOrHMenu, instance, createParam); 1.63 + return (_window != NULL); 1.64 + } 1.65 + return Create(GetSystemString(className), GetSystemString(windowName), 1.66 + style, x, y, width, height, parentWindow, 1.67 + idOrHMenu, instance, createParam); 1.68 +} 1.69 + 1.70 +bool CWindow::CreateEx(DWORD exStyle, LPCWSTR className, 1.71 + LPCWSTR windowName, DWORD style, 1.72 + int x, int y, int width, int height, 1.73 + HWND parentWindow, HMENU idOrHMenu, 1.74 + HINSTANCE instance, LPVOID createParam) 1.75 +{ 1.76 + if (g_IsNT) 1.77 + { 1.78 + _window = ::CreateWindowExW(exStyle, className, windowName, 1.79 + style, x, y, width, height, parentWindow, 1.80 + idOrHMenu, instance, createParam); 1.81 + return (_window != NULL); 1.82 + } 1.83 + AString classNameA; 1.84 + LPCSTR classNameP; 1.85 + if (IS_INTRESOURCE(className)) 1.86 + classNameP = (LPCSTR)className; 1.87 + else 1.88 + { 1.89 + classNameA = GetSystemString(className); 1.90 + classNameP = classNameA; 1.91 + } 1.92 + AString windowNameA; 1.93 + LPCSTR windowNameP; 1.94 + if (IS_INTRESOURCE(windowName)) 1.95 + windowNameP = (LPCSTR)windowName; 1.96 + else 1.97 + { 1.98 + windowNameA = GetSystemString(windowName); 1.99 + windowNameP = windowNameA; 1.100 + } 1.101 + return CreateEx(exStyle, classNameP, windowNameP, 1.102 + style, x, y, width, height, parentWindow, 1.103 + idOrHMenu, instance, createParam); 1.104 +} 1.105 + 1.106 +#endif 1.107 + 1.108 +#ifndef _UNICODE 1.109 +bool MySetWindowText(HWND wnd, LPCWSTR s) 1.110 +{ 1.111 + if (g_IsNT) 1.112 + return BOOLToBool(::SetWindowTextW(wnd, s)); 1.113 + return BOOLToBool(::SetWindowTextA(wnd, UnicodeStringToMultiByte(s))); 1.114 +} 1.115 +#endif 1.116 + 1.117 +bool CWindow::GetText(CSysString &s) 1.118 +{ 1.119 + s.Empty(); 1.120 + int length = GetTextLength(); 1.121 + if (length == 0) 1.122 + return (::GetLastError() == ERROR_SUCCESS); 1.123 + length = GetText(s.GetBuffer(length), length + 1); 1.124 + s.ReleaseBuffer(); 1.125 + if (length == 0) 1.126 + return (::GetLastError() != ERROR_SUCCESS); 1.127 + return true; 1.128 +} 1.129 + 1.130 +#ifndef _UNICODE 1.131 +bool CWindow::GetText(UString &s) 1.132 +{ 1.133 + if (g_IsNT) 1.134 + { 1.135 + s.Empty(); 1.136 + int length = GetWindowTextLengthW(_window); 1.137 + if (length == 0) 1.138 + return (::GetLastError() == ERROR_SUCCESS); 1.139 + length = GetWindowTextW(_window, s.GetBuffer(length), length + 1); 1.140 + s.ReleaseBuffer(); 1.141 + if (length == 0) 1.142 + return (::GetLastError() == ERROR_SUCCESS); 1.143 + return true; 1.144 + } 1.145 + CSysString sysString; 1.146 + bool result = GetText(sysString); 1.147 + s = GetUnicodeString(sysString); 1.148 + return result; 1.149 +} 1.150 +#endif 1.151 + 1.152 + 1.153 +/* 1.154 +bool CWindow::ModifyStyleBase(int styleOffset, 1.155 + DWORD remove, DWORD add, UINT flags) 1.156 +{ 1.157 + DWORD style = GetWindowLong(styleOffset); 1.158 + DWORD newStyle = (style & ~remove) | add; 1.159 + if (style == newStyle) 1.160 + return false; // it is not good 1.161 + 1.162 + SetWindowLong(styleOffset, newStyle); 1.163 + if (flags != 0) 1.164 + { 1.165 + ::SetWindowPos(_window, NULL, 0, 0, 0, 0, 1.166 + SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | flags); 1.167 + } 1.168 + return TRUE; 1.169 +} 1.170 +*/ 1.171 + 1.172 +}