michael@0: // Windows/Window.cpp michael@0: michael@0: #include "StdAfx.h" michael@0: michael@0: #ifndef _UNICODE michael@0: #include "Common/StringConvert.h" michael@0: #endif michael@0: #include "Windows/Window.h" michael@0: michael@0: #ifndef _UNICODE michael@0: extern bool g_IsNT; michael@0: #endif michael@0: michael@0: namespace NWindows { michael@0: michael@0: #ifndef _UNICODE michael@0: ATOM MyRegisterClass(CONST WNDCLASSW *wndClass) michael@0: { michael@0: if (g_IsNT) michael@0: return RegisterClassW(wndClass); michael@0: WNDCLASSA wndClassA; michael@0: wndClassA.style = wndClass->style; michael@0: wndClassA.lpfnWndProc = wndClass->lpfnWndProc; michael@0: wndClassA.cbClsExtra = wndClass->cbClsExtra; michael@0: wndClassA.cbWndExtra = wndClass->cbWndExtra; michael@0: wndClassA.hInstance = wndClass->hInstance; michael@0: wndClassA.hIcon = wndClass->hIcon; michael@0: wndClassA.hCursor = wndClass->hCursor; michael@0: wndClassA.hbrBackground = wndClass->hbrBackground; michael@0: AString menuName; michael@0: AString className; michael@0: if (IS_INTRESOURCE(wndClass->lpszMenuName)) michael@0: wndClassA.lpszMenuName = (LPCSTR)wndClass->lpszMenuName; michael@0: else michael@0: { michael@0: menuName = GetSystemString(wndClass->lpszMenuName); michael@0: wndClassA.lpszMenuName = menuName; michael@0: } michael@0: if (IS_INTRESOURCE(wndClass->lpszClassName)) michael@0: wndClassA.lpszClassName = (LPCSTR)wndClass->lpszClassName; michael@0: else michael@0: { michael@0: className = GetSystemString(wndClass->lpszClassName); michael@0: wndClassA.lpszClassName = className; michael@0: } michael@0: return RegisterClassA(&wndClassA); michael@0: } michael@0: michael@0: bool CWindow::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: { michael@0: if (g_IsNT) michael@0: { michael@0: _window = ::CreateWindowW(className, windowName, michael@0: style, x, y, width, height, parentWindow, michael@0: idOrHMenu, instance, createParam); michael@0: return (_window != NULL); michael@0: } michael@0: return Create(GetSystemString(className), GetSystemString(windowName), michael@0: style, x, y, width, height, parentWindow, michael@0: idOrHMenu, instance, createParam); michael@0: } michael@0: michael@0: bool CWindow::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: { michael@0: if (g_IsNT) michael@0: { michael@0: _window = ::CreateWindowExW(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: AString classNameA; michael@0: LPCSTR classNameP; michael@0: if (IS_INTRESOURCE(className)) michael@0: classNameP = (LPCSTR)className; michael@0: else michael@0: { michael@0: classNameA = GetSystemString(className); michael@0: classNameP = classNameA; michael@0: } michael@0: AString windowNameA; michael@0: LPCSTR windowNameP; michael@0: if (IS_INTRESOURCE(windowName)) michael@0: windowNameP = (LPCSTR)windowName; michael@0: else michael@0: { michael@0: windowNameA = GetSystemString(windowName); michael@0: windowNameP = windowNameA; michael@0: } michael@0: return CreateEx(exStyle, classNameP, windowNameP, michael@0: style, x, y, width, height, parentWindow, michael@0: idOrHMenu, instance, createParam); michael@0: } michael@0: michael@0: #endif michael@0: michael@0: #ifndef _UNICODE michael@0: bool MySetWindowText(HWND wnd, LPCWSTR s) michael@0: { michael@0: if (g_IsNT) michael@0: return BOOLToBool(::SetWindowTextW(wnd, s)); michael@0: return BOOLToBool(::SetWindowTextA(wnd, UnicodeStringToMultiByte(s))); michael@0: } michael@0: #endif michael@0: michael@0: bool CWindow::GetText(CSysString &s) michael@0: { michael@0: s.Empty(); michael@0: int length = GetTextLength(); michael@0: if (length == 0) michael@0: return (::GetLastError() == ERROR_SUCCESS); michael@0: length = GetText(s.GetBuffer(length), length + 1); michael@0: s.ReleaseBuffer(); michael@0: if (length == 0) michael@0: return (::GetLastError() != ERROR_SUCCESS); michael@0: return true; michael@0: } michael@0: michael@0: #ifndef _UNICODE michael@0: bool CWindow::GetText(UString &s) michael@0: { michael@0: if (g_IsNT) michael@0: { michael@0: s.Empty(); michael@0: int length = GetWindowTextLengthW(_window); michael@0: if (length == 0) michael@0: return (::GetLastError() == ERROR_SUCCESS); michael@0: length = GetWindowTextW(_window, s.GetBuffer(length), length + 1); michael@0: s.ReleaseBuffer(); michael@0: if (length == 0) michael@0: return (::GetLastError() == ERROR_SUCCESS); michael@0: return true; michael@0: } michael@0: CSysString sysString; michael@0: bool result = GetText(sysString); michael@0: s = GetUnicodeString(sysString); michael@0: return result; michael@0: } michael@0: #endif michael@0: michael@0: michael@0: /* michael@0: bool CWindow::ModifyStyleBase(int styleOffset, michael@0: DWORD remove, DWORD add, UINT flags) michael@0: { michael@0: DWORD style = GetWindowLong(styleOffset); michael@0: DWORD newStyle = (style & ~remove) | add; michael@0: if (style == newStyle) michael@0: return false; // it is not good michael@0: michael@0: SetWindowLong(styleOffset, newStyle); michael@0: if (flags != 0) michael@0: { michael@0: ::SetWindowPos(_window, NULL, 0, 0, 0, 0, michael@0: SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | flags); michael@0: } michael@0: return TRUE; michael@0: } michael@0: */ michael@0: michael@0: }