2 * Copyright 2003 Martin Fuchs
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.
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.
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
25 // Martin Fuchs, 23.07.2003
29 // standard windows headers
30 #define WIN32_LEAN_AND_MEAN
31 #define WIN32_EXTRA_LEAN
40 #include <windowsx.h> // for SelectBrush(), ListBox_SetSel(), SubclassWindow(), ...
43 #include <malloc.h> // for alloca()
49 #define BTNS_BUTTON TBSTYLE_BUTTON //TODO: should be in mingw headers
50 #define BTNS_SEP TBSTYLE_SEP
52 #ifndef TB_HITTEST //missing in mingw headers
53 #define TB_HITTEST (WM_USER+69)
60 #pragma warning(disable: 4786) // disable warnings about too long debug information symbols
63 // STL headers for strings and streams
68 #if _MSC_VER>=1300 // VS.Net
69 #define _NO_COMUTIL //@@
72 #if defined(_MSC_VER) && !defined(_NO_COMUTIL)
74 // COM utility headers
76 using namespace _com_util
;
78 #endif // _MSC_VER && !_NO_COMUTIL
81 #define for if (0) {} else for
84 #define BUFFER_LEN 1024
87 struct CommonControlInit
89 CommonControlInit(DWORD flags
=ICC_LISTVIEW_CLASSES
|ICC_TREEVIEW_CLASSES
|ICC_BAR_CLASSES
|ICC_PROGRESS_CLASS
|ICC_COOL_CLASSES
)
91 INITCOMMONCONTROLSEX icc
= {sizeof(INITCOMMONCONTROLSEX
), flags
};
93 InitCommonControlsEx(&icc
);
104 _old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
109 SetCursor(_old_cursor
);
119 struct ClientRect
: public RECT
121 ClientRect(HWND hwnd
)
123 GetClientRect(hwnd
, this);
126 operator LPRECT() {return this;}
129 struct WindowRect
: public RECT
131 WindowRect(HWND hwnd
)
133 GetWindowRect(hwnd
, this);
136 operator LPRECT() {return this;}
139 struct Point
: public POINT
141 Point(LONG x_
, LONG y_
)
147 // constructor for being used in processing WM_MOUSEMOVE, WM_LBUTTONDOWN, ... messages
150 x
= GET_X_LPARAM(lparam
);
151 y
= GET_Y_LPARAM(lparam
);
154 operator LPPOINT() {return this;}
158 struct FullScreenParameters
160 FullScreenParameters()
173 struct PaintCanvas
: public PAINTSTRUCT
175 PaintCanvas(HWND hwnd
)
178 BeginPaint(hwnd
, this);
183 EndPaint(_hwnd
, this);
186 operator HDC() const {return hdc
;}
194 Canvas(HDC hdc
) : _hdc(hdc
) {}
196 operator HDC() {return _hdc
;}
202 struct WindowCanvas
: public Canvas
204 WindowCanvas(HWND hwnd
)
205 : Canvas(GetDC(hwnd
)), _hwnd(hwnd
) {}
207 ~WindowCanvas() {ReleaseDC(_hwnd
, _hdc
);}
214 // double buffering classes
216 struct MemCanvas
: public Canvas
219 : Canvas(CreateCompatibleDC(hdc
)) {assert(_hdc
);}
221 ~MemCanvas() {DeleteDC(_hdc
);}
224 struct SelectedBitmap
226 SelectedBitmap(HDC hdc
, HBITMAP hbmp
)
227 : _hdc(hdc
), _old_hbmp(SelectBitmap(hdc
, hbmp
)) {}
229 ~SelectedBitmap() {DeleteObject(SelectBitmap(_hdc
, _old_hbmp
));}
236 struct BufferCanvas
: public MemCanvas
238 BufferCanvas(HDC hdc
, int x
, int y
, int w
, int h
)
239 : MemCanvas(hdc
), _hdctarg(hdc
),
240 _x(x
), _y(y
), _w(w
), _h(h
),
241 _bmp(_hdc
, CreateCompatibleBitmap(hdc
, w
, h
)) {}
243 BufferCanvas(HDC hdc
, const RECT
& rect
)
244 : MemCanvas(hdc
), _hdctarg(hdc
),
245 _x(rect
.left
), _y(rect
.top
), _w(rect
.right
-rect
.left
), _h(rect
.bottom
-rect
.top
),
246 _bmp(_hdc
, CreateCompatibleBitmap(hdc
, _w
, _h
)) {}
254 struct BufferedCanvas
: public BufferCanvas
256 BufferedCanvas(HDC hdc
, int x
, int y
, int w
, int h
, DWORD mode
=SRCCOPY
)
257 : BufferCanvas(hdc
, x
, y
, w
, h
), _mode(mode
) {}
259 BufferedCanvas(HDC hdc
, const RECT
& rect
, DWORD mode
=SRCCOPY
)
260 : BufferCanvas(hdc
, rect
), _mode(mode
) {}
262 ~BufferedCanvas() {BitBlt(_hdctarg
, _x
, _y
, _w
, _h
, _hdc
, 0, 0, _mode
);}
267 struct BufferedPaintCanvas
: public PaintCanvas
, public BufferedCanvas
269 BufferedPaintCanvas(HWND hwnd
)
271 BufferedCanvas(PAINTSTRUCT::hdc
, 0, 0, rcPaint
.right
, rcPaint
.bottom
)
275 operator HDC() {return BufferedCanvas::_hdc
;}
281 TextColor(HDC hdc
, COLORREF color
)
282 : _hdc(hdc
), _old_color(SetTextColor(hdc
, color
)) {}
284 ~TextColor() {SetTextColor(_hdc
, _old_color
);}
293 BkMode(HDC hdc
, int bkmode
)
294 : _hdc(hdc
), _old_bkmode(SetBkMode(hdc
, bkmode
)) {}
296 ~BkMode() {SetBkMode(_hdc
, _old_bkmode
);}
300 COLORREF _old_bkmode
;
305 FontSelection(HDC hdc
, HFONT hFont
)
306 : _hdc(hdc
), _old_hFont(SelectFont(hdc
, hFont
)) {}
308 ~FontSelection() {SelectFont(_hdc
, _old_hFont
);}
324 typedef wstring super
;
326 typedef string super
;
330 String(LPCTSTR s
) : super(s
) {}
331 String(const String
& other
) : super(other
) {}
333 String
& operator=(LPCTSTR s
) {assign(s
); return *this;}
334 operator LPCTSTR() const {return c_str();}
338 #endif // __cplusplus
347 #define LONGLONGARG TEXT("I64")
349 #define LONGLONGARG TEXT("L")
355 #define _tcsrchr wcsrchr
357 #define _tcsrchr strrchr
363 #define _stprintf wcsprintf
365 #define _stprintf sprintf
370 #define SetDlgCtrlID(hwnd, id) SetWindowLong(hwnd, GWL_ID, id)
374 extern void display_error(HWND hwnd
, DWORD error
);
376 // convert time_t to WIN32 FILETIME
377 extern BOOL
time_to_filetime(const time_t* t
, FILETIME
* ftime
);
379 // search for windows of a specific classname
380 extern int find_window_class(LPCTSTR classname
);
382 // launch a program or document file
383 extern BOOL
launch_file(HWND hwnd
, LPCTSTR cmd
, UINT nCmdShow
);
385 extern BOOL
launch_fileA(HWND hwnd
, LPSTR cmd
, UINT nCmdShow
);
387 #define launch_fileA launch_file
390 // create a bitmap from an icon
391 extern HBITMAP
create_bitmap_from_icon(HICON hIcon
, HBRUSH hbrush_bkgnd
, HDC hdc_wnd
);