1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/private.h
3 // Purpose: Private declarations: as this header is only included by
4 // wxWidgets itself, it may contain identifiers which don't start
6 // Author: Julian Smart
10 // Copyright: (c) Julian Smart
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
14 #ifndef _WX_PRIVATE_H_
15 #define _WX_PRIVATE_H_
17 #include "wx/msw/wrapwin.h"
20 // Extra prototypes and symbols not defined by MicroWindows
21 #include "wx/msw/microwin.h"
27 #include "wx/window.h"
30 class WXDLLIMPEXP_FWD_CORE wxFont
;
31 class WXDLLIMPEXP_FWD_CORE wxWindow
;
32 class WXDLLIMPEXP_FWD_CORE wxWindowBase
;
34 // ---------------------------------------------------------------------------
36 // ---------------------------------------------------------------------------
38 // 260 was taken from windef.h
43 // ---------------------------------------------------------------------------
44 // standard icons from the resources
45 // ---------------------------------------------------------------------------
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
;
59 // ---------------------------------------------------------------------------
61 // ---------------------------------------------------------------------------
63 extern WXDLLIMPEXP_DATA_BASE(HINSTANCE
) wxhInstance
;
67 WXDLLIMPEXP_BASE HINSTANCE
wxGetInstance();
70 WXDLLIMPEXP_BASE
void wxSetInstance(HINSTANCE hInst
);
72 // ---------------------------------------------------------------------------
73 // define things missing from some compilers' headers
74 // ---------------------------------------------------------------------------
76 #if defined(__WXWINCE__) || (defined(__GNUWIN32__) && !wxUSE_NORLANDER_HEADERS)
78 inline void ZeroMemory(void *buf
, size_t len
) { memset(buf
, 0, len
); }
82 // this defines a CASTWNDPROC macro which casts a pointer to the type of a
84 #if defined(STRICT) || defined(__GNUC__)
85 typedef WNDPROC WndProcCast
;
87 typedef FARPROC WndProcCast
;
91 #define CASTWNDPROC (WndProcCast)
95 // ---------------------------------------------------------------------------
96 // some stuff for old Windows versions (FIXME: what does it do here??)
97 // ---------------------------------------------------------------------------
99 #if !defined(APIENTRY) // NT defines APIENTRY, 3.x not
100 #define APIENTRY FAR PASCAL
106 #define _EXPORT _export
110 typedef signed short int SHORT
;
113 #if !defined(__WIN32__) // 3.x uses FARPROC for dialogs
115 #define DLGPROC FARPROC
120 * Decide what window classes we're going to use
121 * for this combination of CTl3D/FAFA settings
124 #define STATIC_CLASS wxT("STATIC")
125 #define STATIC_FLAGS (SS_LEFT|WS_CHILD|WS_VISIBLE)
126 #define CHECK_CLASS wxT("BUTTON")
127 #define CHECK_FLAGS (BS_AUTOCHECKBOX|WS_TABSTOP|WS_CHILD)
128 #define CHECK_IS_FAFA FALSE
129 #define RADIO_CLASS wxT("BUTTON")
130 #define RADIO_FLAGS (BS_AUTORADIOBUTTON|WS_CHILD|WS_VISIBLE)
131 #define RADIO_SIZE 20
132 #define RADIO_IS_FAFA FALSE
134 #define GROUP_CLASS wxT("BUTTON")
135 #define GROUP_FLAGS (BS_GROUPBOX|WS_CHILD|WS_VISIBLE)
138 #define BITCHECK_FLAGS (FB_BITMAP|FC_BUTTONDRAW|FC_DEFAULT|WS_VISIBLE)
139 #define BITRADIO_FLAGS (FC_BUTTONDRAW|FB_BITMAP|FC_RADIO|WS_CHILD|WS_VISIBLE)
142 // ---------------------------------------------------------------------------
144 // ---------------------------------------------------------------------------
146 #define MEANING_CHARACTER '0'
147 #define DEFAULT_ITEM_WIDTH 100
148 #define DEFAULT_ITEM_HEIGHT 80
150 // Scale font to get edit control height
151 //#define EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) (3*(cy)/2)
152 #define EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) (cy+8)
154 // Generic subclass proc, for panel item moving/sizing and intercept
155 // EDIT control VK_RETURN messages
156 extern LONG APIENTRY _EXPORT
157 wxSubclassedGenericControlProc(WXHWND hWnd
, WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
);
159 // ---------------------------------------------------------------------------
160 // useful macros and functions
161 // ---------------------------------------------------------------------------
163 // a wrapper macro for ZeroMemory()
164 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
165 #define wxZeroMemory(obj) ::ZeroMemory(&obj, sizeof(obj))
167 #define wxZeroMemory(obj) memset((void*) & obj, 0, sizeof(obj))
170 // This one is a macro so that it can be tested with #ifdef, it will be
171 // undefined if it cannot be implemented for a given compiler.
172 // Vc++, bcc, dmc, ow, mingw akk have _get_osfhandle() and Cygwin has
173 // get_osfhandle. Others are currently unknown, e.g. Salford, Intel, Visual
175 #if defined(__WXWINCE__)
176 #define wxGetOSFHandle(fd) ((HANDLE)fd)
177 #define wxOpenOSFHandle(h, flags) ((int)wxPtrToUInt(h))
178 #elif defined(__CYGWIN__)
179 #define wxGetOSFHandle(fd) ((HANDLE)get_osfhandle(fd))
180 #elif defined(__VISUALC__) \
181 || defined(__BORLANDC__) \
182 || defined(__DMC__) \
183 || defined(__WATCOMC__) \
184 || defined(__MINGW32__)
185 #define wxGetOSFHandle(fd) ((HANDLE)_get_osfhandle(fd))
186 #define wxOpenOSFHandle(h, flags) (_open_osfhandle(wxPtrToUInt(h), flags))
187 #define wx_fdopen _fdopen
190 // close the handle in the class dtor
194 wxEXPLICIT
AutoHANDLE(HANDLE handle
) : m_handle(handle
) { }
196 bool IsOk() const { return m_handle
!= INVALID_HANDLE_VALUE
; }
197 operator HANDLE() const { return m_handle
; }
199 ~AutoHANDLE() { if ( IsOk() ) ::CloseHandle(m_handle
); }
205 // a template to make initializing Windows styructs less painful: it zeroes all
206 // the struct fields and also sets cbSize member to the correct value (and so
207 // can be only used with structures which have this member...)
209 struct WinStruct
: public T
213 ::ZeroMemory(this, sizeof(T
));
215 // explicit qualification is required here for this to be valid C++
216 this->cbSize
= sizeof(T
);
223 #include "wx/gdicmn.h"
224 #include "wx/colour.h"
226 // make conversion from wxColour and COLORREF a bit less painful
227 inline COLORREF
wxColourToRGB(const wxColour
& c
)
229 return RGB(c
.Red(), c
.Green(), c
.Blue());
232 inline COLORREF
wxColourToPalRGB(const wxColour
& c
)
234 return PALETTERGB(c
.Red(), c
.Green(), c
.Blue());
237 inline wxColour
wxRGBToColour(COLORREF rgb
)
239 return wxColour(GetRValue(rgb
), GetGValue(rgb
), GetBValue(rgb
));
242 inline void wxRGBToColour(wxColour
& c
, COLORREF rgb
)
244 c
.Set(GetRValue(rgb
), GetGValue(rgb
), GetBValue(rgb
));
247 // get the standard colour map for some standard colours - see comment in this
248 // function to understand why is it needed and when should it be used
250 // it returns a wxCOLORMAP (can't use COLORMAP itself here as comctl32.dll
251 // might be not included/available) array of size wxSTD_COLOUR_MAX
253 // NB: if you change these colours, update wxBITMAP_STD_COLOURS in the
254 // resources as well: it must have the same number of pixels!
260 wxSTD_COL_BTNHIGHLIGHT
,
264 struct WXDLLIMPEXP_CORE wxCOLORMAP
269 // this function is implemented in src/msw/window.cpp
270 extern wxCOLORMAP
*wxGetStdColourMap();
272 // create a wxRect from Windows RECT
273 inline wxRect
wxRectFromRECT(const RECT
& rc
)
275 return wxRect(rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
278 // copy Windows RECT to our wxRect
279 inline void wxCopyRECTToRect(const RECT
& rc
, wxRect
& rect
)
281 rect
= wxRectFromRECT(rc
);
285 inline void wxCopyRectToRECT(const wxRect
& rect
, RECT
& rc
)
287 // note that we don't use wxRect::GetRight() as it is one of compared to
288 // wxRectFromRECT() above
291 rc
.right
= rect
.x
+ rect
.width
;
292 rc
.bottom
= rect
.y
+ rect
.height
;
295 // translations between HIMETRIC units (which OLE likes) and pixels (which are
296 // liked by all the others) - implemented in msw/utilsexc.cpp
297 extern void HIMETRICToPixel(LONG
*x
, LONG
*y
);
298 extern void HIMETRICToPixel(LONG
*x
, LONG
*y
, HDC hdcRef
);
299 extern void PixelToHIMETRIC(LONG
*x
, LONG
*y
);
300 extern void PixelToHIMETRIC(LONG
*x
, LONG
*y
, HDC hdcRef
);
302 // Windows convention of the mask is opposed to the wxWidgets one, so we need
303 // to invert the mask each time we pass one/get one to/from Windows
304 extern HBITMAP
wxInvertMask(HBITMAP hbmpMask
, int w
= 0, int h
= 0);
306 // Creates an icon or cursor depending from a bitmap
308 // The bitmap must be valid and it should have a mask. If it doesn't, a default
309 // mask is created using light grey as the transparent colour.
310 extern HICON
wxBitmapToHICON(const wxBitmap
& bmp
);
312 // Same requirments as above apply and the bitmap must also have the correct
315 HCURSOR
wxBitmapToHCURSOR(const wxBitmap
& bmp
, int hotSpotX
, int hotSpotY
);
318 #if wxUSE_OWNER_DRAWN
320 // Draw the bitmap in specified state (this is used by owner drawn controls)
329 BOOL
wxDrawStateBitmap(HDC hDC
, HBITMAP hBitmap
, int x
, int y
, UINT uState
);
331 #endif // wxUSE_OWNER_DRAWN
333 // get (x, y) from DWORD - notice that HI/LOWORD can *not* be used because they
334 // will fail on system with multiple monitors where the coords may be negative
336 // these macros are standard now (Win98) but some older headers don't have them
338 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
339 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
340 #endif // GET_X_LPARAM
342 // get the current state of SHIFT/CTRL/ALT keys
343 inline bool wxIsModifierDown(int vk
)
345 // GetKeyState() returns different negative values on WinME and WinNT,
346 // so simply test for negative value.
347 return ::GetKeyState(vk
) < 0;
350 inline bool wxIsShiftDown()
352 return wxIsModifierDown(VK_SHIFT
);
355 inline bool wxIsCtrlDown()
357 return wxIsModifierDown(VK_CONTROL
);
360 inline bool wxIsAltDown()
362 return wxIsModifierDown(VK_MENU
);
365 inline bool wxIsAnyModifierDown()
367 return wxIsShiftDown() || wxIsCtrlDown() || wxIsAltDown();
370 // wrapper around GetWindowRect() and GetClientRect() APIs doing error checking
372 inline RECT
wxGetWindowRect(HWND hwnd
)
376 if ( !::GetWindowRect(hwnd
, &rect
) )
378 wxLogLastError(wxT("GetWindowRect"));
384 inline RECT
wxGetClientRect(HWND hwnd
)
388 if ( !::GetClientRect(hwnd
, &rect
) )
390 wxLogLastError(wxT("GetClientRect"));
396 // ---------------------------------------------------------------------------
397 // small helper classes
398 // ---------------------------------------------------------------------------
400 // create an instance of this class and use it as the HDC for screen, will
401 // automatically release the DC going out of scope
405 ScreenHDC() { m_hdc
= ::GetDC(NULL
); }
406 ~ScreenHDC() { ::ReleaseDC(NULL
, m_hdc
); }
408 operator HDC() const { return m_hdc
; }
413 wxDECLARE_NO_COPY_CLASS(ScreenHDC
);
416 // the same as ScreenHDC but for window DCs
420 WindowHDC(HWND hwnd
) { m_hdc
= ::GetDC(m_hwnd
= hwnd
); }
421 ~WindowHDC() { ::ReleaseDC(m_hwnd
, m_hdc
); }
423 operator HDC() const { return m_hdc
; }
429 wxDECLARE_NO_COPY_CLASS(WindowHDC
);
432 // the same as ScreenHDC but for memory DCs: creates the HDC compatible with
433 // the given one (screen by default) in ctor and destroys it in dtor
437 MemoryHDC(HDC hdc
= 0) { m_hdc
= ::CreateCompatibleDC(hdc
); }
438 ~MemoryHDC() { ::DeleteDC(m_hdc
); }
440 operator HDC() const { return m_hdc
; }
445 wxDECLARE_NO_COPY_CLASS(MemoryHDC
);
448 // a class which selects a GDI object into a DC in its ctor and deselects in
453 void DoInit(HGDIOBJ hgdiobj
) { m_hgdiobj
= ::SelectObject(m_hdc
, hgdiobj
); }
456 SelectInHDC() : m_hdc(NULL
), m_hgdiobj(NULL
) { }
457 SelectInHDC(HDC hdc
, HGDIOBJ hgdiobj
) : m_hdc(hdc
) { DoInit(hgdiobj
); }
459 void Init(HDC hdc
, HGDIOBJ hgdiobj
)
461 wxASSERT_MSG( !m_hdc
, wxT("initializing twice?") );
468 ~SelectInHDC() { if ( m_hdc
) ::SelectObject(m_hdc
, m_hgdiobj
); }
470 // return true if the object was successfully selected
471 operator bool() const { return m_hgdiobj
!= 0; }
477 wxDECLARE_NO_COPY_CLASS(SelectInHDC
);
480 // a class which cleans up any GDI object
484 AutoGDIObject() { m_gdiobj
= NULL
; }
485 AutoGDIObject(HGDIOBJ gdiobj
) : m_gdiobj(gdiobj
) { }
486 ~AutoGDIObject() { if ( m_gdiobj
) ::DeleteObject(m_gdiobj
); }
488 void InitGdiobj(HGDIOBJ gdiobj
)
490 wxASSERT_MSG( !m_gdiobj
, wxT("initializing twice?") );
495 HGDIOBJ
GetObject() const { return m_gdiobj
; }
501 // TODO: all this asks for using a AutoHandler<T, CreateFunc> template...
503 // a class for temporary brushes
504 class AutoHBRUSH
: private AutoGDIObject
507 AutoHBRUSH(COLORREF col
)
508 : AutoGDIObject(::CreateSolidBrush(col
)) { }
510 operator HBRUSH() const { return (HBRUSH
)GetObject(); }
513 // a class for temporary fonts
514 class AutoHFONT
: private AutoGDIObject
519 : AutoGDIObject() { }
521 AutoHFONT(const LOGFONT
& lf
)
522 : AutoGDIObject(::CreateFontIndirect(&lf
)) { }
524 void Init(const LOGFONT
& lf
) { InitGdiobj(::CreateFontIndirect(&lf
)); }
526 operator HFONT() const { return (HFONT
)GetObject(); }
529 // a class for temporary pens
530 class AutoHPEN
: private AutoGDIObject
533 AutoHPEN(COLORREF col
)
534 : AutoGDIObject(::CreatePen(PS_SOLID
, 0, col
)) { }
536 operator HPEN() const { return (HPEN
)GetObject(); }
539 // classes for temporary bitmaps
540 class AutoHBITMAP
: private AutoGDIObject
544 : AutoGDIObject() { }
546 AutoHBITMAP(HBITMAP hbmp
) : AutoGDIObject(hbmp
) { }
548 void Init(HBITMAP hbmp
) { InitGdiobj(hbmp
); }
550 operator HBITMAP() const { return (HBITMAP
)GetObject(); }
553 class CompatibleBitmap
: public AutoHBITMAP
556 CompatibleBitmap(HDC hdc
, int w
, int h
)
557 : AutoHBITMAP(::CreateCompatibleBitmap(hdc
, w
, h
))
562 class MonoBitmap
: public AutoHBITMAP
565 MonoBitmap(int w
, int h
)
566 : AutoHBITMAP(::CreateBitmap(w
, h
, 1, 1, 0))
571 // class automatically destroys the region object
572 class AutoHRGN
: private AutoGDIObject
575 AutoHRGN(HRGN hrgn
) : AutoGDIObject(hrgn
) { }
577 operator HRGN() const { return (HRGN
)GetObject(); }
580 // class sets the specified clipping region during its life time
584 HDCClipper(HDC hdc
, HRGN hrgn
)
587 if ( !::SelectClipRgn(hdc
, hrgn
) )
589 wxLogLastError(wxT("SelectClipRgn"));
595 ::SelectClipRgn(m_hdc
, NULL
);
601 wxDECLARE_NO_COPY_CLASS(HDCClipper
);
604 // set the given map mode for the life time of this object
606 // NB: SetMapMode() is not supported by CE so we also define a helper macro
607 // to avoid using it there
609 #define wxCHANGE_HDC_MAP_MODE(hdc, mm)
610 #else // !__WXWINCE__
611 class HDCMapModeChanger
614 HDCMapModeChanger(HDC hdc
, int mm
)
617 m_modeOld
= ::SetMapMode(hdc
, mm
);
620 wxLogLastError(wxT("SelectClipRgn"));
627 ::SetMapMode(m_hdc
, m_modeOld
);
634 wxDECLARE_NO_COPY_CLASS(HDCMapModeChanger
);
637 #define wxCHANGE_HDC_MAP_MODE(hdc, mm) \
638 HDCMapModeChanger wxMAKE_UNIQUE_NAME(wxHDCMapModeChanger)(hdc, mm)
639 #endif // __WXWINCE__/!__WXWINCE__
641 // smart pointer using GlobalAlloc/GlobalFree()
645 // default ctor, call Init() later
651 // allocates a block of given size
652 void Init(size_t size
, unsigned flags
= GMEM_MOVEABLE
)
654 m_hGlobal
= ::GlobalAlloc(flags
, size
);
657 wxLogLastError(wxT("GlobalAlloc"));
661 GlobalPtr(size_t size
, unsigned flags
= GMEM_MOVEABLE
)
668 if ( m_hGlobal
&& ::GlobalFree(m_hGlobal
) )
670 wxLogLastError(wxT("GlobalFree"));
674 // implicit conversion
675 operator HGLOBAL() const { return m_hGlobal
; }
680 wxDECLARE_NO_COPY_CLASS(GlobalPtr
);
683 // when working with global pointers (which is unfortunately still necessary
684 // sometimes, e.g. for clipboard) it is important to unlock them exactly as
685 // many times as we lock them which just asks for using a "smart lock" class
689 // default ctor, use Init() later -- should only be used if the HGLOBAL can
690 // be NULL (in which case Init() shouldn't be called)
697 // initialize the object, may be only called if we were created using the
698 // default ctor; HGLOBAL must not be NULL
699 void Init(HGLOBAL hGlobal
)
703 // NB: GlobalLock() is a macro, not a function, hence don't use the
704 // global scope operator with it (and neither with GlobalUnlock())
705 m_ptr
= GlobalLock(hGlobal
);
708 wxLogLastError(wxT("GlobalLock"));
712 // initialize the object, HGLOBAL must not be NULL
713 GlobalPtrLock(HGLOBAL hGlobal
)
720 if ( m_hGlobal
&& !GlobalUnlock(m_hGlobal
) )
722 // this might happen simply because the block became unlocked
723 DWORD dwLastError
= ::GetLastError();
724 if ( dwLastError
!= NO_ERROR
)
726 wxLogApiError(wxT("GlobalUnlock"), dwLastError
);
731 void *Get() const { return m_ptr
; }
732 operator void *() const { return m_ptr
; }
738 wxDECLARE_NO_COPY_CLASS(GlobalPtrLock
);
741 // register the class when it is first needed and unregister it in dtor
745 // ctor doesn't register the class, call Initialize() for this
746 ClassRegistrar() { m_registered
= -1; }
748 // return true if the class is already registered
749 bool IsInitialized() const { return m_registered
!= -1; }
751 // return true if the class had been already registered
752 bool IsRegistered() const { return m_registered
== 1; }
754 // try to register the class if not done yet, return true on success
755 bool Register(const WNDCLASS
& wc
)
757 // we should only be called if we hadn't been initialized yet
758 wxASSERT_MSG( m_registered
== -1,
759 wxT("calling ClassRegistrar::Register() twice?") );
761 m_registered
= ::RegisterClass(&wc
) ? 1 : 0;
762 if ( !IsRegistered() )
764 wxLogLastError(wxT("RegisterClassEx()"));
768 m_clsname
= wc
.lpszClassName
;
771 return m_registered
== 1;
774 // get the name of the registered class (returns empty string if not
776 const wxString
& GetName() const { return m_clsname
; }
778 // unregister the class if it had been registered
781 if ( IsRegistered() )
783 if ( !::UnregisterClass(m_clsname
.wx_str(), wxGetInstance()) )
785 wxLogLastError(wxT("UnregisterClass"));
791 // initial value is -1 which means that we hadn't tried registering the
792 // class yet, it becomes true or false (1 or 0) when Initialize() is called
795 // the name of the class, only non empty if it had been registered
799 // ---------------------------------------------------------------------------
800 // macros to make casting between WXFOO and FOO a bit easier: the GetFoo()
801 // returns Foo cast to the Windows type for oruselves, while GetFooOf() takes
802 // an argument which should be a pointer or reference to the object of the
803 // corresponding class (this depends on the macro)
804 // ---------------------------------------------------------------------------
806 #define GetHwnd() ((HWND)GetHWND())
807 #define GetHwndOf(win) ((HWND)((win)->GetHWND()))
809 #define GetWinHwnd GetHwndOf
811 #define GetHdc() ((HDC)GetHDC())
812 #define GetHdcOf(dc) ((HDC)(dc).GetHDC())
814 #define GetHbitmap() ((HBITMAP)GetHBITMAP())
815 #define GetHbitmapOf(bmp) ((HBITMAP)(bmp).GetHBITMAP())
817 #define GetHicon() ((HICON)GetHICON())
818 #define GetHiconOf(icon) ((HICON)(icon).GetHICON())
820 #define GetHaccel() ((HACCEL)GetHACCEL())
821 #define GetHaccelOf(table) ((HACCEL)((table).GetHACCEL()))
823 #define GetHbrush() ((HBRUSH)GetResourceHandle())
824 #define GetHbrushOf(brush) ((HBRUSH)(brush).GetResourceHandle())
826 #define GetHmenu() ((HMENU)GetHMenu())
827 #define GetHmenuOf(menu) ((HMENU)(menu)->GetHMenu())
829 #define GetHcursor() ((HCURSOR)GetHCURSOR())
830 #define GetHcursorOf(cursor) ((HCURSOR)(cursor).GetHCURSOR())
832 #define GetHfont() ((HFONT)GetHFONT())
833 #define GetHfontOf(font) ((HFONT)(font).GetHFONT())
835 #define GetHimagelist() ((HIMAGELIST)GetHIMAGELIST())
836 #define GetHimagelistOf(imgl) ((HIMAGELIST)(imgl)->GetHIMAGELIST())
838 #define GetHpalette() ((HPALETTE)GetHPALETTE())
839 #define GetHpaletteOf(pal) ((HPALETTE)(pal).GetHPALETTE())
841 #define GetHpen() ((HPEN)GetResourceHandle())
842 #define GetHpenOf(pen) ((HPEN)(pen).GetResourceHandle())
844 #define GetHrgn() ((HRGN)GetHRGN())
845 #define GetHrgnOf(rgn) ((HRGN)(rgn).GetHRGN())
849 // ---------------------------------------------------------------------------
851 // ---------------------------------------------------------------------------
853 // return the full path of the given module
854 inline wxString
wxGetFullModuleName(HMODULE hmod
)
857 if ( !::GetModuleFileName
860 wxStringBuffer(fullname
, MAX_PATH
),
864 wxLogLastError(wxT("GetModuleFileName"));
870 // return the full path of the program file
871 inline wxString
wxGetFullModuleName()
873 return wxGetFullModuleName((HMODULE
)wxGetInstance());
876 // return the run-time version of the OS in a format similar to
877 // WINVER/_WIN32_WINNT compile-time macros:
879 // 0x0300 Windows NT 3.51
880 // 0x0400 Windows 95, NT4
882 // 0x0500 Windows ME, 2000
883 // 0x0501 Windows XP, 2003
884 // 0x0502 Windows XP SP2, 2003 SP1
885 // 0x0600 Windows Vista, 2008
888 // for the other Windows versions 0 is currently returned
891 wxWinVersion_Unknown
= 0,
893 wxWinVersion_3
= 0x0300,
894 wxWinVersion_NT3
= wxWinVersion_3
,
896 wxWinVersion_4
= 0x0400,
897 wxWinVersion_95
= wxWinVersion_4
,
898 wxWinVersion_NT4
= wxWinVersion_4
,
899 wxWinVersion_98
= 0x0410,
901 wxWinVersion_5
= 0x0500,
902 wxWinVersion_ME
= wxWinVersion_5
,
903 wxWinVersion_NT5
= wxWinVersion_5
,
904 wxWinVersion_2000
= wxWinVersion_5
,
905 wxWinVersion_XP
= 0x0501,
906 wxWinVersion_2003
= 0x0501,
907 wxWinVersion_XP_SP2
= 0x0502,
908 wxWinVersion_2003_SP1
= 0x0502,
910 wxWinVersion_6
= 0x0600,
911 wxWinVersion_Vista
= wxWinVersion_6
,
912 wxWinVersion_NT6
= wxWinVersion_6
,
914 wxWinVersion_7
= 0x601
917 WXDLLIMPEXP_BASE wxWinVersion
wxGetWinVersion();
922 extern HCURSOR
wxGetCurrentBusyCursor(); // from msw/utils.cpp
923 extern const wxCursor
*wxGetGlobalCursor(); // from msw/cursor.cpp
925 // GetCursorPos can fail without populating the POINT. This falls back to GetMessagePos.
926 WXDLLIMPEXP_CORE
void wxGetCursorPosMSW(POINT
* pt
);
928 WXDLLIMPEXP_CORE
void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
& the_font
);
929 WXDLLIMPEXP_CORE
void wxFillLogFont(LOGFONT
*logFont
, const wxFont
*font
);
930 WXDLLIMPEXP_CORE wxFont
wxCreateFontFromLogFont(const LOGFONT
*logFont
);
931 WXDLLIMPEXP_CORE wxFontEncoding
wxGetFontEncFromCharSet(int charset
);
933 WXDLLIMPEXP_CORE
void wxSliderEvent(WXHWND control
, WXWORD wParam
, WXWORD pos
);
934 WXDLLIMPEXP_CORE
void wxScrollBarEvent(WXHWND hbar
, WXWORD wParam
, WXWORD pos
);
936 // Find maximum size of window/rectangle
937 extern WXDLLIMPEXP_CORE
void wxFindMaxSize(WXHWND hwnd
, RECT
*rect
);
939 // Safely get the window text (i.e. without using fixed size buffer)
940 extern WXDLLIMPEXP_CORE wxString
wxGetWindowText(WXHWND hWnd
);
942 // get the window class name
943 extern WXDLLIMPEXP_CORE wxString
wxGetWindowClass(WXHWND hWnd
);
945 // get the window id (should be unsigned, hence this is not wxWindowID which
946 // is, for mainly historical reasons, signed)
947 extern WXDLLIMPEXP_CORE
int wxGetWindowId(WXHWND hWnd
);
949 // check if hWnd's WNDPROC is wndProc. Return true if yes, false if they are
951 extern WXDLLIMPEXP_CORE
bool wxCheckWindowWndProc(WXHWND hWnd
, WXFARPROC wndProc
);
953 // Does this window style specify any border?
954 inline bool wxStyleHasBorder(long style
)
956 return (style
& (wxSIMPLE_BORDER
| wxRAISED_BORDER
|
957 wxSUNKEN_BORDER
| wxDOUBLE_BORDER
)) != 0;
960 inline long wxGetWindowExStyle(const wxWindowMSW
*win
)
962 return ::GetWindowLong(GetHwndOf(win
), GWL_EXSTYLE
);
965 inline bool wxHasWindowExStyle(const wxWindowMSW
*win
, long style
)
967 return (wxGetWindowExStyle(win
) & style
) != 0;
970 inline long wxSetWindowExStyle(const wxWindowMSW
*win
, long style
)
972 return ::SetWindowLong(GetHwndOf(win
), GWL_EXSTYLE
, style
);
975 // ----------------------------------------------------------------------------
976 // functions mapping HWND to wxWindow
977 // ----------------------------------------------------------------------------
979 // this function simply checks whether the given hwnd corresponds to a wxWindow
980 // and returns either that window if it does or NULL otherwise
981 extern WXDLLIMPEXP_CORE wxWindow
* wxFindWinFromHandle(HWND hwnd
);
983 // find the window for HWND which is part of some wxWindow, i.e. unlike
984 // wxFindWinFromHandle() above it will also work for "sub controls" of a
987 // returns the wxWindow corresponding to the given HWND or NULL.
988 extern WXDLLIMPEXP_CORE wxWindow
*wxGetWindowFromHWND(WXHWND hwnd
);
990 // Get the size of an icon
991 extern WXDLLIMPEXP_CORE wxSize
wxGetHiconSize(HICON hicon
);
993 // Lines are drawn differently for WinCE and regular WIN32
994 WXDLLIMPEXP_CORE
void wxDrawLine(HDC hdc
, int x1
, int y1
, int x2
, int y2
);
996 // fill the client rect of the given window on the provided dc using this brush
997 inline void wxFillRect(HWND hwnd
, HDC hdc
, HBRUSH hbr
)
1000 ::GetClientRect(hwnd
, &rc
);
1001 ::FillRect(hdc
, &rc
, hbr
);
1004 // ----------------------------------------------------------------------------
1005 // 32/64 bit helpers
1006 // ----------------------------------------------------------------------------
1010 inline void *wxGetWindowProc(HWND hwnd
)
1012 return (void *)::GetWindowLongPtr(hwnd
, GWLP_WNDPROC
);
1015 inline void *wxGetWindowUserData(HWND hwnd
)
1017 return (void *)::GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
1020 inline WNDPROC
wxSetWindowProc(HWND hwnd
, WNDPROC func
)
1022 return (WNDPROC
)::SetWindowLongPtr(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)func
);
1025 inline void *wxSetWindowUserData(HWND hwnd
, void *data
)
1027 return (void *)::SetWindowLongPtr(hwnd
, GWLP_USERDATA
, (LONG_PTR
)data
);
1032 // note that the casts to LONG_PTR here are required even on 32-bit machines
1033 // for the 64-bit warning mode of later versions of MSVC (C4311/4312)
1034 inline WNDPROC
wxGetWindowProc(HWND hwnd
)
1036 return (WNDPROC
)(LONG_PTR
)::GetWindowLong(hwnd
, GWL_WNDPROC
);
1039 inline void *wxGetWindowUserData(HWND hwnd
)
1041 return (void *)(LONG_PTR
)::GetWindowLong(hwnd
, GWL_USERDATA
);
1044 inline WNDPROC
wxSetWindowProc(HWND hwnd
, WNDPROC func
)
1046 return (WNDPROC
)(LONG_PTR
)::SetWindowLong(hwnd
, GWL_WNDPROC
, (LONG_PTR
)func
);
1049 inline void *wxSetWindowUserData(HWND hwnd
, void *data
)
1051 return (void *)(LONG_PTR
)::SetWindowLong(hwnd
, GWL_USERDATA
, (LONG_PTR
)data
);
1054 #endif // __WIN64__/__WIN32__
1058 #endif // _WX_PRIVATE_H_