dynamic startmenu widths
[reactos.git] / reactos / subsys / system / explorer / utility / utility.h
1 /*
2 * Copyright 2003 Martin Fuchs
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19
20 //
21 // Explorer clone
22 //
23 // utility.h
24 //
25 // Martin Fuchs, 23.07.2003
26 //
27
28
29 // standard windows headers
30 #define WIN32_LEAN_AND_MEAN
31 #define WIN32_EXTRA_LEAN
32 #include <windows.h>
33
34 // Unicode support
35 #ifdef UNICODE
36 #define _UNICODE
37 #endif
38 #include <tchar.h>
39
40 #include <windowsx.h> // for SelectBrush(), ListBox_SetSel(), SubclassWindow(), ...
41 #include <commctrl.h>
42
43 #include <malloc.h> // for alloca()
44 #include <assert.h>
45 #include <time.h>
46
47
48 #ifndef BTNS_BUTTON
49 #define BTNS_BUTTON TBSTYLE_BUTTON //TODO: should be in mingw headers
50 #define BTNS_SEP TBSTYLE_SEP
51 #endif
52
53
54 #ifdef __cplusplus
55
56 #ifdef _MSC_VER
57 #pragma warning(disable: 4786) // disable warnings about too long debug information symbols
58 #endif
59
60 // STL headers for strings and streams
61 #include <string>
62 #include <iostream>
63 using namespace std;
64
65 #if defined(_MSC_VER) && !defined(_NO_COMUTIL)
66
67 // COM utility headers
68 #include <comdef.h>
69 using namespace _com_util;
70
71 #endif // _MSC_VER && !_NO_COMUTIL
72
73
74 #define for if (0) {} else for
75
76
77 #define BUFFER_LEN 1024
78
79
80 struct CommonControlInit
81 {
82 CommonControlInit(DWORD flags=ICC_LISTVIEW_CLASSES)
83 {
84 INITCOMMONCONTROLSEX icc = {sizeof(INITCOMMONCONTROLSEX), flags};
85
86 InitCommonControlsEx(&icc);
87 }
88 };
89
90
91 struct WaitCursor
92 {
93 WaitCursor()
94 {
95 _old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
96 }
97
98 ~WaitCursor()
99 {
100 SetCursor(_old_cursor);
101 }
102
103 protected:
104 HCURSOR _old_cursor;
105 };
106
107
108 struct ClientRect : public RECT
109 {
110 ClientRect(HWND hwnd)
111 {
112 GetClientRect(hwnd, this);
113 }
114 };
115
116 struct WindowRect : public RECT
117 {
118 WindowRect(HWND hwnd)
119 {
120 GetWindowRect(hwnd, this);
121 }
122 };
123
124
125 struct TextColor
126 {
127 TextColor(HDC hdc, COLORREF color)
128 : _hdc(hdc), _old_color(SetTextColor(hdc, color)) {}
129
130 ~TextColor() {SetTextColor(_hdc, _old_color);}
131
132 protected:
133 HDC _hdc;
134 COLORREF _old_color;
135 };
136
137 struct BkMode
138 {
139 BkMode(HDC hdc, int bkmode)
140 : _hdc(hdc), _old_bkmode(SetBkMode(hdc, bkmode)) {}
141
142 ~BkMode() {SetBkMode(_hdc, _old_bkmode);}
143
144 protected:
145 HDC _hdc;
146 COLORREF _old_bkmode;
147 };
148
149 struct SelectedFont
150 {
151 SelectedFont(HDC hdc, HFONT hFont)
152 : _hdc(hdc), _old_hFont(SelectFont(hdc, hFont)) {}
153
154 ~SelectedFont() {SelectFont(_hdc, _old_hFont);}
155
156 protected:
157 HDC _hdc;
158 HFONT _old_hFont;
159 };
160
161
162 struct FullScreenParameters {
163 FullScreenParameters()
164 : _mode(FALSE)
165 {
166 }
167
168 BOOL _mode;
169 RECT _orgPos;
170 BOOL _wasZoomed;
171 };
172
173
174 struct String
175 #ifdef UNICODE
176 : public wstring
177 #else
178 : public string
179 #endif
180 {
181 #ifdef UNICODE
182 typedef wstring super;
183 #else
184 typedef string super;
185 #endif
186
187 String() {}
188 String(LPCTSTR s) : super(s) {}
189 String(const String& other) : super(other) {}
190
191 String& operator=(LPCTSTR s) {assign(s); return *this;}
192 operator LPCTSTR() const {return c_str();}
193 };
194
195
196 #endif // __cplusplus
197
198
199 #ifdef __cplusplus
200 extern "C" {
201 #endif
202
203
204 #ifdef _MSC_VER
205 #define LONGLONGARG TEXT("I64")
206 #else
207 #define LONGLONGARG TEXT("L")
208 #endif
209
210
211 #ifndef _tcsrchr
212 #ifdef UNICODE
213 #define _tcsrchr wcsrchr
214 #else
215 #define _tcsrchr strrchr
216 #endif
217 #endif
218
219 #ifndef _stprintf
220 #ifdef UNICODE
221 #define _stprintf wcsrintf
222 #else
223 #define _stprintf sprintf
224 #endif
225 #endif
226
227
228 #define SetDlgCtrlID(hwnd, id) SetWindowLong(hwnd, GWL_ID, id)
229
230
231 // display
232 extern void display_error(HWND hwnd, DWORD error);
233
234 // convert time_t to WIN32 FILETIME
235 extern BOOL time_to_filetime(const time_t* t, FILETIME* ftime);
236
237 // search for windows of a specific classname
238 extern int find_window_class(LPCTSTR classname);
239
240 // launch a program or document file
241 extern BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow);
242 #ifdef UNICODE
243 extern BOOL launch_fileA(HWND hwnd, LPSTR cmd, UINT nCmdShow);
244 #else
245 #define launch_fileA launch_file
246 #endif
247
248
249 #ifdef __cplusplus
250 } // extern "C"
251 #endif
252