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()
45 #include <stdlib.h> // for _MAX_DIR, ...
46 #include <stdio.h> // for sprintf()
51 #define _MAX_FNAME 256
52 #define _MAX_DIR _MAX_FNAME
53 #define _MAX_EXT _MAX_FNAME
59 #define BTNS_BUTTON TBSTYLE_BUTTON //missing in old mingw headers
60 #define BTNS_SEP TBSTYLE_SEP
61 #define BTNS_NOPREFIX TBSTYLE_NOPREFIX
64 #ifndef TB_HITTEST //missing in mingw headers
65 #define TB_HITTEST (WM_USER+69)
68 #ifndef TB_GETBUTTONINFO //missing in mingw headers
69 #define TB_GETBUTTONINFO (WM_USER+65)
73 #ifndef SFGAO_HIDDEN //SFGAO_GHOSTED wrong defined, SFGAO_HIDDEN missing in mingw headers
74 #define SFGAO_HIDDEN 0x00080000L
76 #define SFGAO_GHOSTED 0x00008000L
85 #pragma warning(disable: 4786) // disable warnings about too long debug information symbols
88 // STL headers for strings and streams
93 #if _MSC_VER>=1300 // VS.Net
94 #define _NO_COMUTIL //@@
97 #if defined(_MSC_VER) && !defined(_NO_COMUTIL)
99 // COM utility headers
101 using namespace _com_util
;
103 #endif // _MSC_VER && !_NO_COMUTIL
106 #define for if (0) {} else for
109 #define BUFFER_LEN 1024
112 struct CommonControlInit
114 CommonControlInit(DWORD flags
=ICC_LISTVIEW_CLASSES
|ICC_TREEVIEW_CLASSES
|ICC_BAR_CLASSES
|ICC_PROGRESS_CLASS
|ICC_COOL_CLASSES
)
116 INITCOMMONCONTROLSEX icc
= {sizeof(INITCOMMONCONTROLSEX
), flags
};
118 InitCommonControlsEx(&icc
);
125 struct WaitCursor
//TODO: integrate with WM_SETCURSOR to enable multithreaded background tasks as program launching
129 _old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
134 SetCursor(_old_cursor
);
144 WindowHandle(HWND hwnd
=0)
147 operator HWND() const {return _hwnd
;}
148 HWND
* operator&() {return &_hwnd
;}
155 /// critical section wrapper
157 struct CritSect
: public CRITICAL_SECTION
161 InitializeCriticalSection(this);
166 DeleteCriticalSection(this);
171 /// Lock protects a code section utilizing a critical section
175 Lock(CritSect
& crit_sect
)
176 : _crit_sect(crit_sect
)
178 EnterCriticalSection(&crit_sect
);
183 LeaveCriticalSection(&_crit_sect
);
187 CritSect
& _crit_sect
;
193 struct ClientRect
: public RECT
195 ClientRect(HWND hwnd
)
197 GetClientRect(hwnd
, this);
200 operator LPRECT() {return this;}
203 struct WindowRect
: public RECT
205 WindowRect(HWND hwnd
)
207 GetWindowRect(hwnd
, this);
210 operator LPRECT() {return this;}
213 struct Point
: public POINT
215 Point(LONG x_
, LONG y_
)
221 // constructor for being used in processing WM_MOUSEMOVE, WM_LBUTTONDOWN, ... messages
224 x
= GET_X_LPARAM(lparam
);
225 y
= GET_Y_LPARAM(lparam
);
228 operator LPPOINT() {return this;}
232 struct FullScreenParameters
234 FullScreenParameters()
247 struct PaintCanvas
: public PAINTSTRUCT
249 PaintCanvas(HWND hwnd
)
252 BeginPaint(hwnd
, this);
257 EndPaint(_hwnd
, this);
260 operator HDC() const {return hdc
;}
268 Canvas(HDC hdc
) : _hdc(hdc
) {}
270 operator HDC() {return _hdc
;}
276 struct WindowCanvas
: public Canvas
278 WindowCanvas(HWND hwnd
)
279 : Canvas(GetDC(hwnd
)), _hwnd(hwnd
) {}
281 ~WindowCanvas() {ReleaseDC(_hwnd
, _hdc
);}
288 // double buffering classes
290 struct MemCanvas
: public Canvas
293 : Canvas(CreateCompatibleDC(hdc
)) {assert(_hdc
);}
295 ~MemCanvas() {DeleteDC(_hdc
);}
298 struct SelectedBitmap
300 SelectedBitmap(HDC hdc
, HBITMAP hbmp
)
301 : _hdc(hdc
), _old_hbmp(SelectBitmap(hdc
, hbmp
)) {}
303 ~SelectedBitmap() {DeleteObject(SelectBitmap(_hdc
, _old_hbmp
));}
310 struct BufferCanvas
: public MemCanvas
312 BufferCanvas(HDC hdc
, int x
, int y
, int w
, int h
)
313 : MemCanvas(hdc
), _hdctarg(hdc
),
314 _x(x
), _y(y
), _w(w
), _h(h
),
315 _bmp(_hdc
, CreateCompatibleBitmap(hdc
, w
, h
)) {}
317 BufferCanvas(HDC hdc
, const RECT
& rect
)
318 : MemCanvas(hdc
), _hdctarg(hdc
),
319 _x(rect
.left
), _y(rect
.top
), _w(rect
.right
-rect
.left
), _h(rect
.bottom
-rect
.top
),
320 _bmp(_hdc
, CreateCompatibleBitmap(hdc
, _w
, _h
)) {}
328 struct BufferedCanvas
: public BufferCanvas
330 BufferedCanvas(HDC hdc
, int x
, int y
, int w
, int h
, DWORD mode
=SRCCOPY
)
331 : BufferCanvas(hdc
, x
, y
, w
, h
), _mode(mode
) {}
333 BufferedCanvas(HDC hdc
, const RECT
& rect
, DWORD mode
=SRCCOPY
)
334 : BufferCanvas(hdc
, rect
), _mode(mode
) {}
336 ~BufferedCanvas() {BitBlt(_hdctarg
, _x
, _y
, _w
, _h
, _hdc
, 0, 0, _mode
);}
341 struct BufferedPaintCanvas
: public PaintCanvas
, public BufferedCanvas
343 BufferedPaintCanvas(HWND hwnd
)
345 BufferedCanvas(PAINTSTRUCT::hdc
, 0, 0, rcPaint
.right
, rcPaint
.bottom
)
349 operator HDC() {return BufferedCanvas::_hdc
;}
355 TextColor(HDC hdc
, COLORREF color
)
356 : _hdc(hdc
), _old_color(SetTextColor(hdc
, color
)) {}
358 ~TextColor() {SetTextColor(_hdc
, _old_color
);}
367 BkMode(HDC hdc
, int bkmode
)
368 : _hdc(hdc
), _old_bkmode(SetBkMode(hdc
, bkmode
)) {}
370 ~BkMode() {SetBkMode(_hdc
, _old_bkmode
);}
374 COLORREF _old_bkmode
;
379 FontSelection(HDC hdc
, HFONT hFont
)
380 : _hdc(hdc
), _old_hFont(SelectFont(hdc
, hFont
)) {}
382 ~FontSelection() {SelectFont(_hdc
, _old_hFont
);}
389 struct BitmapSelection
391 BitmapSelection(HDC hdc
, HBITMAP hBmp
)
392 : _hdc(hdc
), _old_hBmp(SelectBitmap(hdc
, hBmp
)) {}
394 ~BitmapSelection() {SelectBitmap(_hdc
, _old_hBmp
);}
410 typedef wstring super
;
412 typedef string super
;
416 String(LPCTSTR s
) : super(s
) {}
417 String(const String
& other
) : super(other
) {}
419 String
& operator=(LPCTSTR s
) {assign(s
); return *this;}
420 operator LPCTSTR() const {return c_str();}
424 #endif // __cplusplus
433 #define LONGLONGARG TEXT("I64")
435 #define LONGLONGARG TEXT("L")
441 #define _tcsrchr wcsrchr
443 #define _tcsrchr strrchr
449 #define _stprintf wcsprintf
451 #define _stprintf sprintf
458 extern void _wsplitpath(const WCHAR
* path
, WCHAR
* drv
, WCHAR
* dir
, WCHAR
* name
, WCHAR
* ext
);
460 extern void _splitpath(const CHAR
* path
, CHAR
* drv
, CHAR
* dir
, CHAR
* name
, CHAR
* ext
);
464 #ifndef FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
465 #define FILE_ATTRIBUTE_ENCRYPTED 0x00000040
466 #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
467 #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
468 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
472 #define SetDlgCtrlID(hwnd, id) SetWindowLong(hwnd, GWL_ID, id)
473 #define SetWindowStyle(hwnd, val) (DWORD)SetWindowLong(hwnd, GWL_STYLE, val)
474 #define SetWindowExStyle(h, val) (DWORD)SetWindowLong(hwnd, GWL_EXSTYLE, val)
478 extern void display_error(HWND hwnd
, DWORD error
);
480 // convert time_t to WIN32 FILETIME
481 extern BOOL
time_to_filetime(const time_t* t
, FILETIME
* ftime
);
483 // search for windows of a specific classname
484 extern int find_window_class(LPCTSTR classname
);
486 // create a bitmap from an icon
487 extern HBITMAP
create_bitmap_from_icon(HICON hIcon
, HBRUSH hbrush_bkgnd
, HDC hdc_wnd
);
489 // launch a program or document file
490 extern BOOL
launch_file(HWND hwnd
, LPCTSTR cmd
, UINT nCmdShow
);
492 extern BOOL
launch_fileA(HWND hwnd
, LPSTR cmd
, UINT nCmdShow
);
494 #define launch_fileA launch_file
497 // call an DLL export like rundll32
498 BOOL
RunDLL(HWND hwnd
, LPCTSTR dllname
, LPCSTR procname
, LPCTSTR cmdline
, UINT nCmdShow
);