]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
c0089c96 | 2 | // Name: wx/msw/private.h |
a23fd0e1 | 3 | // Purpose: Private declarations: as this header is only included by |
77ffb593 | 4 | // wxWidgets itself, it may contain identifiers which don't start |
a23fd0e1 | 5 | // with "wx". |
2bda0e17 KB |
6 | // Author: Julian Smart |
7 | // Modified by: | |
8 | // Created: 01/02/97 | |
9 | // RCS-ID: $Id$ | |
bbcdf8bc | 10 | // Copyright: (c) Julian Smart |
65571936 | 11 | // Licence: wxWindows licence |
2bda0e17 KB |
12 | ///////////////////////////////////////////////////////////////////////////// |
13 | ||
bbcdf8bc JS |
14 | #ifndef _WX_PRIVATE_H_ |
15 | #define _WX_PRIVATE_H_ | |
2bda0e17 | 16 | |
9ed0d735 | 17 | #include "wx/msw/wrapwin.h" |
2bda0e17 | 18 | |
04ef50df | 19 | #ifdef __WXMICROWIN__ |
b225f659 VZ |
20 | // Extra prototypes and symbols not defined by MicroWindows |
21 | #include "wx/msw/microwin.h" | |
04ef50df JS |
22 | #endif |
23 | ||
3a922bb4 RL |
24 | #include "wx/log.h" |
25 | ||
d66d0500 VZ |
26 | #if wxUSE_GUI |
27 | #include "wx/window.h" | |
28 | #endif // wxUSE_GUI | |
29 | ||
b5dbe15d VS |
30 | class WXDLLIMPEXP_FWD_CORE wxFont; |
31 | class WXDLLIMPEXP_FWD_CORE wxWindow; | |
32 | class WXDLLIMPEXP_FWD_CORE wxWindowBase; | |
2bda0e17 | 33 | |
42e69d6b VZ |
34 | // --------------------------------------------------------------------------- |
35 | // private constants | |
36 | // --------------------------------------------------------------------------- | |
37 | ||
77d8d6cd VZ |
38 | // 260 was taken from windef.h |
39 | #ifndef MAX_PATH | |
40 | #define MAX_PATH 260 | |
41 | #endif | |
42 | ||
a23fd0e1 VZ |
43 | // --------------------------------------------------------------------------- |
44 | // standard icons from the resources | |
45 | // --------------------------------------------------------------------------- | |
2bda0e17 | 46 | |
b568d04f VZ |
47 | #if wxUSE_GUI |
48 | ||
53a2db12 FM |
49 | extern WXDLLIMPEXP_DATA_CORE(HICON) wxSTD_FRAME_ICON; |
50 | extern WXDLLIMPEXP_DATA_CORE(HICON) wxSTD_MDIPARENTFRAME_ICON; | |
51 | extern WXDLLIMPEXP_DATA_CORE(HICON) wxSTD_MDICHILDFRAME_ICON; | |
52 | extern WXDLLIMPEXP_DATA_CORE(HICON) wxDEFAULT_FRAME_ICON; | |
53 | extern WXDLLIMPEXP_DATA_CORE(HICON) wxDEFAULT_MDIPARENTFRAME_ICON; | |
54 | extern WXDLLIMPEXP_DATA_CORE(HICON) wxDEFAULT_MDICHILDFRAME_ICON; | |
55 | extern WXDLLIMPEXP_DATA_CORE(HFONT) wxSTATUS_LINE_FONT; | |
2bda0e17 | 56 | |
b568d04f VZ |
57 | #endif // wxUSE_GUI |
58 | ||
77ec05d4 VZ |
59 | // --------------------------------------------------------------------------- |
60 | // global data | |
61 | // --------------------------------------------------------------------------- | |
62 | ||
63 | extern WXDLLIMPEXP_DATA_BASE(HINSTANCE) wxhInstance; | |
64 | ||
a23fd0e1 | 65 | // --------------------------------------------------------------------------- |
11c7d5b6 | 66 | // define things missing from some compilers' headers |
a23fd0e1 | 67 | // --------------------------------------------------------------------------- |
c455ab93 | 68 | |
7f0586ef | 69 | #if defined(__WXWINCE__) || (defined(__GNUWIN32__) && !wxUSE_NORLANDER_HEADERS) |
01dba85a | 70 | #ifndef ZeroMemory |
11c7d5b6 | 71 | inline void ZeroMemory(void *buf, size_t len) { memset(buf, 0, len); } |
01dba85a | 72 | #endif |
11c7d5b6 VZ |
73 | #endif // old mingw32 |
74 | ||
75 | // this defines a CASTWNDPROC macro which casts a pointer to the type of a | |
76 | // window proc | |
7f0586ef | 77 | #if defined(STRICT) || defined(__GNUC__) |
ebb0781f | 78 | typedef WNDPROC WndProcCast; |
c3b177ae | 79 | #else |
ebb0781f VZ |
80 | typedef FARPROC WndProcCast; |
81 | #endif | |
82 | ||
552a0ebd | 83 | |
ebb0781f | 84 | #define CASTWNDPROC (WndProcCast) |
2bda0e17 | 85 | |
dd54f5d3 | 86 | |
50165591 | 87 | |
a23fd0e1 VZ |
88 | // --------------------------------------------------------------------------- |
89 | // some stuff for old Windows versions (FIXME: what does it do here??) | |
90 | // --------------------------------------------------------------------------- | |
91 | ||
c085e333 | 92 | #if !defined(APIENTRY) // NT defines APIENTRY, 3.x not |
a23fd0e1 | 93 | #define APIENTRY FAR PASCAL |
2bda0e17 | 94 | #endif |
c085e333 | 95 | |
2bda0e17 | 96 | #ifdef __WIN32__ |
a23fd0e1 | 97 | #define _EXPORT |
2bda0e17 | 98 | #else |
a23fd0e1 VZ |
99 | #define _EXPORT _export |
100 | #endif | |
101 | ||
102 | #ifndef __WIN32__ | |
103 | typedef signed short int SHORT; | |
2bda0e17 | 104 | #endif |
c085e333 VZ |
105 | |
106 | #if !defined(__WIN32__) // 3.x uses FARPROC for dialogs | |
27a9bd48 | 107 | #ifndef STRICT |
a23fd0e1 | 108 | #define DLGPROC FARPROC |
2bda0e17 | 109 | #endif |
27a9bd48 | 110 | #endif |
2bda0e17 | 111 | |
2bda0e17 KB |
112 | /* |
113 | * Decide what window classes we're going to use | |
114 | * for this combination of CTl3D/FAFA settings | |
115 | */ | |
c085e333 | 116 | |
223d09f6 | 117 | #define STATIC_CLASS wxT("STATIC") |
2bda0e17 | 118 | #define STATIC_FLAGS (SS_LEFT|WS_CHILD|WS_VISIBLE) |
223d09f6 | 119 | #define CHECK_CLASS wxT("BUTTON") |
2bda0e17 | 120 | #define CHECK_FLAGS (BS_AUTOCHECKBOX|WS_TABSTOP|WS_CHILD) |
078cf5cb | 121 | #define CHECK_IS_FAFA FALSE |
223d09f6 | 122 | #define RADIO_CLASS wxT("BUTTON") |
2bda0e17 KB |
123 | #define RADIO_FLAGS (BS_AUTORADIOBUTTON|WS_CHILD|WS_VISIBLE) |
124 | #define RADIO_SIZE 20 | |
078cf5cb | 125 | #define RADIO_IS_FAFA FALSE |
2bda0e17 | 126 | #define PURE_WINDOWS |
223d09f6 | 127 | #define GROUP_CLASS wxT("BUTTON") |
2bda0e17 KB |
128 | #define GROUP_FLAGS (BS_GROUPBOX|WS_CHILD|WS_VISIBLE) |
129 | ||
130 | /* | |
131 | #define BITCHECK_FLAGS (FB_BITMAP|FC_BUTTONDRAW|FC_DEFAULT|WS_VISIBLE) | |
132 | #define BITRADIO_FLAGS (FC_BUTTONDRAW|FB_BITMAP|FC_RADIO|WS_CHILD|WS_VISIBLE) | |
133 | */ | |
134 | ||
a23fd0e1 VZ |
135 | // --------------------------------------------------------------------------- |
136 | // misc macros | |
137 | // --------------------------------------------------------------------------- | |
138 | ||
2bda0e17 | 139 | #define MEANING_CHARACTER '0' |
5d368213 | 140 | #define DEFAULT_ITEM_WIDTH 100 |
2bda0e17 | 141 | #define DEFAULT_ITEM_HEIGHT 80 |
1c4a764c VZ |
142 | |
143 | // Scale font to get edit control height | |
f6bcfd97 BP |
144 | //#define EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) (3*(cy)/2) |
145 | #define EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) (cy+8) | |
2bda0e17 KB |
146 | |
147 | // Generic subclass proc, for panel item moving/sizing and intercept | |
148 | // EDIT control VK_RETURN messages | |
149 | extern LONG APIENTRY _EXPORT | |
150 | wxSubclassedGenericControlProc(WXHWND hWnd, WXUINT message, WXWPARAM wParam, WXLPARAM lParam); | |
151 | ||
11c7d5b6 VZ |
152 | // --------------------------------------------------------------------------- |
153 | // useful macros and functions | |
154 | // --------------------------------------------------------------------------- | |
155 | ||
156 | // a wrapper macro for ZeroMemory() | |
04ef50df | 157 | #if defined(__WIN32__) && !defined(__WXMICROWIN__) |
11c7d5b6 | 158 | #define wxZeroMemory(obj) ::ZeroMemory(&obj, sizeof(obj)) |
0e528b99 JS |
159 | #else |
160 | #define wxZeroMemory(obj) memset((void*) & obj, 0, sizeof(obj)) | |
161 | #endif | |
11c7d5b6 | 162 | |
18a1516c MW |
163 | // This one is a macro so that it can be tested with #ifdef, it will be |
164 | // undefined if it cannot be implemented for a given compiler. | |
165 | // Vc++, bcc, dmc, ow, mingw, codewarrior (and rsxnt) have _get_osfhandle. | |
166 | // Cygwin has get_osfhandle. Others are currently unknown, e.g. Salford, | |
167 | // Intel, Visual Age. | |
168 | #if defined(__WXWINCE__) | |
169 | #define wxGetOSFHandle(fd) ((HANDLE)fd) | |
7d45ec4a | 170 | #define wxOpenOSFHandle(h, flags) ((int)wxPtrToUInt(h)) |
18a1516c MW |
171 | #elif defined(__CYGWIN__) |
172 | #define wxGetOSFHandle(fd) ((HANDLE)get_osfhandle(fd)) | |
173 | #elif defined(__VISUALC__) \ | |
174 | || defined(__BORLANDC__) \ | |
18a1516c | 175 | || defined(__DMC__) \ |
74fe6751 | 176 | || defined(__WATCOMC__) \ |
8df9a8a0 | 177 | || defined(__MINGW32__) \ |
18a1516c MW |
178 | || (defined(__MWERKS__) && defined(__MSL__)) |
179 | #define wxGetOSFHandle(fd) ((HANDLE)_get_osfhandle(fd)) | |
7d45ec4a MW |
180 | #define wxOpenOSFHandle(h, flags) (_open_osfhandle(wxPtrToUInt(h), flags)) |
181 | #define wx_fdopen _fdopen | |
18a1516c MW |
182 | #endif |
183 | ||
0cdd4e19 VZ |
184 | // close the handle in the class dtor |
185 | class AutoHANDLE | |
186 | { | |
187 | public: | |
188 | wxEXPLICIT AutoHANDLE(HANDLE handle) : m_handle(handle) { } | |
189 | ||
190 | bool IsOk() const { return m_handle != INVALID_HANDLE_VALUE; } | |
191 | operator HANDLE() const { return m_handle; } | |
192 | ||
193 | ~AutoHANDLE() { if ( IsOk() ) ::CloseHandle(m_handle); } | |
194 | ||
195 | protected: | |
196 | HANDLE m_handle; | |
197 | }; | |
198 | ||
d1e4a818 VZ |
199 | // a template to make initializing Windows styructs less painful: it zeroes all |
200 | // the struct fields and also sets cbSize member to the correct value (and so | |
201 | // can be only used with structures which have this member...) | |
202 | template <class T> | |
203 | struct WinStruct : public T | |
204 | { | |
205 | WinStruct() | |
206 | { | |
207 | ::ZeroMemory(this, sizeof(T)); | |
208 | ||
209 | // explicit qualification is required here for this to be valid C++ | |
210 | this->cbSize = sizeof(T); | |
211 | } | |
212 | }; | |
213 | ||
214 | ||
f6bcfd97 BP |
215 | #if wxUSE_GUI |
216 | ||
c0089c96 WS |
217 | #include "wx/gdicmn.h" |
218 | #include "wx/colour.h" | |
01dba85a | 219 | |
11c7d5b6 VZ |
220 | // make conversion from wxColour and COLORREF a bit less painful |
221 | inline COLORREF wxColourToRGB(const wxColour& c) | |
4ab861e5 VZ |
222 | { |
223 | return RGB(c.Red(), c.Green(), c.Blue()); | |
224 | } | |
225 | ||
226 | inline COLORREF wxColourToPalRGB(const wxColour& c) | |
11c7d5b6 | 227 | { |
19193a2c | 228 | return PALETTERGB(c.Red(), c.Green(), c.Blue()); |
11c7d5b6 VZ |
229 | } |
230 | ||
d23c8ba2 VZ |
231 | inline wxColour wxRGBToColour(COLORREF rgb) |
232 | { | |
233 | return wxColour(GetRValue(rgb), GetGValue(rgb), GetBValue(rgb)); | |
234 | } | |
235 | ||
11c7d5b6 VZ |
236 | inline void wxRGBToColour(wxColour& c, COLORREF rgb) |
237 | { | |
238 | c.Set(GetRValue(rgb), GetGValue(rgb), GetBValue(rgb)); | |
239 | } | |
240 | ||
90c1530a VZ |
241 | // get the standard colour map for some standard colours - see comment in this |
242 | // function to understand why is it needed and when should it be used | |
243 | // | |
244 | // it returns a wxCOLORMAP (can't use COLORMAP itself here as comctl32.dll | |
245 | // might be not included/available) array of size wxSTD_COLOUR_MAX | |
246 | // | |
247 | // NB: if you change these colours, update wxBITMAP_STD_COLOURS in the | |
248 | // resources as well: it must have the same number of pixels! | |
249 | enum wxSTD_COLOUR | |
250 | { | |
251 | wxSTD_COL_BTNTEXT, | |
252 | wxSTD_COL_BTNSHADOW, | |
253 | wxSTD_COL_BTNFACE, | |
254 | wxSTD_COL_BTNHIGHLIGHT, | |
57e075e9 | 255 | wxSTD_COL_MAX |
90c1530a VZ |
256 | }; |
257 | ||
53a2db12 | 258 | struct WXDLLIMPEXP_CORE wxCOLORMAP |
90c1530a VZ |
259 | { |
260 | COLORREF from, to; | |
261 | }; | |
262 | ||
263 | // this function is implemented in src/msw/window.cpp | |
264 | extern wxCOLORMAP *wxGetStdColourMap(); | |
265 | ||
9688700c | 266 | // create a wxRect from Windows RECT |
8704b366 | 267 | inline wxRect wxRectFromRECT(const RECT& rc) |
9688700c | 268 | { |
8704b366 | 269 | return wxRect(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); |
9688700c VZ |
270 | } |
271 | ||
ed791986 | 272 | // copy Windows RECT to our wxRect |
8704b366 | 273 | inline void wxCopyRECTToRect(const RECT& rc, wxRect& rect) |
ed791986 | 274 | { |
8704b366 VZ |
275 | rect = wxRectFromRECT(rc); |
276 | } | |
277 | ||
278 | // and vice versa | |
279 | inline void wxCopyRectToRECT(const wxRect& rect, RECT& rc) | |
280 | { | |
281 | // note that we don't use wxRect::GetRight() as it is one of compared to | |
282 | // wxRectFromRECT() above | |
283 | rc.top = rect.y; | |
284 | rc.left = rect.x; | |
285 | rc.right = rect.x + rect.width; | |
286 | rc.bottom = rect.y + rect.height; | |
ed791986 VZ |
287 | } |
288 | ||
d9317fd4 VZ |
289 | // translations between HIMETRIC units (which OLE likes) and pixels (which are |
290 | // liked by all the others) - implemented in msw/utilsexc.cpp | |
291 | extern void HIMETRICToPixel(LONG *x, LONG *y); | |
292 | extern void PixelToHIMETRIC(LONG *x, LONG *y); | |
293 | ||
77ffb593 | 294 | // Windows convention of the mask is opposed to the wxWidgets one, so we need |
4b7f2165 VZ |
295 | // to invert the mask each time we pass one/get one to/from Windows |
296 | extern HBITMAP wxInvertMask(HBITMAP hbmpMask, int w = 0, int h = 0); | |
297 | ||
211b54b1 VZ |
298 | // Creates an icon or cursor depending from a bitmap |
299 | // | |
300 | // The bitmap must be valid and it should have a mask. If it doesn't, a default | |
301 | // mask is created using light grey as the transparent colour. | |
302 | extern HICON wxBitmapToHICON(const wxBitmap& bmp); | |
303 | ||
304 | // Same requirments as above apply and the bitmap must also have the correct | |
305 | // size. | |
306 | extern | |
307 | HCURSOR wxBitmapToHCURSOR(const wxBitmap& bmp, int hotSpotX, int hotSpotY); | |
308 | ||
8614c467 VZ |
309 | // get (x, y) from DWORD - notice that HI/LOWORD can *not* be used because they |
310 | // will fail on system with multiple monitors where the coords may be negative | |
311 | // | |
312 | // these macros are standard now (Win98) but some older headers don't have them | |
313 | #ifndef GET_X_LPARAM | |
314 | #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp)) | |
315 | #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp)) | |
316 | #endif // GET_X_LPARAM | |
317 | ||
6719c06a VZ |
318 | // get the current state of SHIFT/CTRL/ALT keys |
319 | inline bool wxIsModifierDown(int vk) | |
a95e38c0 | 320 | { |
6719c06a | 321 | // GetKeyState() returns different negative values on WinME and WinNT, |
1fdf858b | 322 | // so simply test for negative value. |
6719c06a VZ |
323 | return ::GetKeyState(vk) < 0; |
324 | } | |
325 | ||
326 | inline bool wxIsShiftDown() | |
327 | { | |
328 | return wxIsModifierDown(VK_SHIFT); | |
a95e38c0 VZ |
329 | } |
330 | ||
1f80a703 | 331 | inline bool wxIsCtrlDown() |
a95e38c0 | 332 | { |
6719c06a VZ |
333 | return wxIsModifierDown(VK_CONTROL); |
334 | } | |
335 | ||
336 | inline bool wxIsAltDown() | |
337 | { | |
338 | return wxIsModifierDown(VK_MENU); | |
339 | } | |
340 | ||
341 | inline bool wxIsAnyModifierDown() | |
342 | { | |
343 | return wxIsShiftDown() || wxIsCtrlDown() || wxIsAltDown(); | |
a95e38c0 VZ |
344 | } |
345 | ||
82c9f85c VZ |
346 | // wrapper around GetWindowRect() and GetClientRect() APIs doing error checking |
347 | // for Win32 | |
348 | inline RECT wxGetWindowRect(HWND hwnd) | |
349 | { | |
350 | RECT rect; | |
3a5bcc4d | 351 | |
82c9f85c | 352 | if ( !::GetWindowRect(hwnd, &rect) ) |
82c9f85c | 353 | wxLogLastError(_T("GetWindowRect")); |
82c9f85c VZ |
354 | |
355 | return rect; | |
356 | } | |
357 | ||
358 | inline RECT wxGetClientRect(HWND hwnd) | |
359 | { | |
360 | RECT rect; | |
3a5bcc4d | 361 | |
82c9f85c | 362 | if ( !::GetClientRect(hwnd, &rect) ) |
82c9f85c | 363 | wxLogLastError(_T("GetClientRect")); |
82c9f85c VZ |
364 | |
365 | return rect; | |
366 | } | |
367 | ||
6d167489 VZ |
368 | // --------------------------------------------------------------------------- |
369 | // small helper classes | |
370 | // --------------------------------------------------------------------------- | |
371 | ||
372 | // create an instance of this class and use it as the HDC for screen, will | |
373 | // automatically release the DC going out of scope | |
374 | class ScreenHDC | |
375 | { | |
376 | public: | |
091225b4 VZ |
377 | ScreenHDC() { m_hdc = ::GetDC(NULL); } |
378 | ~ScreenHDC() { ::ReleaseDC(NULL, m_hdc); } | |
379 | ||
380 | operator HDC() const { return m_hdc; } | |
381 | ||
382 | private: | |
383 | HDC m_hdc; | |
22f3361e VZ |
384 | |
385 | DECLARE_NO_COPY_CLASS(ScreenHDC) | |
091225b4 VZ |
386 | }; |
387 | ||
2ff56383 VZ |
388 | // the same as ScreenHDC but for window DCs |
389 | class WindowHDC | |
390 | { | |
391 | public: | |
392 | WindowHDC(HWND hwnd) { m_hdc = ::GetDC(m_hwnd = hwnd); } | |
393 | ~WindowHDC() { ::ReleaseDC(m_hwnd, m_hdc); } | |
394 | ||
395 | operator HDC() const { return m_hdc; } | |
396 | ||
397 | private: | |
398 | HWND m_hwnd; | |
399 | HDC m_hdc; | |
400 | ||
401 | DECLARE_NO_COPY_CLASS(WindowHDC) | |
402 | }; | |
403 | ||
697b08a8 VZ |
404 | // the same as ScreenHDC but for memory DCs: creates the HDC compatible with |
405 | // the given one (screen by default) in ctor and destroys it in dtor | |
091225b4 VZ |
406 | class MemoryHDC |
407 | { | |
408 | public: | |
9cf743aa | 409 | MemoryHDC(HDC hdc = 0) { m_hdc = ::CreateCompatibleDC(hdc); } |
697b08a8 | 410 | ~MemoryHDC() { ::DeleteDC(m_hdc); } |
091225b4 VZ |
411 | |
412 | operator HDC() const { return m_hdc; } | |
6d167489 VZ |
413 | |
414 | private: | |
415 | HDC m_hdc; | |
22f3361e VZ |
416 | |
417 | DECLARE_NO_COPY_CLASS(MemoryHDC) | |
6d167489 VZ |
418 | }; |
419 | ||
091225b4 VZ |
420 | // a class which selects a GDI object into a DC in its ctor and deselects in |
421 | // dtor | |
422 | class SelectInHDC | |
423 | { | |
6969c2c3 VZ |
424 | private: |
425 | void DoInit(HGDIOBJ hgdiobj) { m_hgdiobj = ::SelectObject(m_hdc, hgdiobj); } | |
426 | ||
091225b4 | 427 | public: |
6969c2c3 VZ |
428 | SelectInHDC() : m_hdc(NULL) { } |
429 | SelectInHDC(HDC hdc, HGDIOBJ hgdiobj) : m_hdc(hdc) { DoInit(hgdiobj); } | |
430 | ||
431 | void Init(HDC hdc, HGDIOBJ hgdiobj) | |
432 | { | |
433 | wxASSERT_MSG( !m_hdc, _T("initializing twice?") ); | |
434 | ||
435 | m_hdc = hdc; | |
091225b4 | 436 | |
6969c2c3 VZ |
437 | DoInit(hgdiobj); |
438 | } | |
091225b4 | 439 | |
6969c2c3 VZ |
440 | ~SelectInHDC() { if ( m_hdc ) ::SelectObject(m_hdc, m_hgdiobj); } |
441 | ||
442 | // return true if the object was successfully selected | |
443 | operator bool() const { return m_hgdiobj != 0; } | |
091225b4 VZ |
444 | |
445 | private: | |
6969c2c3 VZ |
446 | HDC m_hdc; |
447 | HGDIOBJ m_hgdiobj; | |
22f3361e | 448 | |
6969c2c3 | 449 | DECLARE_NO_COPY_CLASS(SelectInHDC) |
51a2a728 VZ |
450 | }; |
451 | ||
a27cbf44 VZ |
452 | // a class which cleans up any GDI object |
453 | class AutoGDIObject | |
454 | { | |
455 | protected: | |
6969c2c3 | 456 | AutoGDIObject() { m_gdiobj = NULL; } |
a27cbf44 VZ |
457 | AutoGDIObject(HGDIOBJ gdiobj) : m_gdiobj(gdiobj) { } |
458 | ~AutoGDIObject() { if ( m_gdiobj ) ::DeleteObject(m_gdiobj); } | |
459 | ||
6969c2c3 VZ |
460 | void InitGdiobj(HGDIOBJ gdiobj) |
461 | { | |
462 | wxASSERT_MSG( !m_gdiobj, _T("initializing twice?") ); | |
463 | ||
464 | m_gdiobj = gdiobj; | |
465 | } | |
466 | ||
a27cbf44 VZ |
467 | HGDIOBJ GetObject() const { return m_gdiobj; } |
468 | ||
469 | private: | |
470 | HGDIOBJ m_gdiobj; | |
471 | }; | |
472 | ||
cf831d8e VZ |
473 | // TODO: all this asks for using a AutoHandler<T, CreateFunc> template... |
474 | ||
6969c2c3 | 475 | // a class for temporary brushes |
cf831d8e VZ |
476 | class AutoHBRUSH : private AutoGDIObject |
477 | { | |
478 | public: | |
479 | AutoHBRUSH(COLORREF col) | |
480 | : AutoGDIObject(::CreateSolidBrush(col)) { } | |
481 | ||
482 | operator HBRUSH() const { return (HBRUSH)GetObject(); } | |
483 | }; | |
484 | ||
6969c2c3 VZ |
485 | // a class for temporary fonts |
486 | class AutoHFONT : private AutoGDIObject | |
487 | { | |
488 | private: | |
489 | public: | |
490 | AutoHFONT() | |
491 | : AutoGDIObject() { } | |
492 | ||
493 | AutoHFONT(const LOGFONT& lf) | |
494 | : AutoGDIObject(::CreateFontIndirect(&lf)) { } | |
495 | ||
496 | void Init(const LOGFONT& lf) { InitGdiobj(::CreateFontIndirect(&lf)); } | |
497 | ||
498 | operator HFONT() const { return (HFONT)GetObject(); } | |
499 | }; | |
500 | ||
cf831d8e VZ |
501 | // a class for temporary pens |
502 | class AutoHPEN : private AutoGDIObject | |
503 | { | |
504 | public: | |
505 | AutoHPEN(COLORREF col) | |
506 | : AutoGDIObject(::CreatePen(PS_SOLID, 0, col)) { } | |
507 | ||
508 | operator HPEN() const { return (HPEN)GetObject(); } | |
509 | }; | |
510 | ||
511 | // classes for temporary bitmaps | |
512 | class AutoHBITMAP : private AutoGDIObject | |
513 | { | |
514 | public: | |
515 | AutoHBITMAP(HBITMAP hbmp) : AutoGDIObject(hbmp) { } | |
516 | ||
517 | operator HBITMAP() const { return (HBITMAP)GetObject(); } | |
518 | }; | |
519 | ||
520 | class CompatibleBitmap : public AutoHBITMAP | |
978bb48f VZ |
521 | { |
522 | public: | |
523 | CompatibleBitmap(HDC hdc, int w, int h) | |
cf831d8e | 524 | : AutoHBITMAP(::CreateCompatibleBitmap(hdc, w, h)) |
978bb48f | 525 | { |
978bb48f | 526 | } |
cf831d8e | 527 | }; |
978bb48f | 528 | |
cf831d8e VZ |
529 | class MonoBitmap : public AutoHBITMAP |
530 | { | |
531 | public: | |
532 | MonoBitmap(int w, int h) | |
533 | : AutoHBITMAP(::CreateBitmap(w, h, 1, 1, 0)) | |
534 | { | |
535 | } | |
a27cbf44 | 536 | }; |
978bb48f | 537 | |
a27cbf44 VZ |
538 | // class automatically destroys the region object |
539 | class AutoHRGN : private AutoGDIObject | |
540 | { | |
541 | public: | |
542 | AutoHRGN(HRGN hrgn) : AutoGDIObject(hrgn) { } | |
978bb48f | 543 | |
a27cbf44 | 544 | operator HRGN() const { return (HRGN)GetObject(); } |
978bb48f VZ |
545 | }; |
546 | ||
a1372ae2 VZ |
547 | // class sets the specified clipping region during its life time |
548 | class HDCClipper | |
549 | { | |
550 | public: | |
551 | HDCClipper(HDC hdc, HRGN hrgn) | |
552 | : m_hdc(hdc) | |
553 | { | |
554 | if ( !::SelectClipRgn(hdc, hrgn) ) | |
555 | wxLogLastError(_T("SelectClipRgn")); | |
556 | } | |
557 | ||
558 | ~HDCClipper() | |
559 | { | |
560 | ::SelectClipRgn(m_hdc, NULL); | |
561 | } | |
562 | ||
563 | private: | |
564 | HDC m_hdc; | |
565 | ||
566 | DECLARE_NO_COPY_CLASS(HDCClipper) | |
567 | }; | |
568 | ||
566b7f7b VZ |
569 | // set the given map mode for the life time of this object |
570 | // | |
571 | // NB: SetMapMode() is not supported by CE so we also define a helper macro | |
572 | // to avoid using it there | |
573 | #ifdef __WXWINCE__ | |
574 | #define wxCHANGE_HDC_MAP_MODE(hdc, mm) | |
575 | #else // !__WXWINCE__ | |
576 | class HDCMapModeChanger | |
577 | { | |
578 | public: | |
579 | HDCMapModeChanger(HDC hdc, int mm) | |
580 | : m_hdc(hdc) | |
581 | { | |
582 | m_modeOld = ::SetMapMode(hdc, mm); | |
583 | if ( !m_modeOld ) | |
584 | wxLogLastError(_T("SelectClipRgn")); | |
585 | } | |
586 | ||
587 | ~HDCMapModeChanger() | |
588 | { | |
589 | if ( m_modeOld ) | |
590 | ::SetMapMode(m_hdc, m_modeOld); | |
591 | } | |
592 | ||
593 | private: | |
594 | HDC m_hdc; | |
595 | int m_modeOld; | |
596 | ||
597 | DECLARE_NO_COPY_CLASS(HDCMapModeChanger) | |
598 | }; | |
599 | ||
600 | #define wxCHANGE_HDC_MAP_MODE(hdc, mm) \ | |
601 | HDCMapModeChanger wxMAKE_UNIQUE_NAME(wxHDCMapModeChanger)(hdc, mm) | |
602 | #endif // __WXWINCE__/!__WXWINCE__ | |
603 | ||
82d1a195 | 604 | // smart pointer using GlobalAlloc/GlobalFree() |
2be57a51 VZ |
605 | class GlobalPtr |
606 | { | |
607 | public: | |
6fa6d659 VZ |
608 | // default ctor, call Init() later |
609 | GlobalPtr() | |
610 | { | |
611 | m_hGlobal = NULL; | |
612 | } | |
613 | ||
2be57a51 | 614 | // allocates a block of given size |
6fa6d659 | 615 | void Init(size_t size, unsigned flags = GMEM_MOVEABLE) |
2be57a51 VZ |
616 | { |
617 | m_hGlobal = ::GlobalAlloc(flags, size); | |
618 | if ( !m_hGlobal ) | |
619 | wxLogLastError(_T("GlobalAlloc")); | |
620 | } | |
621 | ||
6fa6d659 VZ |
622 | GlobalPtr(size_t size, unsigned flags = GMEM_MOVEABLE) |
623 | { | |
624 | Init(size, flags); | |
625 | } | |
626 | ||
2be57a51 VZ |
627 | ~GlobalPtr() |
628 | { | |
629 | if ( m_hGlobal && ::GlobalFree(m_hGlobal) ) | |
630 | wxLogLastError(_T("GlobalFree")); | |
631 | } | |
632 | ||
633 | // implicit conversion | |
634 | operator HGLOBAL() const { return m_hGlobal; } | |
635 | ||
636 | private: | |
637 | HGLOBAL m_hGlobal; | |
638 | ||
639 | DECLARE_NO_COPY_CLASS(GlobalPtr) | |
640 | }; | |
641 | ||
51a2a728 VZ |
642 | // when working with global pointers (which is unfortunately still necessary |
643 | // sometimes, e.g. for clipboard) it is important to unlock them exactly as | |
644 | // many times as we lock them which just asks for using a "smart lock" class | |
0645e2b9 | 645 | class GlobalPtrLock |
51a2a728 VZ |
646 | { |
647 | public: | |
2d2b68ba VZ |
648 | // default ctor, use Init() later -- should only be used if the HGLOBAL can |
649 | // be NULL (in which case Init() shouldn't be called) | |
650 | GlobalPtrLock() | |
51a2a728 | 651 | { |
2d2b68ba VZ |
652 | m_hGlobal = NULL; |
653 | m_ptr = NULL; | |
654 | } | |
655 | ||
656 | // initialize the object, may be only called if we were created using the | |
657 | // default ctor; HGLOBAL must not be NULL | |
658 | void Init(HGLOBAL hGlobal) | |
659 | { | |
660 | m_hGlobal = hGlobal; | |
82d1a195 VZ |
661 | |
662 | // NB: GlobalLock() is a macro, not a function, hence don't use the | |
663 | // global scope operator with it (and neither with GlobalUnlock()) | |
664 | m_ptr = GlobalLock(hGlobal); | |
51a2a728 | 665 | if ( !m_ptr ) |
51a2a728 | 666 | wxLogLastError(_T("GlobalLock")); |
51a2a728 VZ |
667 | } |
668 | ||
2d2b68ba VZ |
669 | // initialize the object, HGLOBAL must not be NULL |
670 | GlobalPtrLock(HGLOBAL hGlobal) | |
671 | { | |
672 | Init(hGlobal); | |
673 | } | |
674 | ||
0645e2b9 | 675 | ~GlobalPtrLock() |
51a2a728 | 676 | { |
82d1a195 | 677 | if ( m_hGlobal && !GlobalUnlock(m_hGlobal) ) |
51a2a728 VZ |
678 | { |
679 | #ifdef __WXDEBUG__ | |
680 | // this might happen simply because the block became unlocked | |
681 | DWORD dwLastError = ::GetLastError(); | |
682 | if ( dwLastError != NO_ERROR ) | |
683 | { | |
684 | wxLogApiError(_T("GlobalUnlock"), dwLastError); | |
685 | } | |
686 | #endif // __WXDEBUG__ | |
687 | } | |
688 | } | |
689 | ||
2d2b68ba | 690 | void *Get() const { return m_ptr; } |
51a2a728 VZ |
691 | operator void *() const { return m_ptr; } |
692 | ||
693 | private: | |
694 | HGLOBAL m_hGlobal; | |
695 | void *m_ptr; | |
696 | ||
0645e2b9 | 697 | DECLARE_NO_COPY_CLASS(GlobalPtrLock) |
091225b4 VZ |
698 | }; |
699 | ||
77ec05d4 VZ |
700 | // register the class when it is first needed and unregister it in dtor |
701 | class ClassRegistrar | |
702 | { | |
703 | public: | |
704 | // ctor doesn't register the class, call Initialize() for this | |
705 | ClassRegistrar() { m_registered = -1; } | |
706 | ||
707 | // return true if the class is already registered | |
708 | bool IsInitialized() const { return m_registered != -1; } | |
709 | ||
710 | // return true if the class had been already registered | |
711 | bool IsRegistered() const { return m_registered == 1; } | |
712 | ||
713 | // try to register the class if not done yet, return true on success | |
714 | bool Register(const WNDCLASS& wc) | |
715 | { | |
716 | // we should only be called if we hadn't been initialized yet | |
717 | wxASSERT_MSG( m_registered == -1, | |
718 | _T("calling ClassRegistrar::Register() twice?") ); | |
719 | ||
720 | m_registered = ::RegisterClass(&wc) ? 1 : 0; | |
721 | if ( !IsRegistered() ) | |
722 | { | |
723 | wxLogLastError(_T("RegisterClassEx()")); | |
724 | } | |
725 | else | |
726 | { | |
727 | m_clsname = wc.lpszClassName; | |
728 | } | |
729 | ||
730 | return m_registered == 1; | |
731 | } | |
732 | ||
733 | // get the name of the registered class (returns empty string if not | |
734 | // registered) | |
735 | const wxString& GetName() const { return m_clsname; } | |
736 | ||
737 | // unregister the class if it had been registered | |
738 | ~ClassRegistrar() | |
739 | { | |
740 | if ( IsRegistered() ) | |
741 | { | |
e0a050e3 | 742 | if ( !::UnregisterClass(m_clsname.wx_str(), wxhInstance) ) |
77ec05d4 VZ |
743 | { |
744 | wxLogLastError(_T("UnregisterClass")); | |
745 | } | |
746 | } | |
747 | } | |
748 | ||
749 | private: | |
750 | // initial value is -1 which means that we hadn't tried registering the | |
751 | // class yet, it becomes true or false (1 or 0) when Initialize() is called | |
752 | int m_registered; | |
753 | ||
754 | // the name of the class, only non empty if it had been registered | |
755 | wxString m_clsname; | |
756 | }; | |
757 | ||
a23fd0e1 | 758 | // --------------------------------------------------------------------------- |
42e69d6b | 759 | // macros to make casting between WXFOO and FOO a bit easier: the GetFoo() |
c50f1fb9 VZ |
760 | // returns Foo cast to the Windows type for oruselves, while GetFooOf() takes |
761 | // an argument which should be a pointer or reference to the object of the | |
762 | // corresponding class (this depends on the macro) | |
a23fd0e1 VZ |
763 | // --------------------------------------------------------------------------- |
764 | ||
765 | #define GetHwnd() ((HWND)GetHWND()) | |
c50f1fb9 VZ |
766 | #define GetHwndOf(win) ((HWND)((win)->GetHWND())) |
767 | // old name | |
768 | #define GetWinHwnd GetHwndOf | |
a23fd0e1 VZ |
769 | |
770 | #define GetHdc() ((HDC)GetHDC()) | |
c50f1fb9 | 771 | #define GetHdcOf(dc) ((HDC)(dc).GetHDC()) |
a23fd0e1 | 772 | |
11c7d5b6 VZ |
773 | #define GetHbitmap() ((HBITMAP)GetHBITMAP()) |
774 | #define GetHbitmapOf(bmp) ((HBITMAP)(bmp).GetHBITMAP()) | |
775 | ||
42e69d6b | 776 | #define GetHicon() ((HICON)GetHICON()) |
c50f1fb9 | 777 | #define GetHiconOf(icon) ((HICON)(icon).GetHICON()) |
42e69d6b | 778 | |
a23fd0e1 | 779 | #define GetHaccel() ((HACCEL)GetHACCEL()) |
c50f1fb9 VZ |
780 | #define GetHaccelOf(table) ((HACCEL)((table).GetHACCEL())) |
781 | ||
a27cbf44 VZ |
782 | #define GetHbrush() ((HBRUSH)GetResourceHandle()) |
783 | #define GetHbrushOf(brush) ((HBRUSH)(brush).GetResourceHandle()) | |
ee50eab8 | 784 | |
c50f1fb9 VZ |
785 | #define GetHmenu() ((HMENU)GetHMenu()) |
786 | #define GetHmenuOf(menu) ((HMENU)menu->GetHMenu()) | |
a23fd0e1 | 787 | |
bfbd6dc1 VZ |
788 | #define GetHcursor() ((HCURSOR)GetHCURSOR()) |
789 | #define GetHcursorOf(cursor) ((HCURSOR)(cursor).GetHCURSOR()) | |
790 | ||
f6bcfd97 BP |
791 | #define GetHfont() ((HFONT)GetHFONT()) |
792 | #define GetHfontOf(font) ((HFONT)(font).GetHFONT()) | |
793 | ||
f6840be6 VZ |
794 | #define GetHimagelist() ((HIMAGELIST)GetHIMAGELIST()) |
795 | #define GetHimagelistOf(imgl) ((HIMAGELIST)imgl->GetHIMAGELIST()) | |
796 | ||
1816a070 | 797 | #define GetHpalette() ((HPALETTE)GetHPALETTE()) |
b95edd47 | 798 | #define GetHpaletteOf(pal) ((HPALETTE)(pal).GetHPALETTE()) |
1816a070 | 799 | |
75776373 VZ |
800 | #define GetHpen() ((HPEN)GetResourceHandle()) |
801 | #define GetHpenOf(pen) ((HPEN)(pen).GetResourceHandle()) | |
802 | ||
1e6feb95 VZ |
803 | #define GetHrgn() ((HRGN)GetHRGN()) |
804 | #define GetHrgnOf(rgn) ((HRGN)(rgn).GetHRGN()) | |
805 | ||
f6bcfd97 BP |
806 | #endif // wxUSE_GUI |
807 | ||
a23fd0e1 VZ |
808 | // --------------------------------------------------------------------------- |
809 | // global functions | |
810 | // --------------------------------------------------------------------------- | |
811 | ||
18600546 GRG |
812 | extern "C" |
813 | { | |
bb24c68f | 814 | WXDLLIMPEXP_BASE HINSTANCE wxGetInstance(); |
18600546 GRG |
815 | } |
816 | ||
bb24c68f | 817 | WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst); |
a23fd0e1 | 818 | |
25b0e7c8 VZ |
819 | // return the full path of the given module |
820 | inline wxString wxGetFullModuleName(HMODULE hmod) | |
77d8d6cd VZ |
821 | { |
822 | wxString fullname; | |
823 | if ( !::GetModuleFileName | |
824 | ( | |
25b0e7c8 | 825 | hmod, |
77d8d6cd VZ |
826 | wxStringBuffer(fullname, MAX_PATH), |
827 | MAX_PATH | |
828 | ) ) | |
829 | { | |
830 | wxLogLastError(_T("GetModuleFileName")); | |
831 | } | |
832 | ||
833 | return fullname; | |
834 | } | |
835 | ||
25b0e7c8 VZ |
836 | // return the full path of the program file |
837 | inline wxString wxGetFullModuleName() | |
838 | { | |
839 | return wxGetFullModuleName((HMODULE)wxGetInstance()); | |
840 | } | |
841 | ||
4c5da5e4 VZ |
842 | // return the run-time version of the OS in a format similar to |
843 | // WINVER/_WIN32_WINNT compile-time macros: | |
844 | // | |
845 | // 0x0300 Windows NT 3.51 | |
846 | // 0x0400 Windows 95, NT4 | |
847 | // 0x0410 Windows 98 | |
848 | // 0x0500 Windows ME, 2000 | |
849 | // 0x0501 Windows XP | |
850 | // 0x0502 Windows 2003 | |
851 | // 0x0600 Longhorn | |
852 | // | |
853 | // for the other Windows versions 0 is currently returned | |
854 | enum wxWinVersion | |
855 | { | |
856 | wxWinVersion_Unknown = 0, | |
857 | ||
858 | wxWinVersion_3 = 0x0300, | |
859 | wxWinVersion_NT3 = wxWinVersion_3, | |
860 | ||
861 | wxWinVersion_4 = 0x0400, | |
862 | wxWinVersion_95 = wxWinVersion_4, | |
863 | wxWinVersion_NT4 = wxWinVersion_4, | |
864 | wxWinVersion_98 = 0x0410, | |
865 | ||
866 | wxWinVersion_5 = 0x0500, | |
867 | wxWinVersion_ME = wxWinVersion_5, | |
868 | wxWinVersion_NT5 = wxWinVersion_5, | |
869 | wxWinVersion_2000 = wxWinVersion_5, | |
870 | wxWinVersion_XP = 0x0501, | |
871 | wxWinVersion_2003 = 0x0502, | |
872 | ||
873 | wxWinVersion_6 = 0x0600, | |
0df7cb7e | 874 | wxWinVersion_Vista = wxWinVersion_6, |
c8b431ad | 875 | wxWinVersion_NT6 = wxWinVersion_6 |
4c5da5e4 VZ |
876 | }; |
877 | ||
be2572a3 | 878 | WXDLLIMPEXP_BASE wxWinVersion wxGetWinVersion(); |
4c5da5e4 | 879 | |
b568d04f VZ |
880 | #if wxUSE_GUI |
881 | ||
bfbd6dc1 VZ |
882 | // cursor stuff |
883 | extern HCURSOR wxGetCurrentBusyCursor(); // from msw/utils.cpp | |
884 | extern const wxCursor *wxGetGlobalCursor(); // from msw/cursor.cpp | |
885 | ||
53a2db12 FM |
886 | WXDLLIMPEXP_CORE void wxGetCharSize(WXHWND wnd, int *x, int *y, const wxFont& the_font); |
887 | WXDLLIMPEXP_CORE void wxFillLogFont(LOGFONT *logFont, const wxFont *font); | |
888 | WXDLLIMPEXP_CORE wxFont wxCreateFontFromLogFont(const LOGFONT *logFont); | |
889 | WXDLLIMPEXP_CORE wxFontEncoding wxGetFontEncFromCharSet(int charset); | |
a23fd0e1 | 890 | |
53a2db12 FM |
891 | WXDLLIMPEXP_CORE void wxSliderEvent(WXHWND control, WXWORD wParam, WXWORD pos); |
892 | WXDLLIMPEXP_CORE void wxScrollBarEvent(WXHWND hbar, WXWORD wParam, WXWORD pos); | |
a23fd0e1 VZ |
893 | |
894 | // Find maximum size of window/rectangle | |
53a2db12 | 895 | extern WXDLLIMPEXP_CORE void wxFindMaxSize(WXHWND hwnd, RECT *rect); |
a23fd0e1 | 896 | |
1c4a764c | 897 | // Safely get the window text (i.e. without using fixed size buffer) |
53a2db12 | 898 | extern WXDLLIMPEXP_CORE wxString wxGetWindowText(WXHWND hWnd); |
1c4a764c | 899 | |
cc2b7472 | 900 | // get the window class name |
53a2db12 | 901 | extern WXDLLIMPEXP_CORE wxString wxGetWindowClass(WXHWND hWnd); |
cc2b7472 | 902 | |
42e69d6b VZ |
903 | // get the window id (should be unsigned, hence this is not wxWindowID which |
904 | // is, for mainly historical reasons, signed) | |
53a2db12 | 905 | extern WXDLLIMPEXP_CORE int wxGetWindowId(WXHWND hWnd); |
cc2b7472 | 906 | |
ae304744 VZ |
907 | // check if hWnd's WNDPROC is wndProc. Return true if yes, false if they are |
908 | // different | |
53a2db12 | 909 | extern WXDLLIMPEXP_CORE bool wxCheckWindowWndProc(WXHWND hWnd, WXFARPROC wndProc); |
eb5e4d9a | 910 | |
c085e333 | 911 | // Does this window style specify any border? |
184b5d99 | 912 | inline bool wxStyleHasBorder(long style) |
c085e333 | 913 | { |
82c9f85c VZ |
914 | return (style & (wxSIMPLE_BORDER | wxRAISED_BORDER | |
915 | wxSUNKEN_BORDER | wxDOUBLE_BORDER)) != 0; | |
c085e333 VZ |
916 | } |
917 | ||
d026fee4 | 918 | inline long wxGetWindowExStyle(const wxWindowMSW *win) |
d66d0500 VZ |
919 | { |
920 | return ::GetWindowLong(GetHwndOf(win), GWL_EXSTYLE); | |
921 | } | |
922 | ||
d026fee4 | 923 | inline bool wxHasWindowExStyle(const wxWindowMSW *win, long style) |
d66d0500 VZ |
924 | { |
925 | return (wxGetWindowExStyle(win) & style) != 0; | |
926 | } | |
927 | ||
d026fee4 | 928 | inline long wxSetWindowExStyle(const wxWindowMSW *win, long style) |
d66d0500 VZ |
929 | { |
930 | return ::SetWindowLong(GetHwndOf(win), GWL_EXSTYLE, style); | |
931 | } | |
932 | ||
ae304744 VZ |
933 | // ---------------------------------------------------------------------------- |
934 | // functions mapping HWND to wxWindow | |
935 | // ---------------------------------------------------------------------------- | |
936 | ||
dca0f651 | 937 | // this function simply checks whether the given hwnd corresponds to a wxWindow |
ae304744 | 938 | // and returns either that window if it does or NULL otherwise |
53a2db12 | 939 | extern WXDLLIMPEXP_CORE wxWindow* wxFindWinFromHandle(HWND hwnd); |
dca0f651 VZ |
940 | |
941 | // without STRICT WXHWND is the same as HWND anyhow | |
942 | inline wxWindow* wxFindWinFromHandle(WXHWND hWnd) | |
943 | { | |
5c33522f | 944 | return wxFindWinFromHandle(static_cast<HWND>(hWnd)); |
dca0f651 | 945 | } |
ae304744 VZ |
946 | |
947 | // find the window for HWND which is part of some wxWindow, i.e. unlike | |
948 | // wxFindWinFromHandle() above it will also work for "sub controls" of a | |
949 | // wxWindow. | |
8614c467 | 950 | // |
ae304744 | 951 | // returns the wxWindow corresponding to the given HWND or NULL. |
53a2db12 | 952 | extern WXDLLIMPEXP_CORE wxWindow *wxGetWindowFromHWND(WXHWND hwnd); |
8614c467 | 953 | |
6bad4c32 | 954 | // Get the size of an icon |
53a2db12 | 955 | extern WXDLLIMPEXP_CORE wxSize wxGetHiconSize(HICON hicon); |
6bad4c32 | 956 | |
086b3a5b | 957 | // Lines are drawn differently for WinCE and regular WIN32 |
53a2db12 | 958 | WXDLLIMPEXP_CORE void wxDrawLine(HDC hdc, int x1, int y1, int x2, int y2); |
086b3a5b | 959 | |
c3732409 VZ |
960 | // fill the client rect of the given window on the provided dc using this brush |
961 | inline void wxFillRect(HWND hwnd, HDC hdc, HBRUSH hbr) | |
962 | { | |
963 | RECT rc; | |
964 | ::GetClientRect(hwnd, &rc); | |
965 | ::FillRect(hdc, &rc, hbr); | |
966 | } | |
967 | ||
5171ea0e VZ |
968 | // ---------------------------------------------------------------------------- |
969 | // 32/64 bit helpers | |
970 | // ---------------------------------------------------------------------------- | |
971 | ||
972 | #ifdef __WIN64__ | |
973 | ||
974 | inline void *wxGetWindowProc(HWND hwnd) | |
975 | { | |
976 | return (void *)::GetWindowLongPtr(hwnd, GWLP_WNDPROC); | |
977 | } | |
978 | ||
979 | inline void *wxGetWindowUserData(HWND hwnd) | |
980 | { | |
981 | return (void *)::GetWindowLongPtr(hwnd, GWLP_USERDATA); | |
982 | } | |
983 | ||
984 | inline WNDPROC wxSetWindowProc(HWND hwnd, WNDPROC func) | |
985 | { | |
986 | return (WNDPROC)::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)func); | |
987 | } | |
988 | ||
989 | inline void *wxSetWindowUserData(HWND hwnd, void *data) | |
990 | { | |
991 | return (void *)::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)data); | |
992 | } | |
993 | ||
994 | #else // __WIN32__ | |
995 | ||
54892273 VZ |
996 | // note that the casts to LONG_PTR here are required even on 32-bit machines |
997 | // for the 64-bit warning mode of later versions of MSVC (C4311/4312) | |
315a49a1 | 998 | inline WNDPROC wxGetWindowProc(HWND hwnd) |
5171ea0e | 999 | { |
315a49a1 | 1000 | return (WNDPROC)(LONG_PTR)::GetWindowLong(hwnd, GWL_WNDPROC); |
5171ea0e VZ |
1001 | } |
1002 | ||
1003 | inline void *wxGetWindowUserData(HWND hwnd) | |
1004 | { | |
54892273 | 1005 | return (void *)(LONG_PTR)::GetWindowLong(hwnd, GWL_USERDATA); |
5171ea0e VZ |
1006 | } |
1007 | ||
1008 | inline WNDPROC wxSetWindowProc(HWND hwnd, WNDPROC func) | |
1009 | { | |
54892273 | 1010 | return (WNDPROC)(LONG_PTR)::SetWindowLong(hwnd, GWL_WNDPROC, (LONG_PTR)func); |
5171ea0e VZ |
1011 | } |
1012 | ||
1013 | inline void *wxSetWindowUserData(HWND hwnd, void *data) | |
1014 | { | |
54892273 | 1015 | return (void *)(LONG_PTR)::SetWindowLong(hwnd, GWL_USERDATA, (LONG_PTR)data); |
5171ea0e VZ |
1016 | } |
1017 | ||
1018 | #endif // __WIN64__/__WIN32__ | |
1019 | ||
b568d04f VZ |
1020 | #endif // wxUSE_GUI |
1021 | ||
a27cbf44 | 1022 | #endif // _WX_PRIVATE_H_ |