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, codewarrior (and rsxnt) have _get_osfhandle.
173 // Cygwin has get_osfhandle. Others are currently unknown, e.g. Salford,
174 // Intel, Visual Age.
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 || (defined(__MWERKS__) && defined(__MSL__))
186 #define wxGetOSFHandle(fd) ((HANDLE)_get_osfhandle(fd))
187 #define wxOpenOSFHandle(h, flags) (_open_osfhandle(wxPtrToUInt(h), flags))
188 #define wx_fdopen _fdopen
191 // close the handle in the class dtor
195 wxEXPLICIT
AutoHANDLE(HANDLE handle
) : m_handle(handle
) { }
197 bool IsOk() const { return m_handle
!= INVALID_HANDLE_VALUE
; }
198 operator HANDLE() const { return m_handle
; }
200 ~AutoHANDLE() { if ( IsOk() ) ::CloseHandle(m_handle
); }
206 // a template to make initializing Windows styructs less painful: it zeroes all
207 // the struct fields and also sets cbSize member to the correct value (and so
208 // can be only used with structures which have this member...)
210 struct WinStruct
: public T
214 ::ZeroMemory(this, sizeof(T
));
216 // explicit qualification is required here for this to be valid C++
217 this->cbSize
= sizeof(T
);
224 #include "wx/gdicmn.h"
225 #include "wx/colour.h"
227 // make conversion from wxColour and COLORREF a bit less painful
228 inline COLORREF
wxColourToRGB(const wxColour
& c
)
230 return RGB(c
.Red(), c
.Green(), c
.Blue());
233 inline COLORREF
wxColourToPalRGB(const wxColour
& c
)
235 return PALETTERGB(c
.Red(), c
.Green(), c
.Blue());
238 inline wxColour
wxRGBToColour(COLORREF rgb
)
240 return wxColour(GetRValue(rgb
), GetGValue(rgb
), GetBValue(rgb
));
243 inline void wxRGBToColour(wxColour
& c
, COLORREF rgb
)
245 c
.Set(GetRValue(rgb
), GetGValue(rgb
), GetBValue(rgb
));
248 // get the standard colour map for some standard colours - see comment in this
249 // function to understand why is it needed and when should it be used
251 // it returns a wxCOLORMAP (can't use COLORMAP itself here as comctl32.dll
252 // might be not included/available) array of size wxSTD_COLOUR_MAX
254 // NB: if you change these colours, update wxBITMAP_STD_COLOURS in the
255 // resources as well: it must have the same number of pixels!
261 wxSTD_COL_BTNHIGHLIGHT
,
265 struct WXDLLIMPEXP_CORE wxCOLORMAP
270 // this function is implemented in src/msw/window.cpp
271 extern wxCOLORMAP
*wxGetStdColourMap();
273 // create a wxRect from Windows RECT
274 inline wxRect
wxRectFromRECT(const RECT
& rc
)
276 return wxRect(rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
279 // copy Windows RECT to our wxRect
280 inline void wxCopyRECTToRect(const RECT
& rc
, wxRect
& rect
)
282 rect
= wxRectFromRECT(rc
);
286 inline void wxCopyRectToRECT(const wxRect
& rect
, RECT
& rc
)
288 // note that we don't use wxRect::GetRight() as it is one of compared to
289 // wxRectFromRECT() above
292 rc
.right
= rect
.x
+ rect
.width
;
293 rc
.bottom
= rect
.y
+ rect
.height
;
296 // translations between HIMETRIC units (which OLE likes) and pixels (which are
297 // liked by all the others) - implemented in msw/utilsexc.cpp
298 extern void HIMETRICToPixel(LONG
*x
, LONG
*y
);
299 extern void HIMETRICToPixel(LONG
*x
, LONG
*y
, HDC hdcRef
);
300 extern void PixelToHIMETRIC(LONG
*x
, LONG
*y
);
301 extern void PixelToHIMETRIC(LONG
*x
, LONG
*y
, HDC hdcRef
);
303 // Windows convention of the mask is opposed to the wxWidgets one, so we need
304 // to invert the mask each time we pass one/get one to/from Windows
305 extern HBITMAP
wxInvertMask(HBITMAP hbmpMask
, int w
= 0, int h
= 0);
307 // Creates an icon or cursor depending from a bitmap
309 // The bitmap must be valid and it should have a mask. If it doesn't, a default
310 // mask is created using light grey as the transparent colour.
311 extern HICON
wxBitmapToHICON(const wxBitmap
& bmp
);
313 // Same requirments as above apply and the bitmap must also have the correct
316 HCURSOR
wxBitmapToHCURSOR(const wxBitmap
& bmp
, int hotSpotX
, int hotSpotY
);
319 #if wxUSE_OWNER_DRAWN
321 // Draw the bitmap in specified state (this is used by owner drawn controls)
330 BOOL
wxDrawStateBitmap(HDC hDC
, HBITMAP hBitmap
, int x
, int y
, UINT uState
);
332 #endif // wxUSE_OWNER_DRAWN
334 // get (x, y) from DWORD - notice that HI/LOWORD can *not* be used because they
335 // will fail on system with multiple monitors where the coords may be negative
337 // these macros are standard now (Win98) but some older headers don't have them
339 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
340 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
341 #endif // GET_X_LPARAM
343 // get the current state of SHIFT/CTRL/ALT keys
344 inline bool wxIsModifierDown(int vk
)
346 // GetKeyState() returns different negative values on WinME and WinNT,
347 // so simply test for negative value.
348 return ::GetKeyState(vk
) < 0;
351 inline bool wxIsShiftDown()
353 return wxIsModifierDown(VK_SHIFT
);
356 inline bool wxIsCtrlDown()
358 return wxIsModifierDown(VK_CONTROL
);
361 inline bool wxIsAltDown()
363 return wxIsModifierDown(VK_MENU
);
366 inline bool wxIsAnyModifierDown()
368 return wxIsShiftDown() || wxIsCtrlDown() || wxIsAltDown();
371 // wrapper around GetWindowRect() and GetClientRect() APIs doing error checking
373 inline RECT
wxGetWindowRect(HWND hwnd
)
377 if ( !::GetWindowRect(hwnd
, &rect
) )
379 wxLogLastError(wxT("GetWindowRect"));
385 inline RECT
wxGetClientRect(HWND hwnd
)
389 if ( !::GetClientRect(hwnd
, &rect
) )
391 wxLogLastError(wxT("GetClientRect"));
397 // ---------------------------------------------------------------------------
398 // small helper classes
399 // ---------------------------------------------------------------------------
401 // create an instance of this class and use it as the HDC for screen, will
402 // automatically release the DC going out of scope
406 ScreenHDC() { m_hdc
= ::GetDC(NULL
); }
407 ~ScreenHDC() { ::ReleaseDC(NULL
, m_hdc
); }
409 operator HDC() const { return m_hdc
; }
414 wxDECLARE_NO_COPY_CLASS(ScreenHDC
);
417 // the same as ScreenHDC but for window DCs
421 WindowHDC(HWND hwnd
) { m_hdc
= ::GetDC(m_hwnd
= hwnd
); }
422 ~WindowHDC() { ::ReleaseDC(m_hwnd
, m_hdc
); }
424 operator HDC() const { return m_hdc
; }
430 wxDECLARE_NO_COPY_CLASS(WindowHDC
);
433 // the same as ScreenHDC but for memory DCs: creates the HDC compatible with
434 // the given one (screen by default) in ctor and destroys it in dtor
438 MemoryHDC(HDC hdc
= 0) { m_hdc
= ::CreateCompatibleDC(hdc
); }
439 ~MemoryHDC() { ::DeleteDC(m_hdc
); }
441 operator HDC() const { return m_hdc
; }
446 wxDECLARE_NO_COPY_CLASS(MemoryHDC
);
449 // a class which selects a GDI object into a DC in its ctor and deselects in
454 void DoInit(HGDIOBJ hgdiobj
) { m_hgdiobj
= ::SelectObject(m_hdc
, hgdiobj
); }
457 SelectInHDC() : m_hdc(NULL
), m_hgdiobj(NULL
) { }
458 SelectInHDC(HDC hdc
, HGDIOBJ hgdiobj
) : m_hdc(hdc
) { DoInit(hgdiobj
); }
460 void Init(HDC hdc
, HGDIOBJ hgdiobj
)
462 wxASSERT_MSG( !m_hdc
, wxT("initializing twice?") );
469 ~SelectInHDC() { if ( m_hdc
) ::SelectObject(m_hdc
, m_hgdiobj
); }
471 // return true if the object was successfully selected
472 operator bool() const { return m_hgdiobj
!= 0; }
478 wxDECLARE_NO_COPY_CLASS(SelectInHDC
);
481 // a class which cleans up any GDI object
485 AutoGDIObject() { m_gdiobj
= NULL
; }
486 AutoGDIObject(HGDIOBJ gdiobj
) : m_gdiobj(gdiobj
) { }
487 ~AutoGDIObject() { if ( m_gdiobj
) ::DeleteObject(m_gdiobj
); }
489 void InitGdiobj(HGDIOBJ gdiobj
)
491 wxASSERT_MSG( !m_gdiobj
, wxT("initializing twice?") );
496 HGDIOBJ
GetObject() const { return m_gdiobj
; }
502 // TODO: all this asks for using a AutoHandler<T, CreateFunc> template...
504 // a class for temporary brushes
505 class AutoHBRUSH
: private AutoGDIObject
508 AutoHBRUSH(COLORREF col
)
509 : AutoGDIObject(::CreateSolidBrush(col
)) { }
511 operator HBRUSH() const { return (HBRUSH
)GetObject(); }
514 // a class for temporary fonts
515 class AutoHFONT
: private AutoGDIObject
520 : AutoGDIObject() { }
522 AutoHFONT(const LOGFONT
& lf
)
523 : AutoGDIObject(::CreateFontIndirect(&lf
)) { }
525 void Init(const LOGFONT
& lf
) { InitGdiobj(::CreateFontIndirect(&lf
)); }
527 operator HFONT() const { return (HFONT
)GetObject(); }
530 // a class for temporary pens
531 class AutoHPEN
: private AutoGDIObject
534 AutoHPEN(COLORREF col
)
535 : AutoGDIObject(::CreatePen(PS_SOLID
, 0, col
)) { }
537 operator HPEN() const { return (HPEN
)GetObject(); }
540 // classes for temporary bitmaps
541 class AutoHBITMAP
: private AutoGDIObject
545 : AutoGDIObject() { }
547 AutoHBITMAP(HBITMAP hbmp
) : AutoGDIObject(hbmp
) { }
549 void Init(HBITMAP hbmp
) { InitGdiobj(hbmp
); }
551 operator HBITMAP() const { return (HBITMAP
)GetObject(); }
554 class CompatibleBitmap
: public AutoHBITMAP
557 CompatibleBitmap(HDC hdc
, int w
, int h
)
558 : AutoHBITMAP(::CreateCompatibleBitmap(hdc
, w
, h
))
563 class MonoBitmap
: public AutoHBITMAP
566 MonoBitmap(int w
, int h
)
567 : AutoHBITMAP(::CreateBitmap(w
, h
, 1, 1, 0))
572 // class automatically destroys the region object
573 class AutoHRGN
: private AutoGDIObject
576 AutoHRGN(HRGN hrgn
) : AutoGDIObject(hrgn
) { }
578 operator HRGN() const { return (HRGN
)GetObject(); }
581 // class sets the specified clipping region during its life time
585 HDCClipper(HDC hdc
, HRGN hrgn
)
588 if ( !::SelectClipRgn(hdc
, hrgn
) )
590 wxLogLastError(wxT("SelectClipRgn"));
596 ::SelectClipRgn(m_hdc
, NULL
);
602 wxDECLARE_NO_COPY_CLASS(HDCClipper
);
605 // set the given map mode for the life time of this object
607 // NB: SetMapMode() is not supported by CE so we also define a helper macro
608 // to avoid using it there
610 #define wxCHANGE_HDC_MAP_MODE(hdc, mm)
611 #else // !__WXWINCE__
612 class HDCMapModeChanger
615 HDCMapModeChanger(HDC hdc
, int mm
)
618 m_modeOld
= ::SetMapMode(hdc
, mm
);
621 wxLogLastError(wxT("SelectClipRgn"));
628 ::SetMapMode(m_hdc
, m_modeOld
);
635 wxDECLARE_NO_COPY_CLASS(HDCMapModeChanger
);
638 #define wxCHANGE_HDC_MAP_MODE(hdc, mm) \
639 HDCMapModeChanger wxMAKE_UNIQUE_NAME(wxHDCMapModeChanger)(hdc, mm)
640 #endif // __WXWINCE__/!__WXWINCE__
642 // smart pointer using GlobalAlloc/GlobalFree()
646 // default ctor, call Init() later
652 // allocates a block of given size
653 void Init(size_t size
, unsigned flags
= GMEM_MOVEABLE
)
655 m_hGlobal
= ::GlobalAlloc(flags
, size
);
658 wxLogLastError(wxT("GlobalAlloc"));
662 GlobalPtr(size_t size
, unsigned flags
= GMEM_MOVEABLE
)
669 if ( m_hGlobal
&& ::GlobalFree(m_hGlobal
) )
671 wxLogLastError(wxT("GlobalFree"));
675 // implicit conversion
676 operator HGLOBAL() const { return m_hGlobal
; }
681 wxDECLARE_NO_COPY_CLASS(GlobalPtr
);
684 // when working with global pointers (which is unfortunately still necessary
685 // sometimes, e.g. for clipboard) it is important to unlock them exactly as
686 // many times as we lock them which just asks for using a "smart lock" class
690 // default ctor, use Init() later -- should only be used if the HGLOBAL can
691 // be NULL (in which case Init() shouldn't be called)
698 // initialize the object, may be only called if we were created using the
699 // default ctor; HGLOBAL must not be NULL
700 void Init(HGLOBAL hGlobal
)
704 // NB: GlobalLock() is a macro, not a function, hence don't use the
705 // global scope operator with it (and neither with GlobalUnlock())
706 m_ptr
= GlobalLock(hGlobal
);
709 wxLogLastError(wxT("GlobalLock"));
713 // initialize the object, HGLOBAL must not be NULL
714 GlobalPtrLock(HGLOBAL hGlobal
)
721 if ( m_hGlobal
&& !GlobalUnlock(m_hGlobal
) )
723 // this might happen simply because the block became unlocked
724 DWORD dwLastError
= ::GetLastError();
725 if ( dwLastError
!= NO_ERROR
)
727 wxLogApiError(wxT("GlobalUnlock"), dwLastError
);
732 void *Get() const { return m_ptr
; }
733 operator void *() const { return m_ptr
; }
739 wxDECLARE_NO_COPY_CLASS(GlobalPtrLock
);
742 // register the class when it is first needed and unregister it in dtor
746 // ctor doesn't register the class, call Initialize() for this
747 ClassRegistrar() { m_registered
= -1; }
749 // return true if the class is already registered
750 bool IsInitialized() const { return m_registered
!= -1; }
752 // return true if the class had been already registered
753 bool IsRegistered() const { return m_registered
== 1; }
755 // try to register the class if not done yet, return true on success
756 bool Register(const WNDCLASS
& wc
)
758 // we should only be called if we hadn't been initialized yet
759 wxASSERT_MSG( m_registered
== -1,
760 wxT("calling ClassRegistrar::Register() twice?") );
762 m_registered
= ::RegisterClass(&wc
) ? 1 : 0;
763 if ( !IsRegistered() )
765 wxLogLastError(wxT("RegisterClassEx()"));
769 m_clsname
= wc
.lpszClassName
;
772 return m_registered
== 1;
775 // get the name of the registered class (returns empty string if not
777 const wxString
& GetName() const { return m_clsname
; }
779 // unregister the class if it had been registered
782 if ( IsRegistered() )
784 if ( !::UnregisterClass(m_clsname
.wx_str(), wxGetInstance()) )
786 wxLogLastError(wxT("UnregisterClass"));
792 // initial value is -1 which means that we hadn't tried registering the
793 // class yet, it becomes true or false (1 or 0) when Initialize() is called
796 // the name of the class, only non empty if it had been registered
800 // ---------------------------------------------------------------------------
801 // macros to make casting between WXFOO and FOO a bit easier: the GetFoo()
802 // returns Foo cast to the Windows type for oruselves, while GetFooOf() takes
803 // an argument which should be a pointer or reference to the object of the
804 // corresponding class (this depends on the macro)
805 // ---------------------------------------------------------------------------
807 #define GetHwnd() ((HWND)GetHWND())
808 #define GetHwndOf(win) ((HWND)((win)->GetHWND()))
810 #define GetWinHwnd GetHwndOf
812 #define GetHdc() ((HDC)GetHDC())
813 #define GetHdcOf(dc) ((HDC)(dc).GetHDC())
815 #define GetHbitmap() ((HBITMAP)GetHBITMAP())
816 #define GetHbitmapOf(bmp) ((HBITMAP)(bmp).GetHBITMAP())
818 #define GetHicon() ((HICON)GetHICON())
819 #define GetHiconOf(icon) ((HICON)(icon).GetHICON())
821 #define GetHaccel() ((HACCEL)GetHACCEL())
822 #define GetHaccelOf(table) ((HACCEL)((table).GetHACCEL()))
824 #define GetHbrush() ((HBRUSH)GetResourceHandle())
825 #define GetHbrushOf(brush) ((HBRUSH)(brush).GetResourceHandle())
827 #define GetHmenu() ((HMENU)GetHMenu())
828 #define GetHmenuOf(menu) ((HMENU)(menu)->GetHMenu())
830 #define GetHcursor() ((HCURSOR)GetHCURSOR())
831 #define GetHcursorOf(cursor) ((HCURSOR)(cursor).GetHCURSOR())
833 #define GetHfont() ((HFONT)GetHFONT())
834 #define GetHfontOf(font) ((HFONT)(font).GetHFONT())
836 #define GetHimagelist() ((HIMAGELIST)GetHIMAGELIST())
837 #define GetHimagelistOf(imgl) ((HIMAGELIST)(imgl)->GetHIMAGELIST())
839 #define GetHpalette() ((HPALETTE)GetHPALETTE())
840 #define GetHpaletteOf(pal) ((HPALETTE)(pal).GetHPALETTE())
842 #define GetHpen() ((HPEN)GetResourceHandle())
843 #define GetHpenOf(pen) ((HPEN)(pen).GetResourceHandle())
845 #define GetHrgn() ((HRGN)GetHRGN())
846 #define GetHrgnOf(rgn) ((HRGN)(rgn).GetHRGN())
850 // ---------------------------------------------------------------------------
852 // ---------------------------------------------------------------------------
854 // return the full path of the given module
855 inline wxString
wxGetFullModuleName(HMODULE hmod
)
858 if ( !::GetModuleFileName
861 wxStringBuffer(fullname
, MAX_PATH
),
865 wxLogLastError(wxT("GetModuleFileName"));
871 // return the full path of the program file
872 inline wxString
wxGetFullModuleName()
874 return wxGetFullModuleName((HMODULE
)wxGetInstance());
877 // return the run-time version of the OS in a format similar to
878 // WINVER/_WIN32_WINNT compile-time macros:
880 // 0x0300 Windows NT 3.51
881 // 0x0400 Windows 95, NT4
883 // 0x0500 Windows ME, 2000
884 // 0x0501 Windows XP, 2003
885 // 0x0502 Windows XP SP2, 2003 SP1
886 // 0x0600 Windows Vista, 2008
889 // for the other Windows versions 0 is currently returned
892 wxWinVersion_Unknown
= 0,
894 wxWinVersion_3
= 0x0300,
895 wxWinVersion_NT3
= wxWinVersion_3
,
897 wxWinVersion_4
= 0x0400,
898 wxWinVersion_95
= wxWinVersion_4
,
899 wxWinVersion_NT4
= wxWinVersion_4
,
900 wxWinVersion_98
= 0x0410,
902 wxWinVersion_5
= 0x0500,
903 wxWinVersion_ME
= wxWinVersion_5
,
904 wxWinVersion_NT5
= wxWinVersion_5
,
905 wxWinVersion_2000
= wxWinVersion_5
,
906 wxWinVersion_XP
= 0x0501,
907 wxWinVersion_2003
= 0x0501,
908 wxWinVersion_XP_SP2
= 0x0502,
909 wxWinVersion_2003_SP1
= 0x0502,
911 wxWinVersion_6
= 0x0600,
912 wxWinVersion_Vista
= wxWinVersion_6
,
913 wxWinVersion_NT6
= wxWinVersion_6
,
915 wxWinVersion_7
= 0x601
918 WXDLLIMPEXP_BASE wxWinVersion
wxGetWinVersion();
923 extern HCURSOR
wxGetCurrentBusyCursor(); // from msw/utils.cpp
924 extern const wxCursor
*wxGetGlobalCursor(); // from msw/cursor.cpp
926 // GetCursorPos can fail without populating the POINT. This falls back to GetMessagePos.
927 WXDLLIMPEXP_CORE
void wxGetCursorPosMSW(POINT
* pt
);
929 WXDLLIMPEXP_CORE
void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
& the_font
);
930 WXDLLIMPEXP_CORE
void wxFillLogFont(LOGFONT
*logFont
, const wxFont
*font
);
931 WXDLLIMPEXP_CORE wxFont
wxCreateFontFromLogFont(const LOGFONT
*logFont
);
932 WXDLLIMPEXP_CORE wxFontEncoding
wxGetFontEncFromCharSet(int charset
);
934 WXDLLIMPEXP_CORE
void wxSliderEvent(WXHWND control
, WXWORD wParam
, WXWORD pos
);
935 WXDLLIMPEXP_CORE
void wxScrollBarEvent(WXHWND hbar
, WXWORD wParam
, WXWORD pos
);
937 // Find maximum size of window/rectangle
938 extern WXDLLIMPEXP_CORE
void wxFindMaxSize(WXHWND hwnd
, RECT
*rect
);
940 // Safely get the window text (i.e. without using fixed size buffer)
941 extern WXDLLIMPEXP_CORE wxString
wxGetWindowText(WXHWND hWnd
);
943 // get the window class name
944 extern WXDLLIMPEXP_CORE wxString
wxGetWindowClass(WXHWND hWnd
);
946 // get the window id (should be unsigned, hence this is not wxWindowID which
947 // is, for mainly historical reasons, signed)
948 extern WXDLLIMPEXP_CORE
int wxGetWindowId(WXHWND hWnd
);
950 // check if hWnd's WNDPROC is wndProc. Return true if yes, false if they are
952 extern WXDLLIMPEXP_CORE
bool wxCheckWindowWndProc(WXHWND hWnd
, WXFARPROC wndProc
);
954 // Does this window style specify any border?
955 inline bool wxStyleHasBorder(long style
)
957 return (style
& (wxSIMPLE_BORDER
| wxRAISED_BORDER
|
958 wxSUNKEN_BORDER
| wxDOUBLE_BORDER
)) != 0;
961 inline long wxGetWindowExStyle(const wxWindowMSW
*win
)
963 return ::GetWindowLong(GetHwndOf(win
), GWL_EXSTYLE
);
966 inline bool wxHasWindowExStyle(const wxWindowMSW
*win
, long style
)
968 return (wxGetWindowExStyle(win
) & style
) != 0;
971 inline long wxSetWindowExStyle(const wxWindowMSW
*win
, long style
)
973 return ::SetWindowLong(GetHwndOf(win
), GWL_EXSTYLE
, style
);
976 // ----------------------------------------------------------------------------
977 // functions mapping HWND to wxWindow
978 // ----------------------------------------------------------------------------
980 // this function simply checks whether the given hwnd corresponds to a wxWindow
981 // and returns either that window if it does or NULL otherwise
982 extern WXDLLIMPEXP_CORE wxWindow
* wxFindWinFromHandle(HWND hwnd
);
984 // find the window for HWND which is part of some wxWindow, i.e. unlike
985 // wxFindWinFromHandle() above it will also work for "sub controls" of a
988 // returns the wxWindow corresponding to the given HWND or NULL.
989 extern WXDLLIMPEXP_CORE wxWindow
*wxGetWindowFromHWND(WXHWND hwnd
);
991 // Get the size of an icon
992 extern WXDLLIMPEXP_CORE wxSize
wxGetHiconSize(HICON hicon
);
994 // Lines are drawn differently for WinCE and regular WIN32
995 WXDLLIMPEXP_CORE
void wxDrawLine(HDC hdc
, int x1
, int y1
, int x2
, int y2
);
997 // fill the client rect of the given window on the provided dc using this brush
998 inline void wxFillRect(HWND hwnd
, HDC hdc
, HBRUSH hbr
)
1001 ::GetClientRect(hwnd
, &rc
);
1002 ::FillRect(hdc
, &rc
, hbr
);
1005 // ----------------------------------------------------------------------------
1006 // 32/64 bit helpers
1007 // ----------------------------------------------------------------------------
1011 inline void *wxGetWindowProc(HWND hwnd
)
1013 return (void *)::GetWindowLongPtr(hwnd
, GWLP_WNDPROC
);
1016 inline void *wxGetWindowUserData(HWND hwnd
)
1018 return (void *)::GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
1021 inline WNDPROC
wxSetWindowProc(HWND hwnd
, WNDPROC func
)
1023 return (WNDPROC
)::SetWindowLongPtr(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)func
);
1026 inline void *wxSetWindowUserData(HWND hwnd
, void *data
)
1028 return (void *)::SetWindowLongPtr(hwnd
, GWLP_USERDATA
, (LONG_PTR
)data
);
1033 // note that the casts to LONG_PTR here are required even on 32-bit machines
1034 // for the 64-bit warning mode of later versions of MSVC (C4311/4312)
1035 inline WNDPROC
wxGetWindowProc(HWND hwnd
)
1037 return (WNDPROC
)(LONG_PTR
)::GetWindowLong(hwnd
, GWL_WNDPROC
);
1040 inline void *wxGetWindowUserData(HWND hwnd
)
1042 return (void *)(LONG_PTR
)::GetWindowLong(hwnd
, GWL_USERDATA
);
1045 inline WNDPROC
wxSetWindowProc(HWND hwnd
, WNDPROC func
)
1047 return (WNDPROC
)(LONG_PTR
)::SetWindowLong(hwnd
, GWL_WNDPROC
, (LONG_PTR
)func
);
1050 inline void *wxSetWindowUserData(HWND hwnd
, void *data
)
1052 return (void *)(LONG_PTR
)::SetWindowLong(hwnd
, GWL_USERDATA
, (LONG_PTR
)data
);
1055 #endif // __WIN64__/__WIN32__
1059 #endif // _WX_PRIVATE_H_