Open-Source-Software-Entwicklung und Downloads

Browse Subversion Repository

Contents of /trunk/TTProxy/YCL/include/YCL/Window.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3227 - (show annotations) (download) (as text)
Tue Mar 24 15:10:33 2009 UTC (15 years, 1 month ago) by maya
File MIME type: text/x-chdr
File size: 11025 byte(s)
CVS から SVN へ移行: 改行コードを LF から CR+LF へ変換
1 /*
2 * $Id: Window.h,v 1.4 2007-08-18 08:52:18 maya Exp $
3 */
4
5 #ifndef _YCL_WINDOWS_H_
6 #define _YCL_WINDOWS_H_
7
8 #if _MSC_VER >= 1000
9 #pragma once
10 #endif // _MSC_VER >= 1000
11
12 #include <YCL/common.h>
13
14 #include <YCL/String.h>
15
16 namespace yebisuya {
17
18 class Window {
19 private:
20 HWND window;
21 public:
22 Window():window(NULL) {
23 }
24 Window(HWND window):window(window) {
25 }
26 void operator<<=(HWND newWindow) {
27 window = newWindow;
28 }
29 operator HWND()const {
30 return window;
31 }
32
33 long GetWindowLong(int index)const {
34 return ::GetWindowLong(window, index);
35 }
36 long SetWindowLong(int index, long data) {
37 return ::SetWindowLong(window, index, data);
38 }
39 int GetWindowTextLength()const {
40 return ::GetWindowTextLength(window);
41 }
42 int GetWindowText(char* buffer, int size)const {
43 return ::GetWindowText(window, buffer, size);
44 }
45 String GetWindowText()const {
46 int length = GetWindowTextLength();
47 char* buffer = (char*) alloca(length + 1);
48 GetWindowText(buffer, length + 1);
49 return buffer;
50 }
51 bool SetWindowText(const char* text) {
52 return ::SetWindowText(window, text) != FALSE;
53 }
54 long SendMessage(int message, int wparam = 0, long lparam = 0)const {
55 return ::SendMessage(window, message, wparam, lparam);
56 }
57 long PostMessage(int message, int wparam = 0, long lparam = 0)const {
58 return ::PostMessage(window, message, wparam, lparam);
59 }
60 HWND GetParent()const {
61 return ::GetParent(window);
62 }
63 bool EnableWindow(bool enabled) {
64 return ::EnableWindow(window, enabled) != FALSE;
65 }
66 long DefWindowProc(int message, int wparam, long lparam) {
67 return ::DefWindowProc(window, message, wparam, lparam);
68 }
69 long CallWindowProc(WNDPROC proc, int message, int wParam, long lParam) {
70 return ::CallWindowProc(proc, window, message, wParam, lParam);
71 }
72 bool ShowWindow(int command) {
73 return ::ShowWindow(window, command) != FALSE;
74 }
75 HWND SetFocus() {
76 return ::SetFocus(window);
77 }
78 HWND SetCapture() {
79 return ::SetCapture(window);
80 }
81 bool IsWindowEnabled()const {
82 return ::IsWindowEnabled(window) != FALSE;
83 }
84 bool IsWindowVisible()const {
85 return ::IsWindowVisible(window) != FALSE;
86 }
87 bool IsIconic()const {
88 return ::IsIconic(window) != FALSE;
89 }
90 bool IsZoomed()const {
91 return ::IsZoomed(window) != FALSE;
92 }
93 int SetTimer(int id, int elapse, TIMERPROC timerProc = NULL) {
94 return ::SetTimer(window, id, elapse, timerProc);
95 }
96 bool KillTimer(int id) {
97 return ::KillTimer(window, id) != FALSE;
98 }
99 HMENU GetMenu()const {
100 return ::GetMenu(window);
101 }
102 bool SetForegroundWindow() {
103 return ::SetForegroundWindow(window) != FALSE;
104 }
105 void UpdateWindow() {
106 ::UpdateWindow(window);
107 }
108 bool GetWindowRect(RECT& rect)const {
109 return ::GetWindowRect(window, &rect) != FALSE;
110 }
111 bool GetClientRect(RECT& rect)const {
112 return ::GetClientRect(window, &rect) != FALSE;
113 }
114 bool SetWindowPos(HWND previous, int x, int y, int cx, int cy, int flags) {
115 return ::SetWindowPos(window, previous, x, y, cx, cy, flags) != FALSE;
116 }
117 bool ClientToScreen(POINT& point)const {
118 return ::ClientToScreen(window, &point) != FALSE;
119 }
120 bool ScreenToClient(POINT& point)const {
121 return ::ScreenToClient(window, &point) != FALSE;
122 }
123 bool ClientToScreen(RECT& rect)const {
124 return ::ClientToScreen(window, (POINT*) &rect.left) != FALSE
125 && ::ClientToScreen(window, (POINT*) &rect.right) != FALSE;
126 }
127 bool ScreenToClient(RECT& rect)const {
128 return ::ScreenToClient(window, (POINT*) &rect.left) != FALSE
129 && ::ScreenToClient(window, (POINT*) &rect.right) != FALSE;
130 }
131 bool InvalidateRect(bool erase = true) {
132 return ::InvalidateRect(window, NULL, erase) != FALSE;
133 }
134 bool InvalidateRect(RECT& rect, bool erase = true) {
135 return ::InvalidateRect(window, &rect, erase) != FALSE;
136 }
137 bool GetWindowPlacement(WINDOWPLACEMENT& wp)const {
138 wp.length = sizeof wp;
139 return ::GetWindowPlacement(window, &wp) != FALSE;
140 }
141 bool SetWindowPlacement(const WINDOWPLACEMENT& wp) {
142 return ::SetWindowPlacement(window, &wp) != FALSE;
143 }
144 HWND ChildWindowFromPoint(POINT point, int flags = CWP_ALL)const {
145 return ::ChildWindowFromPointEx(window, point, flags);
146 }
147 HWND GetLastActivePopup()const {
148 return ::GetLastActivePopup(window);
149 }
150 HWND GetWindow(int command)const {
151 return ::GetWindow(window, command);
152 }
153 HWND GetTopWindow()const {
154 return ::GetTopWindow(window);
155 }
156 bool IsWindow()const {
157 return ::IsWindow(window) != FALSE;
158 }
159 bool IsChild(HWND child)const {
160 return ::IsChild(window, child) != FALSE;
161 }
162 bool MoveWindow(int x, int y, int cx, int cy, bool repaint) {
163 return ::MoveWindow(window, x, y, cx, cy, repaint) != FALSE;
164 }
165 bool OpenIcon() {
166 return ::OpenIcon(window) != FALSE;
167 }
168 bool ShowOwnedPopups(bool show) {
169 return ::ShowOwnedPopups(window, show) != FALSE;
170 }
171 bool ShowWindowAsync(int command) {
172 return ::ShowWindowAsync(window, command) != FALSE;
173 }
174 int GetDlgCtrlID()const {
175 return ::GetDlgCtrlID(window);
176 }
177 HWND GetDlgItem(int id)const {
178 return ::GetDlgItem(window, id);
179 }
180 bool DestroyWindow() {
181 if (window == NULL || ::DestroyWindow(window) == FALSE)
182 return false;
183 window = NULL;
184 return true;
185 }
186 bool CloseWindow() {
187 return ::CloseWindow(window) != FALSE;
188 }
189 int SetScrollPos(int type, int position, bool redraw) {
190 return ::SetScrollPos(window, type, position, redraw);
191 }
192 int GetScrollPos(int type)const {
193 return ::GetScrollPos(window, type);
194 }
195 bool SetScrollRange(int type, int minimum, int maximum, bool redraw) {
196 return ::SetScrollRange(window, type, minimum, maximum, redraw) != FALSE;
197 }
198 bool GetScrollRange(int type, int& minimum, int& maximum)const {
199 return ::GetScrollRange(window, type, &minimum, &maximum) != FALSE;
200 }
201 int SetScrollInfo(int type, const SCROLLINFO& info, bool redraw) {
202 return ::SetScrollInfo(window, type, &info, redraw);
203 }
204 bool GetScrollInfo(int type, SCROLLINFO& info)const {
205 return ::GetScrollInfo(window, type, &info) != FALSE;
206 }
207 long SetLayeredWindowAttributes(long reserved, int parameters, long attribute) {
208 static const char USER32[] = "user32.dll";
209 static const char APINAME[] = "SetLayeredWindowAttributes";
210 static DWORD (WINAPI* api)(HWND, DWORD, BYTE, DWORD)
211 = (DWORD (WINAPI*)(HWND, DWORD, BYTE, DWORD)) ::GetProcAddress(::GetModuleHandle(USER32), APINAME);
212 return api != NULL ? (*api)(window, reserved, parameters, attribute) : 0;
213 }
214 long SetLayeredWindowAttributes(int parameters, long attribute) {
215 return SetLayeredWindowAttributes(0, parameters, attribute);
216 }
217 HWND SetClipboardViewer() {
218 return ::SetClipboardViewer(window);
219 }
220 bool ChangeClipboardChain(HWND newNext) {
221 return ::ChangeClipboardChain(window, newNext) != FALSE;
222 }
223 bool RegisterHotKey(int id, int modifiers, int keycode) {
224 return ::RegisterHotKey(window, id, modifiers, keycode) != FALSE;
225 }
226 bool UnregisterHotKey(int id) {
227 return ::UnregisterHotKey(window, id) != FALSE;
228 }
229 int MessageBox(const char* message, const char* caption, int type) {
230 return ::MessageBox(window, message, caption, type);
231 }
232 int MessageBox(const char* message, int type) {
233 Window top(window);
234 while ((top.getStyle() & WS_CHILD) != 0) {
235 top <<= top.GetParent();
236 }
237 return MessageBox(message, top.GetWindowText(), type);
238 }
239 long GetClassLong(int index)const {
240 return ::GetClassLong(window, index);
241 }
242 long SetClassLong(int index, long data) {
243 return ::SetClassLong(window, index, data);
244 }
245
246 bool create(long exStyle, const char* classname, const char* title, long style, const RECT& rect, HWND parent, HMENU menu, void* param = NULL) {
247 return create(exStyle, classname, title, style, rect, parent, menu, GetInstanceHandle(), param);
248 }
249 bool create(long exStyle, const char* classname, const char* title, long style, const RECT& rect, HWND parent, HMENU menu, HINSTANCE instance, void* param = NULL) {
250 return (window = ::CreateWindowEx(exStyle, classname, title,
251 style, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
252 parent, menu, instance, param)) != NULL;
253 }
254 void setRedraw(bool redraw) {
255 SendMessage(WM_SETREDRAW, redraw);
256 }
257 HFONT getFont()const {
258 return (HFONT) SendMessage(WM_GETFONT);
259 }
260 HFONT setFont(HFONT font, bool redraw) {
261 return (HFONT) SendMessage(WM_SETFONT, (WPARAM) font, redraw);
262 }
263 HICON getIcon(bool large) {
264 return (HICON) SendMessage(WM_GETICON, large, 0);
265 }
266 HICON setIcon(HICON icon, bool large) {
267 return (HICON) SendMessage(WM_SETICON, large, (LPARAM) icon);
268 }
269 long getStyle()const {
270 return GetWindowLong(GWL_STYLE);
271 }
272 long getExStyle()const {
273 return GetWindowLong(GWL_EXSTYLE);
274 }
275 long setStyle(long style) {
276 return SetWindowLong(GWL_STYLE, style);
277 }
278 long setExStyle(long exStyle) {
279 return SetWindowLong(GWL_EXSTYLE, exStyle);
280 }
281 WNDPROC getWndProc()const {
282 return (WNDPROC) GetWindowLong(GWL_WNDPROC);
283 }
284 WNDPROC setWndProc(WNDPROC proc) {
285 return (WNDPROC) SetWindowLong(GWL_WNDPROC, (long) proc);
286 }
287 HWND getOwner()const {
288 return (HWND) GetWindowLong(GWL_HWNDPARENT);
289 }
290 HWND setOwner(HWND owner) {
291 return (HWND) SetWindowLong(GWL_HWNDPARENT, (long) owner);
292 }
293 HWND getChildWindow()const {
294 return GetWindow(GW_CHILD);
295 }
296 HWND getFirstWindow()const {
297 return GetWindow(GW_HWNDFIRST);
298 }
299 HWND getLastWindow()const {
300 return GetWindow(GW_HWNDLAST);
301 }
302 HWND getNextWindow()const {
303 return GetWindow(GW_HWNDNEXT);
304 }
305 HWND getPreviousWindow()const {
306 return GetWindow(GW_HWNDPREV);
307 }
308 HWND getOwnerWindow()const {
309 return GetWindow(GW_OWNER);
310 }
311 #ifndef WS_EX_LAYERED
312 #define WS_EX_LAYERED 0x80000
313 #endif
314 void setAlpha(int alpha) {
315 long exStyle = getExStyle();
316 if ((exStyle & WS_EX_LAYERED) == 0)
317 setExStyle(exStyle | WS_EX_LAYERED);
318 SetLayeredWindowAttributes(alpha, 2);
319 }
320 static const RECT& USEDEFAULT() {
321 static RECT rect = {CW_USEDEFAULT, CW_USEDEFAULT, 0, 0};
322 return rect;
323 }
324 ATOM getClassAtom()const {
325 return (ATOM) GetClassLong(GCW_ATOM);
326 }
327 long getClassExtra()const {
328 return GetClassLong(GCL_CBCLSEXTRA);
329 }
330 long getWindowExtra()const {
331 return GetClassLong(GCL_CBWNDEXTRA);
332 }
333 HBRUSH getBackgroundBrush()const {
334 return (HBRUSH) GetClassLong(GCL_HBRBACKGROUND);
335 }
336 HCURSOR getClassCursor()const {
337 return (HCURSOR) GetClassLong(GCL_HCURSOR);
338 }
339 HICON getClassIcon()const {
340 return (HICON) GetClassLong(GCL_HICON);
341 }
342 HICON getClassSmallIcon()const {
343 return (HICON) GetClassLong(GCL_HICONSM);
344 }
345 HINSTANCE getClassInstance()const {
346 return (HINSTANCE) GetClassLong(GCL_HMODULE);
347 }
348 int getMenuResourceId()const {
349 return GetClassLong(GCL_MENUNAME);
350 }
351 int getClassStyle()const {
352 return GetClassLong(GCL_STYLE);
353 }
354 WNDPROC getClassWindowProc()const {
355 return (WNDPROC) GetClassLong(GCL_WNDPROC);
356 }
357 };
358
359 #pragma comment(lib, "user32.lib")
360 }
361
362 #endif//_YCL_WINDOWS_H_

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26