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 //missing in old mingw headers
50 #define BTNS_SEP TBSTYLE_SEP
51 #define BTNS_NOPREFIX TBSTYLE_NOPREFIX
53 #ifndef TB_HITTEST //missing in mingw headers
54 #define TB_HITTEST (WM_USER+69)
56 #ifndef TB_GETBUTTONINFO //missing in mingw headers
57 #define TB_GETBUTTONINFO (WM_USER+65)
64 #pragma warning(disable: 4786) // disable warnings about too long debug information symbols
67 // STL headers for strings and streams
72 #if _MSC_VER>=1300 // VS.Net
73 #define _NO_COMUTIL //@@
76 #if defined(_MSC_VER) && !defined(_NO_COMUTIL)
78 // COM utility headers
80 using namespace _com_util
;
82 #endif // _MSC_VER && !_NO_COMUTIL
85 #define for if (0) {} else for
88 #define BUFFER_LEN 1024
91 struct CommonControlInit
93 CommonControlInit(DWORD flags
=ICC_LISTVIEW_CLASSES
|ICC_TREEVIEW_CLASSES
|ICC_BAR_CLASSES
|ICC_PROGRESS_CLASS
|ICC_COOL_CLASSES
)
95 INITCOMMONCONTROLSEX icc
= {sizeof(INITCOMMONCONTROLSEX
), flags
};
97 InitCommonControlsEx(&icc
);
108 _old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
113 SetCursor(_old_cursor
);
123 struct ClientRect
: public RECT
125 ClientRect(HWND hwnd
)
127 GetClientRect(hwnd
, this);
130 operator LPRECT() {return this;}
133 struct WindowRect
: public RECT
135 WindowRect(HWND hwnd
)
137 GetWindowRect(hwnd
, this);
140 operator LPRECT() {return this;}
143 struct Point
: public POINT
145 Point(LONG x_
, LONG y_
)
151 // constructor for being used in processing WM_MOUSEMOVE, WM_LBUTTONDOWN, ... messages
154 x
= GET_X_LPARAM(lparam
);
155 y
= GET_Y_LPARAM(lparam
);
158 operator LPPOINT() {return this;}
162 struct FullScreenParameters
164 FullScreenParameters()
177 struct PaintCanvas
: public PAINTSTRUCT
179 PaintCanvas(HWND hwnd
)
182 BeginPaint(hwnd
, this);
187 EndPaint(_hwnd
, this);
190 operator HDC() const {return hdc
;}
198 Canvas(HDC hdc
) : _hdc(hdc
) {}
200 operator HDC() {return _hdc
;}
206 struct WindowCanvas
: public Canvas
208 WindowCanvas(HWND hwnd
)
209 : Canvas(GetDC(hwnd
)), _hwnd(hwnd
) {}
211 ~WindowCanvas() {ReleaseDC(_hwnd
, _hdc
);}
218 // double buffering classes
220 struct MemCanvas
: public Canvas
223 : Canvas(CreateCompatibleDC(hdc
)) {assert(_hdc
);}
225 ~MemCanvas() {DeleteDC(_hdc
);}
228 struct SelectedBitmap
230 SelectedBitmap(HDC hdc
, HBITMAP hbmp
)
231 : _hdc(hdc
), _old_hbmp(SelectBitmap(hdc
, hbmp
)) {}
233 ~SelectedBitmap() {DeleteObject(SelectBitmap(_hdc
, _old_hbmp
));}
240 struct BufferCanvas
: public MemCanvas
242 BufferCanvas(HDC hdc
, int x
, int y
, int w
, int h
)
243 : MemCanvas(hdc
), _hdctarg(hdc
),
244 _x(x
), _y(y
), _w(w
), _h(h
),
245 _bmp(_hdc
, CreateCompatibleBitmap(hdc
, w
, h
)) {}
247 BufferCanvas(HDC hdc
, const RECT
& rect
)
248 : MemCanvas(hdc
), _hdctarg(hdc
),
249 _x(rect
.left
), _y(rect
.top
), _w(rect
.right
-rect
.left
), _h(rect
.bottom
-rect
.top
),
250 _bmp(_hdc
, CreateCompatibleBitmap(hdc
, _w
, _h
)) {}
258 struct BufferedCanvas
: public BufferCanvas
260 BufferedCanvas(HDC hdc
, int x
, int y
, int w
, int h
, DWORD mode
=SRCCOPY
)
261 : BufferCanvas(hdc
, x
, y
, w
, h
), _mode(mode
) {}
263 BufferedCanvas(HDC hdc
, const RECT
& rect
, DWORD mode
=SRCCOPY
)
264 : BufferCanvas(hdc
, rect
), _mode(mode
) {}
266 ~BufferedCanvas() {BitBlt(_hdctarg
, _x
, _y
, _w
, _h
, _hdc
, 0, 0, _mode
);}
271 struct BufferedPaintCanvas
: public PaintCanvas
, public BufferedCanvas
273 BufferedPaintCanvas(HWND hwnd
)
275 BufferedCanvas(PAINTSTRUCT::hdc
, 0, 0, rcPaint
.right
, rcPaint
.bottom
)
279 operator HDC() {return BufferedCanvas::_hdc
;}
285 TextColor(HDC hdc
, COLORREF color
)
286 : _hdc(hdc
), _old_color(SetTextColor(hdc
, color
)) {}
288 ~TextColor() {SetTextColor(_hdc
, _old_color
);}
297 BkMode(HDC hdc
, int bkmode
)
298 : _hdc(hdc
), _old_bkmode(SetBkMode(hdc
, bkmode
)) {}
300 ~BkMode() {SetBkMode(_hdc
, _old_bkmode
);}
304 COLORREF _old_bkmode
;
309 FontSelection(HDC hdc
, HFONT hFont
)
310 : _hdc(hdc
), _old_hFont(SelectFont(hdc
, hFont
)) {}
312 ~FontSelection() {SelectFont(_hdc
, _old_hFont
);}
328 typedef wstring super
;
330 typedef string super
;
334 String(LPCTSTR s
) : super(s
) {}
335 String(const String
& other
) : super(other
) {}
337 String
& operator=(LPCTSTR s
) {assign(s
); return *this;}
338 operator LPCTSTR() const {return c_str();}
342 #endif // __cplusplus
351 #define LONGLONGARG TEXT("I64")
353 #define LONGLONGARG TEXT("L")
359 #define _tcsrchr wcsrchr
361 #define _tcsrchr strrchr
367 #define _stprintf wcsprintf
369 #define _stprintf sprintf
374 #define SetDlgCtrlID(hwnd, id) SetWindowLong(hwnd, GWL_ID, id)
378 extern void display_error(HWND hwnd
, DWORD error
);
380 // convert time_t to WIN32 FILETIME
381 extern BOOL
time_to_filetime(const time_t* t
, FILETIME
* ftime
);
383 // search for windows of a specific classname
384 extern int find_window_class(LPCTSTR classname
);
386 // launch a program or document file
387 extern BOOL
launch_file(HWND hwnd
, LPCTSTR cmd
, UINT nCmdShow
);
389 extern BOOL
launch_fileA(HWND hwnd
, LPSTR cmd
, UINT nCmdShow
);
391 #define launch_fileA launch_file
394 // create a bitmap from an icon
395 extern HBITMAP
create_bitmap_from_icon(HICON hIcon
, HBRUSH hbrush_bkgnd
, HDC hdc_wnd
);