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 WindowHandle(HWND hwnd
=0)
132 operator HWND() const {return _hwnd
;}
133 HWND
* operator&() {return &_hwnd
;}
140 /// critical section wrapper
142 struct CritSect
: public CRITICAL_SECTION
146 InitializeCriticalSection(this);
151 DeleteCriticalSection(this);
156 /// Lock protects a code section utilizing a critical section
160 Lock(CritSect
& crit_sect
)
161 : _crit_sect(crit_sect
)
163 EnterCriticalSection(&crit_sect
);
168 LeaveCriticalSection(&_crit_sect
);
172 CritSect
& _crit_sect
;
178 struct ClientRect
: public RECT
180 ClientRect(HWND hwnd
)
182 GetClientRect(hwnd
, this);
185 operator LPRECT() {return this;}
188 struct WindowRect
: public RECT
190 WindowRect(HWND hwnd
)
192 GetWindowRect(hwnd
, this);
195 operator LPRECT() {return this;}
198 struct Point
: public POINT
200 Point(LONG x_
, LONG y_
)
206 // constructor for being used in processing WM_MOUSEMOVE, WM_LBUTTONDOWN, ... messages
209 x
= GET_X_LPARAM(lparam
);
210 y
= GET_Y_LPARAM(lparam
);
213 operator LPPOINT() {return this;}
217 struct FullScreenParameters
219 FullScreenParameters()
232 struct PaintCanvas
: public PAINTSTRUCT
234 PaintCanvas(HWND hwnd
)
237 BeginPaint(hwnd
, this);
242 EndPaint(_hwnd
, this);
245 operator HDC() const {return hdc
;}
253 Canvas(HDC hdc
) : _hdc(hdc
) {}
255 operator HDC() {return _hdc
;}
261 struct WindowCanvas
: public Canvas
263 WindowCanvas(HWND hwnd
)
264 : Canvas(GetDC(hwnd
)), _hwnd(hwnd
) {}
266 ~WindowCanvas() {ReleaseDC(_hwnd
, _hdc
);}
273 // double buffering classes
275 struct MemCanvas
: public Canvas
278 : Canvas(CreateCompatibleDC(hdc
)) {assert(_hdc
);}
280 ~MemCanvas() {DeleteDC(_hdc
);}
283 struct SelectedBitmap
285 SelectedBitmap(HDC hdc
, HBITMAP hbmp
)
286 : _hdc(hdc
), _old_hbmp(SelectBitmap(hdc
, hbmp
)) {}
288 ~SelectedBitmap() {DeleteObject(SelectBitmap(_hdc
, _old_hbmp
));}
295 struct BufferCanvas
: public MemCanvas
297 BufferCanvas(HDC hdc
, int x
, int y
, int w
, int h
)
298 : MemCanvas(hdc
), _hdctarg(hdc
),
299 _x(x
), _y(y
), _w(w
), _h(h
),
300 _bmp(_hdc
, CreateCompatibleBitmap(hdc
, w
, h
)) {}
302 BufferCanvas(HDC hdc
, const RECT
& rect
)
303 : MemCanvas(hdc
), _hdctarg(hdc
),
304 _x(rect
.left
), _y(rect
.top
), _w(rect
.right
-rect
.left
), _h(rect
.bottom
-rect
.top
),
305 _bmp(_hdc
, CreateCompatibleBitmap(hdc
, _w
, _h
)) {}
313 struct BufferedCanvas
: public BufferCanvas
315 BufferedCanvas(HDC hdc
, int x
, int y
, int w
, int h
, DWORD mode
=SRCCOPY
)
316 : BufferCanvas(hdc
, x
, y
, w
, h
), _mode(mode
) {}
318 BufferedCanvas(HDC hdc
, const RECT
& rect
, DWORD mode
=SRCCOPY
)
319 : BufferCanvas(hdc
, rect
), _mode(mode
) {}
321 ~BufferedCanvas() {BitBlt(_hdctarg
, _x
, _y
, _w
, _h
, _hdc
, 0, 0, _mode
);}
326 struct BufferedPaintCanvas
: public PaintCanvas
, public BufferedCanvas
328 BufferedPaintCanvas(HWND hwnd
)
330 BufferedCanvas(PAINTSTRUCT::hdc
, 0, 0, rcPaint
.right
, rcPaint
.bottom
)
334 operator HDC() {return BufferedCanvas::_hdc
;}
340 TextColor(HDC hdc
, COLORREF color
)
341 : _hdc(hdc
), _old_color(SetTextColor(hdc
, color
)) {}
343 ~TextColor() {SetTextColor(_hdc
, _old_color
);}
352 BkMode(HDC hdc
, int bkmode
)
353 : _hdc(hdc
), _old_bkmode(SetBkMode(hdc
, bkmode
)) {}
355 ~BkMode() {SetBkMode(_hdc
, _old_bkmode
);}
359 COLORREF _old_bkmode
;
364 FontSelection(HDC hdc
, HFONT hFont
)
365 : _hdc(hdc
), _old_hFont(SelectFont(hdc
, hFont
)) {}
367 ~FontSelection() {SelectFont(_hdc
, _old_hFont
);}
374 struct BitmapSelection
376 BitmapSelection(HDC hdc
, HBITMAP hBmp
)
377 : _hdc(hdc
), _old_hBmp(SelectBitmap(hdc
, hBmp
)) {}
379 ~BitmapSelection() {SelectBitmap(_hdc
, _old_hBmp
);}
395 typedef wstring super
;
397 typedef string super
;
401 String(LPCTSTR s
) : super(s
) {}
402 String(const String
& other
) : super(other
) {}
404 String
& operator=(LPCTSTR s
) {assign(s
); return *this;}
405 operator LPCTSTR() const {return c_str();}
409 #endif // __cplusplus
418 #define LONGLONGARG TEXT("I64")
420 #define LONGLONGARG TEXT("L")
426 #define _tcsrchr wcsrchr
428 #define _tcsrchr strrchr
434 #define _stprintf wcsprintf
436 #define _stprintf sprintf
441 #define SetDlgCtrlID(hwnd, id) SetWindowLong(hwnd, GWL_ID, id)
442 #define SetWindowStyle(hwnd, val) (DWORD)SetWindowLong(hwnd, GWL_STYLE, val)
443 #define SetWindowExStyle(h, val) (DWORD)SetWindowLong(hwnd, GWL_EXSTYLE, val)
447 extern void display_error(HWND hwnd
, DWORD error
);
449 // convert time_t to WIN32 FILETIME
450 extern BOOL
time_to_filetime(const time_t* t
, FILETIME
* ftime
);
452 // search for windows of a specific classname
453 extern int find_window_class(LPCTSTR classname
);
455 // create a bitmap from an icon
456 extern HBITMAP
create_bitmap_from_icon(HICON hIcon
, HBRUSH hbrush_bkgnd
, HDC hdc_wnd
);
458 // launch a program or document file
459 extern BOOL
launch_file(HWND hwnd
, LPCTSTR cmd
, UINT nCmdShow
);
461 extern BOOL
launch_fileA(HWND hwnd
, LPSTR cmd
, UINT nCmdShow
);
463 #define launch_fileA launch_file
466 // call an DLL export like rundll32
467 BOOL
RunDLL(HWND hwnd
, LPCTSTR dllname
, LPCSTR procname
, LPCTSTR cmdline
, UINT nCmdShow
);