OSDN Git Service

forgot to "git add" modified files, so re-commit:
[yamy/yamy.git] / windowstool.h
1 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 // windowstool.h
3
4
5 #ifndef _WINDOWSTOOL_H
6 #  define _WINDOWSTOOL_H
7
8
9 #  include "stringtool.h"
10 #  include <windows.h>
11
12
13 /// instance handle of this application
14 extern HINSTANCE g_hInst;
15
16
17 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 // resource
19
20 /// load resource string
21 extern tstring loadString(UINT i_id);
22
23 /// load small icon resource (it must be deleted by DestroyIcon())
24 extern HICON loadSmallIcon(UINT i_id);
25
26 ///load big icon resource (it must be deleted by DestroyIcon())
27 extern HICON loadBigIcon(UINT i_id);
28
29
30 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31 // window
32
33 /// resize the window (it does not move the window)
34 extern bool resizeWindow(HWND i_hwnd, int i_w, int i_h, bool i_doRepaint);
35
36 /** get rect of the window in client coordinates.
37     @return rect of the window in client coordinates */
38 extern bool getChildWindowRect(HWND i_hwnd, RECT *o_rc);
39
40 /** set small icon to the specified window.
41     @return handle of previous icon or NULL */
42 extern HICON setSmallIcon(HWND i_hwnd, UINT i_id);
43
44 /** set big icon to the specified window.
45     @return handle of previous icon or NULL */
46 extern HICON setBigIcon(HWND i_hwnd, UINT i_id);
47
48 /// remove icon from a window that is set by setSmallIcon
49 extern void unsetSmallIcon(HWND i_hwnd);
50
51 /// remove icon from a window that is set by setBigIcon
52 extern void unsetBigIcon(HWND i_hwnd);
53
54 /// get toplevel (non-child) window
55 extern HWND getToplevelWindow(HWND i_hwnd, bool *io_isMDI);
56
57 /// move window asynchronously
58 extern void asyncMoveWindow(HWND i_hwnd, int i_x, int i_y);
59
60 /// move window asynchronously
61 extern void asyncMoveWindow(HWND i_hwnd, int i_x, int i_y, int i_w, int i_h);
62
63 /// resize asynchronously
64 extern void asyncResize(HWND i_hwnd, int i_w, int i_h);
65
66 /// get dll version
67 extern DWORD getDllVersion(const _TCHAR *i_dllname);
68 #define PACKVERSION(major, minor) MAKELONG(minor, major)
69
70 // workaround of SetForegroundWindow
71 extern bool setForegroundWindow(HWND i_hwnd);
72
73 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74 // dialog
75
76 /// get/set GWL_USERDATA
77 template <class T> inline T getUserData(HWND i_hwnd, T *i_wc)
78 {
79 #ifdef MAYU64
80   return (*i_wc = reinterpret_cast<T>(GetWindowLongPtr(i_hwnd, GWLP_USERDATA)));
81 #else
82   return (*i_wc = reinterpret_cast<T>(GetWindowLong(i_hwnd, GWL_USERDATA)));
83 #endif
84 }
85
86 ///
87 template <class T> inline T setUserData(HWND i_hwnd, T i_wc)
88 {
89 #ifdef MAYU64
90   SetWindowLongPtr(i_hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(i_wc));
91 #else
92   SetWindowLong(i_hwnd, GWL_USERDATA, reinterpret_cast<long>(i_wc));
93 #endif
94   return i_wc;
95 }
96
97
98 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99 // RECT
100
101 ///
102 inline int rcWidth(const RECT *i_rc) { return i_rc->right - i_rc->left; }
103
104 ///
105 inline int rcHeight(const RECT *i_rc) { return i_rc->bottom - i_rc->top; }
106
107 ///
108 inline bool isRectInRect(const RECT *i_rcin, const RECT *i_rcout)
109 {
110   return (i_rcout->left <= i_rcin->left &&
111           i_rcin->right <= i_rcout->right &&
112           i_rcout->top <= i_rcin->top &&
113           i_rcin->bottom <= i_rcout->bottom);
114 }
115
116
117 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
118 // edit control
119
120 /// returns bytes of text
121 extern size_t editGetTextBytes(HWND i_hwnd);
122
123 /// delete a line
124 extern void editDeleteLine(HWND i_hwnd, size_t i_n);
125
126 /// insert text at last
127 extern void editInsertTextAtLast(HWND i_hwnd, const tstring &i_text,
128                                  size_t i_threshold);
129
130
131 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132 // Windows2000/XP specific API
133
134 /// SetLayeredWindowAttributes API
135 typedef BOOL (WINAPI *SetLayeredWindowAttributes_t)
136   (HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
137 extern SetLayeredWindowAttributes_t setLayeredWindowAttributes;
138
139 /// MonitorFromWindow API
140 extern HMONITOR (WINAPI *monitorFromWindow)(HWND hwnd, DWORD dwFlags);
141
142 /// GetMonitorInfo API
143 extern BOOL (WINAPI *getMonitorInfo)(HMONITOR hMonitor, LPMONITORINFO lpmi);
144
145 /// EnumDisplayMonitors API
146 extern BOOL (WINAPI *enumDisplayMonitors)
147   (HDC hdc, LPRECT lprcClip, MONITORENUMPROC lpfnEnum, LPARAM dwData);
148
149
150 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
151 // WindowsXP specific API
152
153 /// WTSRegisterSessionNotification API
154 typedef BOOL (WINAPI *WTSRegisterSessionNotification_t)
155   (HWND hWnd, DWORD dwFlags);
156 extern WTSRegisterSessionNotification_t wtsRegisterSessionNotification;
157
158 /// WTSUnRegisterSessionNotification API
159 typedef BOOL (WINAPI *WTSUnRegisterSessionNotification_t)(HWND hWnd);
160 extern WTSUnRegisterSessionNotification_t wtsUnRegisterSessionNotification;
161
162 /// WTSGetActiveConsoleSessionId API
163 typedef DWORD (WINAPI *WTSGetActiveConsoleSessionId_t)(void);
164 extern WTSGetActiveConsoleSessionId_t wtsGetActiveConsoleSessionId;
165
166 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
167 // Utility
168
169 // PathRemoveFileSpec()
170 tstring pathRemoveFileSpec(const tstring &i_path);
171
172
173 #endif // _WINDOWSTOOL_H