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)
59 #ifndef SFGAO_HIDDEN //SFGAO_GHOSTED wrong defined, SFGAO_HIDDEN missing in mingw headers
60 #define SFGAO_HIDDEN 0x00080000L
62 #define SFGAO_GHOSTED 0x00008000L
70 #pragma warning(disable: 4786) // disable warnings about too long debug information symbols
73 // STL headers for strings and streams
78 #if _MSC_VER>=1300 // VS.Net
79 #define _NO_COMUTIL //@@
82 #if defined(_MSC_VER) && !defined(_NO_COMUTIL)
84 // COM utility headers
86 using namespace _com_util
;
88 #endif // _MSC_VER && !_NO_COMUTIL
91 #define for if (0) {} else for
94 #define BUFFER_LEN 1024
97 struct CommonControlInit
99 CommonControlInit(DWORD flags
=ICC_LISTVIEW_CLASSES
|ICC_TREEVIEW_CLASSES
|ICC_BAR_CLASSES
|ICC_PROGRESS_CLASS
|ICC_COOL_CLASSES
)
101 INITCOMMONCONTROLSEX icc
= {sizeof(INITCOMMONCONTROLSEX
), flags
};
103 InitCommonControlsEx(&icc
);
110 struct WaitCursor
//TODO: integrate with WM_SETCURSOR to enable multithreaded background tasks as program launching
114 _old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
119 SetCursor(_old_cursor
);
129 struct ClientRect
: public RECT
131 ClientRect(HWND hwnd
)
133 GetClientRect(hwnd
, this);
136 operator LPRECT() {return this;}
139 struct WindowRect
: public RECT
141 WindowRect(HWND hwnd
)
143 GetWindowRect(hwnd
, this);
146 operator LPRECT() {return this;}
149 struct Point
: public POINT
151 Point(LONG x_
, LONG y_
)
157 // constructor for being used in processing WM_MOUSEMOVE, WM_LBUTTONDOWN, ... messages
160 x
= GET_X_LPARAM(lparam
);
161 y
= GET_Y_LPARAM(lparam
);
164 operator LPPOINT() {return this;}
168 struct FullScreenParameters
170 FullScreenParameters()
183 struct PaintCanvas
: public PAINTSTRUCT
185 PaintCanvas(HWND hwnd
)
188 BeginPaint(hwnd
, this);
193 EndPaint(_hwnd
, this);
196 operator HDC() const {return hdc
;}
204 Canvas(HDC hdc
) : _hdc(hdc
) {}
206 operator HDC() {return _hdc
;}
212 struct WindowCanvas
: public Canvas
214 WindowCanvas(HWND hwnd
)
215 : Canvas(GetDC(hwnd
)), _hwnd(hwnd
) {}
217 ~WindowCanvas() {ReleaseDC(_hwnd
, _hdc
);}
224 // double buffering classes
226 struct MemCanvas
: public Canvas
229 : Canvas(CreateCompatibleDC(hdc
)) {assert(_hdc
);}
231 ~MemCanvas() {DeleteDC(_hdc
);}
234 struct SelectedBitmap
236 SelectedBitmap(HDC hdc
, HBITMAP hbmp
)
237 : _hdc(hdc
), _old_hbmp(SelectBitmap(hdc
, hbmp
)) {}
239 ~SelectedBitmap() {DeleteObject(SelectBitmap(_hdc
, _old_hbmp
));}
246 struct BufferCanvas
: public MemCanvas
248 BufferCanvas(HDC hdc
, int x
, int y
, int w
, int h
)
249 : MemCanvas(hdc
), _hdctarg(hdc
),
250 _x(x
), _y(y
), _w(w
), _h(h
),
251 _bmp(_hdc
, CreateCompatibleBitmap(hdc
, w
, h
)) {}
253 BufferCanvas(HDC hdc
, const RECT
& rect
)
254 : MemCanvas(hdc
), _hdctarg(hdc
),
255 _x(rect
.left
), _y(rect
.top
), _w(rect
.right
-rect
.left
), _h(rect
.bottom
-rect
.top
),
256 _bmp(_hdc
, CreateCompatibleBitmap(hdc
, _w
, _h
)) {}
264 struct BufferedCanvas
: public BufferCanvas
266 BufferedCanvas(HDC hdc
, int x
, int y
, int w
, int h
, DWORD mode
=SRCCOPY
)
267 : BufferCanvas(hdc
, x
, y
, w
, h
), _mode(mode
) {}
269 BufferedCanvas(HDC hdc
, const RECT
& rect
, DWORD mode
=SRCCOPY
)
270 : BufferCanvas(hdc
, rect
), _mode(mode
) {}
272 ~BufferedCanvas() {BitBlt(_hdctarg
, _x
, _y
, _w
, _h
, _hdc
, 0, 0, _mode
);}
277 struct BufferedPaintCanvas
: public PaintCanvas
, public BufferedCanvas
279 BufferedPaintCanvas(HWND hwnd
)
281 BufferedCanvas(PAINTSTRUCT::hdc
, 0, 0, rcPaint
.right
, rcPaint
.bottom
)
285 operator HDC() {return BufferedCanvas::_hdc
;}
291 TextColor(HDC hdc
, COLORREF color
)
292 : _hdc(hdc
), _old_color(SetTextColor(hdc
, color
)) {}
294 ~TextColor() {SetTextColor(_hdc
, _old_color
);}
303 BkMode(HDC hdc
, int bkmode
)
304 : _hdc(hdc
), _old_bkmode(SetBkMode(hdc
, bkmode
)) {}
306 ~BkMode() {SetBkMode(_hdc
, _old_bkmode
);}
310 COLORREF _old_bkmode
;
315 FontSelection(HDC hdc
, HFONT hFont
)
316 : _hdc(hdc
), _old_hFont(SelectFont(hdc
, hFont
)) {}
318 ~FontSelection() {SelectFont(_hdc
, _old_hFont
);}
325 struct BitmapSelection
327 BitmapSelection(HDC hdc
, HBITMAP hBmp
)
328 : _hdc(hdc
), _old_hBmp(SelectBitmap(hdc
, hBmp
)) {}
330 ~BitmapSelection() {SelectBitmap(_hdc
, _old_hBmp
);}
346 typedef wstring super
;
348 typedef string super
;
352 String(LPCTSTR s
) : super(s
) {}
353 String(const String
& other
) : super(other
) {}
355 String
& operator=(LPCTSTR s
) {assign(s
); return *this;}
356 operator LPCTSTR() const {return c_str();}
360 #endif // __cplusplus
369 #define LONGLONGARG TEXT("I64")
371 #define LONGLONGARG TEXT("L")
377 #define _tcsrchr wcsrchr
379 #define _tcsrchr strrchr
385 #define _stprintf wcsprintf
387 #define _stprintf sprintf
392 #define SetDlgCtrlID(hwnd, id) SetWindowLong(hwnd, GWL_ID, id)
393 #define SetWindowStyle(hwnd, val) (DWORD)SetWindowLong(hwnd, GWL_STYLE, val)
394 #define SetWindowExStyle(h, val) (DWORD)SetWindowLong(hwnd, GWL_EXSTYLE, val)
398 extern void display_error(HWND hwnd
, DWORD error
);
400 // convert time_t to WIN32 FILETIME
401 extern BOOL
time_to_filetime(const time_t* t
, FILETIME
* ftime
);
403 // search for windows of a specific classname
404 extern int find_window_class(LPCTSTR classname
);
406 // create a bitmap from an icon
407 extern HBITMAP
create_bitmap_from_icon(HICON hIcon
, HBRUSH hbrush_bkgnd
, HDC hdc_wnd
);
409 // launch a program or document file
410 extern BOOL
launch_file(HWND hwnd
, LPCTSTR cmd
, UINT nCmdShow
);
412 extern BOOL
launch_fileA(HWND hwnd
, LPSTR cmd
, UINT nCmdShow
);
414 #define launch_fileA launch_file
417 // call an DLL export like rundll32
418 BOOL
RunDLL(HWND hwnd
, LPCTSTR dllname
, LPCSTR procname
, LPCTSTR cmdline
, UINT nCmdShow
);