1 // Windows/Window.cpp
\r
6 #include "Common/StringConvert.h"
\r
8 #include "Windows/Window.h"
\r
14 namespace NWindows {
\r
17 ATOM MyRegisterClass(CONST WNDCLASSW *wndClass)
\r
20 return RegisterClassW(wndClass);
\r
21 WNDCLASSA wndClassA;
\r
22 wndClassA.style = wndClass->style;
\r
23 wndClassA.lpfnWndProc = wndClass->lpfnWndProc;
\r
24 wndClassA.cbClsExtra = wndClass->cbClsExtra;
\r
25 wndClassA.cbWndExtra = wndClass->cbWndExtra;
\r
26 wndClassA.hInstance = wndClass->hInstance;
\r
27 wndClassA.hIcon = wndClass->hIcon;
\r
28 wndClassA.hCursor = wndClass->hCursor;
\r
29 wndClassA.hbrBackground = wndClass->hbrBackground;
\r
32 if (IS_INTRESOURCE(wndClass->lpszMenuName))
\r
33 wndClassA.lpszMenuName = (LPCSTR)wndClass->lpszMenuName;
\r
36 menuName = GetSystemString(wndClass->lpszMenuName);
\r
37 wndClassA.lpszMenuName = menuName;
\r
39 if (IS_INTRESOURCE(wndClass->lpszClassName))
\r
40 wndClassA.lpszClassName = (LPCSTR)wndClass->lpszClassName;
\r
43 className = GetSystemString(wndClass->lpszClassName);
\r
44 wndClassA.lpszClassName = className;
\r
46 return RegisterClassA(&wndClassA);
\r
49 bool CWindow::Create(LPCWSTR className,
\r
50 LPCWSTR windowName, DWORD style,
\r
51 int x, int y, int width, int height,
\r
52 HWND parentWindow, HMENU idOrHMenu,
\r
53 HINSTANCE instance, LPVOID createParam)
\r
57 _window = ::CreateWindowW(className, windowName,
\r
58 style, x, y, width, height, parentWindow,
\r
59 idOrHMenu, instance, createParam);
\r
60 return (_window != NULL);
\r
62 return Create(GetSystemString(className), GetSystemString(windowName),
\r
63 style, x, y, width, height, parentWindow,
\r
64 idOrHMenu, instance, createParam);
\r
67 bool CWindow::CreateEx(DWORD exStyle, LPCWSTR className,
\r
68 LPCWSTR windowName, DWORD style,
\r
69 int x, int y, int width, int height,
\r
70 HWND parentWindow, HMENU idOrHMenu,
\r
71 HINSTANCE instance, LPVOID createParam)
\r
75 _window = ::CreateWindowExW(exStyle, className, windowName,
\r
76 style, x, y, width, height, parentWindow,
\r
77 idOrHMenu, instance, createParam);
\r
78 return (_window != NULL);
\r
82 if (IS_INTRESOURCE(className))
\r
83 classNameP = (LPCSTR)className;
\r
86 classNameA = GetSystemString(className);
\r
87 classNameP = classNameA;
\r
89 AString windowNameA;
\r
91 if (IS_INTRESOURCE(windowName))
\r
92 windowNameP = (LPCSTR)windowName;
\r
95 windowNameA = GetSystemString(windowName);
\r
96 windowNameP = windowNameA;
\r
98 return CreateEx(exStyle, classNameP, windowNameP,
\r
99 style, x, y, width, height, parentWindow,
\r
100 idOrHMenu, instance, createParam);
\r
106 bool MySetWindowText(HWND wnd, LPCWSTR s)
\r
109 return BOOLToBool(::SetWindowTextW(wnd, s));
\r
110 return BOOLToBool(::SetWindowTextA(wnd, UnicodeStringToMultiByte(s)));
\r
114 bool CWindow::GetText(CSysString &s)
\r
117 int length = GetTextLength();
\r
119 return (::GetLastError() == ERROR_SUCCESS);
\r
120 length = GetText(s.GetBuffer(length), length + 1);
\r
123 return (::GetLastError() != ERROR_SUCCESS);
\r
128 bool CWindow::GetText(UString &s)
\r
133 int length = GetWindowTextLengthW(_window);
\r
135 return (::GetLastError() == ERROR_SUCCESS);
\r
136 length = GetWindowTextW(_window, s.GetBuffer(length), length + 1);
\r
139 return (::GetLastError() == ERROR_SUCCESS);
\r
142 CSysString sysString;
\r
143 bool result = GetText(sysString);
\r
144 s = GetUnicodeString(sysString);
\r
151 bool CWindow::ModifyStyleBase(int styleOffset,
\r
152 DWORD remove, DWORD add, UINT flags)
\r
154 DWORD style = GetWindowLong(styleOffset);
\r
155 DWORD newStyle = (style & ~remove) | add;
\r
156 if (style == newStyle)
\r
157 return false; // it is not good
\r
159 SetWindowLong(styleOffset, newStyle);
\r
162 ::SetWindowPos(_window, NULL, 0, 0, 0, 0,
\r
163 SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | flags);
\r