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
);
221 // Macros for converting wxString to the type expected by API functions.
223 // Normally it is enough to just use wxString::t_str() which is implicitly
224 // convertible to LPCTSTR, but in some cases an explicit conversion is required.
226 // In such cases wxMSW_CONV_LPCTSTR() should be used. But if an API function
227 // takes a non-const pointer, wxMSW_CONV_LPTSTR() which casts away the
228 // constness (but doesn't make it possible to really modify the returned
229 // pointer, of course) should be used. And if a string is passed as LPARAM, use
230 // wxMSW_CONV_LPARAM() which does the required ugly reinterpret_cast<> too.
231 #define wxMSW_CONV_LPCTSTR(s) static_cast<const wxChar *>((s).t_str())
232 #define wxMSW_CONV_LPTSTR(s) const_cast<wxChar *>(wxMSW_CONV_LPCTSTR(s))
233 #define wxMSW_CONV_LPARAM(s) reinterpret_cast<LPARAM>(wxMSW_CONV_LPCTSTR(s))
238 #include "wx/gdicmn.h"
239 #include "wx/colour.h"
241 // make conversion from wxColour and COLORREF a bit less painful
242 inline COLORREF
wxColourToRGB(const wxColour
& c
)
244 return RGB(c
.Red(), c
.Green(), c
.Blue());
247 inline COLORREF
wxColourToPalRGB(const wxColour
& c
)
249 return PALETTERGB(c
.Red(), c
.Green(), c
.Blue());
252 inline wxColour
wxRGBToColour(COLORREF rgb
)
254 return wxColour(GetRValue(rgb
), GetGValue(rgb
), GetBValue(rgb
));
257 inline void wxRGBToColour(wxColour
& c
, COLORREF rgb
)
259 c
.Set(GetRValue(rgb
), GetGValue(rgb
), GetBValue(rgb
));
262 // get the standard colour map for some standard colours - see comment in this
263 // function to understand why is it needed and when should it be used
265 // it returns a wxCOLORMAP (can't use COLORMAP itself here as comctl32.dll
266 // might be not included/available) array of size wxSTD_COLOUR_MAX
268 // NB: if you change these colours, update wxBITMAP_STD_COLOURS in the
269 // resources as well: it must have the same number of pixels!
275 wxSTD_COL_BTNHIGHLIGHT
,
279 struct WXDLLIMPEXP_CORE wxCOLORMAP
284 // this function is implemented in src/msw/window.cpp
285 extern wxCOLORMAP
*wxGetStdColourMap();
287 // create a wxRect from Windows RECT
288 inline wxRect
wxRectFromRECT(const RECT
& rc
)
290 return wxRect(rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
293 // copy Windows RECT to our wxRect
294 inline void wxCopyRECTToRect(const RECT
& rc
, wxRect
& rect
)
296 rect
= wxRectFromRECT(rc
);
300 inline void wxCopyRectToRECT(const wxRect
& rect
, RECT
& rc
)
302 // note that we don't use wxRect::GetRight() as it is one of compared to
303 // wxRectFromRECT() above
306 rc
.right
= rect
.x
+ rect
.width
;
307 rc
.bottom
= rect
.y
+ rect
.height
;
310 // translations between HIMETRIC units (which OLE likes) and pixels (which are
311 // liked by all the others) - implemented in msw/utilsexc.cpp
312 extern void HIMETRICToPixel(LONG
*x
, LONG
*y
);
313 extern void HIMETRICToPixel(LONG
*x
, LONG
*y
, HDC hdcRef
);
314 extern void PixelToHIMETRIC(LONG
*x
, LONG
*y
);
315 extern void PixelToHIMETRIC(LONG
*x
, LONG
*y
, HDC hdcRef
);
317 // Windows convention of the mask is opposed to the wxWidgets one, so we need
318 // to invert the mask each time we pass one/get one to/from Windows
319 extern HBITMAP
wxInvertMask(HBITMAP hbmpMask
, int w
= 0, int h
= 0);
321 // Creates an icon or cursor depending from a bitmap
323 // The bitmap must be valid and it should have a mask. If it doesn't, a default
324 // mask is created using light grey as the transparent colour.
325 extern HICON
wxBitmapToHICON(const wxBitmap
& bmp
);
327 // Same requirments as above apply and the bitmap must also have the correct
330 HCURSOR
wxBitmapToHCURSOR(const wxBitmap
& bmp
, int hotSpotX
, int hotSpotY
);
333 #if wxUSE_OWNER_DRAWN
335 // Draw the bitmap in specified state (this is used by owner drawn controls)
344 BOOL
wxDrawStateBitmap(HDC hDC
, HBITMAP hBitmap
, int x
, int y
, UINT uState
);
346 #endif // wxUSE_OWNER_DRAWN
348 // get (x, y) from DWORD - notice that HI/LOWORD can *not* be used because they
349 // will fail on system with multiple monitors where the coords may be negative
351 // these macros are standard now (Win98) but some older headers don't have them
353 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
354 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
355 #endif // GET_X_LPARAM
357 // get the current state of SHIFT/CTRL/ALT keys
358 inline bool wxIsModifierDown(int vk
)
360 // GetKeyState() returns different negative values on WinME and WinNT,
361 // so simply test for negative value.
362 return ::GetKeyState(vk
) < 0;
365 inline bool wxIsShiftDown()
367 return wxIsModifierDown(VK_SHIFT
);
370 inline bool wxIsCtrlDown()
372 return wxIsModifierDown(VK_CONTROL
);
375 inline bool wxIsAltDown()
377 return wxIsModifierDown(VK_MENU
);
380 inline bool wxIsAnyModifierDown()
382 return wxIsShiftDown() || wxIsCtrlDown() || wxIsAltDown();
385 // wrapper around GetWindowRect() and GetClientRect() APIs doing error checking
387 inline RECT
wxGetWindowRect(HWND hwnd
)
391 if ( !::GetWindowRect(hwnd
, &rect
) )
393 wxLogLastError(wxT("GetWindowRect"));
399 inline RECT
wxGetClientRect(HWND hwnd
)
403 if ( !::GetClientRect(hwnd
, &rect
) )
405 wxLogLastError(wxT("GetClientRect"));
411 // ---------------------------------------------------------------------------
412 // small helper classes
413 // ---------------------------------------------------------------------------
415 // create an instance of this class and use it as the HDC for screen, will
416 // automatically release the DC going out of scope
420 ScreenHDC() { m_hdc
= ::GetDC(NULL
); }
421 ~ScreenHDC() { ::ReleaseDC(NULL
, m_hdc
); }
423 operator HDC() const { return m_hdc
; }
428 wxDECLARE_NO_COPY_CLASS(ScreenHDC
);
431 // the same as ScreenHDC but for window DCs
435 WindowHDC() : m_hwnd(NULL
), m_hdc(NULL
) { }
436 WindowHDC(HWND hwnd
) { m_hdc
= ::GetDC(m_hwnd
= hwnd
); }
437 ~WindowHDC() { if ( m_hwnd
&& m_hdc
) { ::ReleaseDC(m_hwnd
, m_hdc
); } }
439 operator HDC() const { return m_hdc
; }
445 wxDECLARE_NO_COPY_CLASS(WindowHDC
);
448 // the same as ScreenHDC but for memory DCs: creates the HDC compatible with
449 // the given one (screen by default) in ctor and destroys it in dtor
453 MemoryHDC(HDC hdc
= 0) { m_hdc
= ::CreateCompatibleDC(hdc
); }
454 ~MemoryHDC() { ::DeleteDC(m_hdc
); }
456 operator HDC() const { return m_hdc
; }
461 wxDECLARE_NO_COPY_CLASS(MemoryHDC
);
464 // a class which selects a GDI object into a DC in its ctor and deselects in
469 void DoInit(HGDIOBJ hgdiobj
) { m_hgdiobj
= ::SelectObject(m_hdc
, hgdiobj
); }
472 SelectInHDC() : m_hdc(NULL
), m_hgdiobj(NULL
) { }
473 SelectInHDC(HDC hdc
, HGDIOBJ hgdiobj
) : m_hdc(hdc
) { DoInit(hgdiobj
); }
475 void Init(HDC hdc
, HGDIOBJ hgdiobj
)
477 wxASSERT_MSG( !m_hdc
, wxT("initializing twice?") );
484 ~SelectInHDC() { if ( m_hdc
) ::SelectObject(m_hdc
, m_hgdiobj
); }
486 // return true if the object was successfully selected
487 operator bool() const { return m_hgdiobj
!= 0; }
493 wxDECLARE_NO_COPY_CLASS(SelectInHDC
);
496 // a class which cleans up any GDI object
500 AutoGDIObject() { m_gdiobj
= NULL
; }
501 AutoGDIObject(HGDIOBJ gdiobj
) : m_gdiobj(gdiobj
) { }
502 ~AutoGDIObject() { if ( m_gdiobj
) ::DeleteObject(m_gdiobj
); }
504 void InitGdiobj(HGDIOBJ gdiobj
)
506 wxASSERT_MSG( !m_gdiobj
, wxT("initializing twice?") );
511 HGDIOBJ
GetObject() const { return m_gdiobj
; }
517 // TODO: all this asks for using a AutoHandler<T, CreateFunc> template...
519 // a class for temporary brushes
520 class AutoHBRUSH
: private AutoGDIObject
523 AutoHBRUSH(COLORREF col
)
524 : AutoGDIObject(::CreateSolidBrush(col
)) { }
526 operator HBRUSH() const { return (HBRUSH
)GetObject(); }
529 // a class for temporary fonts
530 class AutoHFONT
: private AutoGDIObject
535 : AutoGDIObject() { }
537 AutoHFONT(const LOGFONT
& lf
)
538 : AutoGDIObject(::CreateFontIndirect(&lf
)) { }
540 void Init(const LOGFONT
& lf
) { InitGdiobj(::CreateFontIndirect(&lf
)); }
542 operator HFONT() const { return (HFONT
)GetObject(); }
545 // a class for temporary pens
546 class AutoHPEN
: private AutoGDIObject
549 AutoHPEN(COLORREF col
)
550 : AutoGDIObject(::CreatePen(PS_SOLID
, 0, col
)) { }
552 operator HPEN() const { return (HPEN
)GetObject(); }
555 // classes for temporary bitmaps
556 class AutoHBITMAP
: private AutoGDIObject
560 : AutoGDIObject() { }
562 AutoHBITMAP(HBITMAP hbmp
) : AutoGDIObject(hbmp
) { }
564 void Init(HBITMAP hbmp
) { InitGdiobj(hbmp
); }
566 operator HBITMAP() const { return (HBITMAP
)GetObject(); }
569 class CompatibleBitmap
: public AutoHBITMAP
572 CompatibleBitmap(HDC hdc
, int w
, int h
)
573 : AutoHBITMAP(::CreateCompatibleBitmap(hdc
, w
, h
))
578 class MonoBitmap
: public AutoHBITMAP
581 MonoBitmap(int w
, int h
)
582 : AutoHBITMAP(::CreateBitmap(w
, h
, 1, 1, 0))
587 // class automatically destroys the region object
588 class AutoHRGN
: private AutoGDIObject
591 AutoHRGN(HRGN hrgn
) : AutoGDIObject(hrgn
) { }
593 operator HRGN() const { return (HRGN
)GetObject(); }
596 // class sets the specified clipping region during its life time
600 HDCClipper(HDC hdc
, HRGN hrgn
)
603 if ( !::SelectClipRgn(hdc
, hrgn
) )
605 wxLogLastError(wxT("SelectClipRgn"));
611 ::SelectClipRgn(m_hdc
, NULL
);
617 wxDECLARE_NO_COPY_CLASS(HDCClipper
);
620 // set the given map mode for the life time of this object
622 // NB: SetMapMode() is not supported by CE so we also define a helper macro
623 // to avoid using it there
625 #define wxCHANGE_HDC_MAP_MODE(hdc, mm)
626 #else // !__WXWINCE__
627 class HDCMapModeChanger
630 HDCMapModeChanger(HDC hdc
, int mm
)
633 m_modeOld
= ::SetMapMode(hdc
, mm
);
636 wxLogLastError(wxT("SelectClipRgn"));
643 ::SetMapMode(m_hdc
, m_modeOld
);
650 wxDECLARE_NO_COPY_CLASS(HDCMapModeChanger
);
653 #define wxCHANGE_HDC_MAP_MODE(hdc, mm) \
654 HDCMapModeChanger wxMAKE_UNIQUE_NAME(wxHDCMapModeChanger)(hdc, mm)
655 #endif // __WXWINCE__/!__WXWINCE__
657 // smart pointer using GlobalAlloc/GlobalFree()
661 // default ctor, call Init() later
667 // allocates a block of given size
668 void Init(size_t size
, unsigned flags
= GMEM_MOVEABLE
)
670 m_hGlobal
= ::GlobalAlloc(flags
, size
);
673 wxLogLastError(wxT("GlobalAlloc"));
677 GlobalPtr(size_t size
, unsigned flags
= GMEM_MOVEABLE
)
684 if ( m_hGlobal
&& ::GlobalFree(m_hGlobal
) )
686 wxLogLastError(wxT("GlobalFree"));
690 // implicit conversion
691 operator HGLOBAL() const { return m_hGlobal
; }
696 wxDECLARE_NO_COPY_CLASS(GlobalPtr
);
699 // when working with global pointers (which is unfortunately still necessary
700 // sometimes, e.g. for clipboard) it is important to unlock them exactly as
701 // many times as we lock them which just asks for using a "smart lock" class
705 // default ctor, use Init() later -- should only be used if the HGLOBAL can
706 // be NULL (in which case Init() shouldn't be called)
713 // initialize the object, may be only called if we were created using the
714 // default ctor; HGLOBAL must not be NULL
715 void Init(HGLOBAL hGlobal
)
719 // NB: GlobalLock() is a macro, not a function, hence don't use the
720 // global scope operator with it (and neither with GlobalUnlock())
721 m_ptr
= GlobalLock(hGlobal
);
724 wxLogLastError(wxT("GlobalLock"));
728 // initialize the object, HGLOBAL must not be NULL
729 GlobalPtrLock(HGLOBAL hGlobal
)
736 if ( m_hGlobal
&& !GlobalUnlock(m_hGlobal
) )
738 // this might happen simply because the block became unlocked
739 DWORD dwLastError
= ::GetLastError();
740 if ( dwLastError
!= NO_ERROR
)
742 wxLogApiError(wxT("GlobalUnlock"), dwLastError
);
747 void *Get() const { return m_ptr
; }
748 operator void *() const { return m_ptr
; }
754 wxDECLARE_NO_COPY_CLASS(GlobalPtrLock
);
757 // register the class when it is first needed and unregister it in dtor
761 // ctor doesn't register the class, call Initialize() for this
762 ClassRegistrar() { m_registered
= -1; }
764 // return true if the class is already registered
765 bool IsInitialized() const { return m_registered
!= -1; }
767 // return true if the class had been already registered
768 bool IsRegistered() const { return m_registered
== 1; }
770 // try to register the class if not done yet, return true on success
771 bool Register(const WNDCLASS
& wc
)
773 // we should only be called if we hadn't been initialized yet
774 wxASSERT_MSG( m_registered
== -1,
775 wxT("calling ClassRegistrar::Register() twice?") );
777 m_registered
= ::RegisterClass(&wc
) ? 1 : 0;
778 if ( !IsRegistered() )
780 wxLogLastError(wxT("RegisterClassEx()"));
784 m_clsname
= wc
.lpszClassName
;
787 return m_registered
== 1;
790 // get the name of the registered class (returns empty string if not
792 const wxString
& GetName() const { return m_clsname
; }
794 // unregister the class if it had been registered
797 if ( IsRegistered() )
799 if ( !::UnregisterClass(m_clsname
.t_str(), wxGetInstance()) )
801 wxLogLastError(wxT("UnregisterClass"));
807 // initial value is -1 which means that we hadn't tried registering the
808 // class yet, it becomes true or false (1 or 0) when Initialize() is called
811 // the name of the class, only non empty if it had been registered
815 // ---------------------------------------------------------------------------
816 // macros to make casting between WXFOO and FOO a bit easier: the GetFoo()
817 // returns Foo cast to the Windows type for oruselves, while GetFooOf() takes
818 // an argument which should be a pointer or reference to the object of the
819 // corresponding class (this depends on the macro)
820 // ---------------------------------------------------------------------------
822 #define GetHwnd() ((HWND)GetHWND())
823 #define GetHwndOf(win) ((HWND)((win)->GetHWND()))
825 #define GetWinHwnd GetHwndOf
827 #define GetHdc() ((HDC)GetHDC())
828 #define GetHdcOf(dc) ((HDC)(dc).GetHDC())
830 #define GetHbitmap() ((HBITMAP)GetHBITMAP())
831 #define GetHbitmapOf(bmp) ((HBITMAP)(bmp).GetHBITMAP())
833 #define GetHicon() ((HICON)GetHICON())
834 #define GetHiconOf(icon) ((HICON)(icon).GetHICON())
836 #define GetHaccel() ((HACCEL)GetHACCEL())
837 #define GetHaccelOf(table) ((HACCEL)((table).GetHACCEL()))
839 #define GetHbrush() ((HBRUSH)GetResourceHandle())
840 #define GetHbrushOf(brush) ((HBRUSH)(brush).GetResourceHandle())
842 #define GetHmenu() ((HMENU)GetHMenu())
843 #define GetHmenuOf(menu) ((HMENU)(menu)->GetHMenu())
845 #define GetHcursor() ((HCURSOR)GetHCURSOR())
846 #define GetHcursorOf(cursor) ((HCURSOR)(cursor).GetHCURSOR())
848 #define GetHfont() ((HFONT)GetHFONT())
849 #define GetHfontOf(font) ((HFONT)(font).GetHFONT())
851 #define GetHimagelist() ((HIMAGELIST)GetHIMAGELIST())
852 #define GetHimagelistOf(imgl) ((HIMAGELIST)(imgl)->GetHIMAGELIST())
854 #define GetHpalette() ((HPALETTE)GetHPALETTE())
855 #define GetHpaletteOf(pal) ((HPALETTE)(pal).GetHPALETTE())
857 #define GetHpen() ((HPEN)GetResourceHandle())
858 #define GetHpenOf(pen) ((HPEN)(pen).GetResourceHandle())
860 #define GetHrgn() ((HRGN)GetHRGN())
861 #define GetHrgnOf(rgn) ((HRGN)(rgn).GetHRGN())
865 // ---------------------------------------------------------------------------
867 // ---------------------------------------------------------------------------
869 // return the full path of the given module
870 inline wxString
wxGetFullModuleName(HMODULE hmod
)
873 if ( !::GetModuleFileName
876 wxStringBuffer(fullname
, MAX_PATH
),
880 wxLogLastError(wxT("GetModuleFileName"));
886 // return the full path of the program file
887 inline wxString
wxGetFullModuleName()
889 return wxGetFullModuleName((HMODULE
)wxGetInstance());
892 // return the run-time version of the OS in a format similar to
893 // WINVER/_WIN32_WINNT compile-time macros:
895 // 0x0300 Windows NT 3.51
896 // 0x0400 Windows 95, NT4
898 // 0x0500 Windows ME, 2000
899 // 0x0501 Windows XP, 2003
900 // 0x0502 Windows XP SP2, 2003 SP1
901 // 0x0600 Windows Vista, 2008
904 // for the other Windows versions 0 is currently returned
907 wxWinVersion_Unknown
= 0,
909 wxWinVersion_3
= 0x0300,
910 wxWinVersion_NT3
= wxWinVersion_3
,
912 wxWinVersion_4
= 0x0400,
913 wxWinVersion_95
= wxWinVersion_4
,
914 wxWinVersion_NT4
= wxWinVersion_4
,
915 wxWinVersion_98
= 0x0410,
917 wxWinVersion_5
= 0x0500,
918 wxWinVersion_ME
= wxWinVersion_5
,
919 wxWinVersion_NT5
= wxWinVersion_5
,
920 wxWinVersion_2000
= wxWinVersion_5
,
921 wxWinVersion_XP
= 0x0501,
922 wxWinVersion_2003
= 0x0501,
923 wxWinVersion_XP_SP2
= 0x0502,
924 wxWinVersion_2003_SP1
= 0x0502,
926 wxWinVersion_6
= 0x0600,
927 wxWinVersion_Vista
= wxWinVersion_6
,
928 wxWinVersion_NT6
= wxWinVersion_6
,
930 wxWinVersion_7
= 0x601
933 WXDLLIMPEXP_BASE wxWinVersion
wxGetWinVersion();
938 extern HCURSOR
wxGetCurrentBusyCursor(); // from msw/utils.cpp
939 extern const wxCursor
*wxGetGlobalCursor(); // from msw/cursor.cpp
941 // GetCursorPos can fail without populating the POINT. This falls back to GetMessagePos.
942 WXDLLIMPEXP_CORE
void wxGetCursorPosMSW(POINT
* pt
);
944 WXDLLIMPEXP_CORE
void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
& the_font
);
945 WXDLLIMPEXP_CORE
void wxFillLogFont(LOGFONT
*logFont
, const wxFont
*font
);
946 WXDLLIMPEXP_CORE wxFont
wxCreateFontFromLogFont(const LOGFONT
*logFont
);
947 WXDLLIMPEXP_CORE wxFontEncoding
wxGetFontEncFromCharSet(int charset
);
949 WXDLLIMPEXP_CORE
void wxSliderEvent(WXHWND control
, WXWORD wParam
, WXWORD pos
);
950 WXDLLIMPEXP_CORE
void wxScrollBarEvent(WXHWND hbar
, WXWORD wParam
, WXWORD pos
);
952 // Find maximum size of window/rectangle
953 extern WXDLLIMPEXP_CORE
void wxFindMaxSize(WXHWND hwnd
, RECT
*rect
);
955 // Safely get the window text (i.e. without using fixed size buffer)
956 extern WXDLLIMPEXP_CORE wxString
wxGetWindowText(WXHWND hWnd
);
958 // get the window class name
959 extern WXDLLIMPEXP_CORE wxString
wxGetWindowClass(WXHWND hWnd
);
961 // get the window id (should be unsigned, hence this is not wxWindowID which
962 // is, for mainly historical reasons, signed)
963 extern WXDLLIMPEXP_CORE
int wxGetWindowId(WXHWND hWnd
);
965 // check if hWnd's WNDPROC is wndProc. Return true if yes, false if they are
967 extern WXDLLIMPEXP_CORE
bool wxCheckWindowWndProc(WXHWND hWnd
, WXFARPROC wndProc
);
969 // Does this window style specify any border?
970 inline bool wxStyleHasBorder(long style
)
972 return (style
& (wxSIMPLE_BORDER
| wxRAISED_BORDER
|
973 wxSUNKEN_BORDER
| wxDOUBLE_BORDER
)) != 0;
976 inline long wxGetWindowExStyle(const wxWindowMSW
*win
)
978 return ::GetWindowLong(GetHwndOf(win
), GWL_EXSTYLE
);
981 inline bool wxHasWindowExStyle(const wxWindowMSW
*win
, long style
)
983 return (wxGetWindowExStyle(win
) & style
) != 0;
986 inline long wxSetWindowExStyle(const wxWindowMSW
*win
, long style
)
988 return ::SetWindowLong(GetHwndOf(win
), GWL_EXSTYLE
, style
);
991 // ----------------------------------------------------------------------------
992 // functions mapping HWND to wxWindow
993 // ----------------------------------------------------------------------------
995 // this function simply checks whether the given hwnd corresponds to a wxWindow
996 // and returns either that window if it does or NULL otherwise
997 extern WXDLLIMPEXP_CORE wxWindow
* wxFindWinFromHandle(HWND hwnd
);
999 // find the window for HWND which is part of some wxWindow, i.e. unlike
1000 // wxFindWinFromHandle() above it will also work for "sub controls" of a
1003 // returns the wxWindow corresponding to the given HWND or NULL.
1004 extern WXDLLIMPEXP_CORE wxWindow
*wxGetWindowFromHWND(WXHWND hwnd
);
1006 // Get the size of an icon
1007 extern WXDLLIMPEXP_CORE wxSize
wxGetHiconSize(HICON hicon
);
1009 // Lines are drawn differently for WinCE and regular WIN32
1010 WXDLLIMPEXP_CORE
void wxDrawLine(HDC hdc
, int x1
, int y1
, int x2
, int y2
);
1012 // fill the client rect of the given window on the provided dc using this brush
1013 inline void wxFillRect(HWND hwnd
, HDC hdc
, HBRUSH hbr
)
1016 ::GetClientRect(hwnd
, &rc
);
1017 ::FillRect(hdc
, &rc
, hbr
);
1020 // ----------------------------------------------------------------------------
1021 // 32/64 bit helpers
1022 // ----------------------------------------------------------------------------
1026 inline void *wxGetWindowProc(HWND hwnd
)
1028 return (void *)::GetWindowLongPtr(hwnd
, GWLP_WNDPROC
);
1031 inline void *wxGetWindowUserData(HWND hwnd
)
1033 return (void *)::GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
1036 inline WNDPROC
wxSetWindowProc(HWND hwnd
, WNDPROC func
)
1038 return (WNDPROC
)::SetWindowLongPtr(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)func
);
1041 inline void *wxSetWindowUserData(HWND hwnd
, void *data
)
1043 return (void *)::SetWindowLongPtr(hwnd
, GWLP_USERDATA
, (LONG_PTR
)data
);
1048 // note that the casts to LONG_PTR here are required even on 32-bit machines
1049 // for the 64-bit warning mode of later versions of MSVC (C4311/4312)
1050 inline WNDPROC
wxGetWindowProc(HWND hwnd
)
1052 return (WNDPROC
)(LONG_PTR
)::GetWindowLong(hwnd
, GWL_WNDPROC
);
1055 inline void *wxGetWindowUserData(HWND hwnd
)
1057 return (void *)(LONG_PTR
)::GetWindowLong(hwnd
, GWL_USERDATA
);
1060 inline WNDPROC
wxSetWindowProc(HWND hwnd
, WNDPROC func
)
1062 return (WNDPROC
)(LONG_PTR
)::SetWindowLong(hwnd
, GWL_WNDPROC
, (LONG_PTR
)func
);
1065 inline void *wxSetWindowUserData(HWND hwnd
, void *data
)
1067 return (void *)(LONG_PTR
)::SetWindowLong(hwnd
, GWL_USERDATA
, (LONG_PTR
)data
);
1070 #endif // __WIN64__/__WIN32__
1074 #endif // _WX_PRIVATE_H_