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
9 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef _WX_PRIVATE_H_
14 #define _WX_PRIVATE_H_
16 #include "wx/msw/wrapwin.h"
19 // Extra prototypes and symbols not defined by MicroWindows
20 #include "wx/msw/microwin.h"
26 #include "wx/window.h"
29 class WXDLLIMPEXP_FWD_CORE wxFont
;
30 class WXDLLIMPEXP_FWD_CORE wxWindow
;
31 class WXDLLIMPEXP_FWD_CORE wxWindowBase
;
33 // ---------------------------------------------------------------------------
35 // ---------------------------------------------------------------------------
37 // 260 was taken from windef.h
42 // ---------------------------------------------------------------------------
43 // standard icons from the resources
44 // ---------------------------------------------------------------------------
48 extern WXDLLIMPEXP_DATA_CORE(HICON
) wxSTD_FRAME_ICON
;
49 extern WXDLLIMPEXP_DATA_CORE(HICON
) wxSTD_MDIPARENTFRAME_ICON
;
50 extern WXDLLIMPEXP_DATA_CORE(HICON
) wxSTD_MDICHILDFRAME_ICON
;
51 extern WXDLLIMPEXP_DATA_CORE(HICON
) wxDEFAULT_FRAME_ICON
;
52 extern WXDLLIMPEXP_DATA_CORE(HICON
) wxDEFAULT_MDIPARENTFRAME_ICON
;
53 extern WXDLLIMPEXP_DATA_CORE(HICON
) wxDEFAULT_MDICHILDFRAME_ICON
;
54 extern WXDLLIMPEXP_DATA_CORE(HFONT
) wxSTATUS_LINE_FONT
;
58 // ---------------------------------------------------------------------------
60 // ---------------------------------------------------------------------------
62 extern WXDLLIMPEXP_DATA_BASE(HINSTANCE
) wxhInstance
;
66 WXDLLIMPEXP_BASE HINSTANCE
wxGetInstance();
69 WXDLLIMPEXP_BASE
void wxSetInstance(HINSTANCE hInst
);
71 // ---------------------------------------------------------------------------
72 // define things missing from some compilers' headers
73 // ---------------------------------------------------------------------------
75 #if defined(__WXWINCE__) || (defined(__GNUWIN32__) && !wxUSE_NORLANDER_HEADERS)
77 inline void ZeroMemory(void *buf
, size_t len
) { memset(buf
, 0, len
); }
81 // this defines a CASTWNDPROC macro which casts a pointer to the type of a
83 #if defined(STRICT) || defined(__GNUC__)
84 typedef WNDPROC WndProcCast
;
86 typedef FARPROC WndProcCast
;
90 #define CASTWNDPROC (WndProcCast)
94 // ---------------------------------------------------------------------------
95 // some stuff for old Windows versions (FIXME: what does it do here??)
96 // ---------------------------------------------------------------------------
98 #if !defined(APIENTRY) // NT defines APIENTRY, 3.x not
99 #define APIENTRY FAR PASCAL
105 #define _EXPORT _export
109 typedef signed short int SHORT
;
112 #if !defined(__WIN32__) // 3.x uses FARPROC for dialogs
114 #define DLGPROC FARPROC
119 * Decide what window classes we're going to use
120 * for this combination of CTl3D/FAFA settings
123 #define STATIC_CLASS wxT("STATIC")
124 #define STATIC_FLAGS (SS_LEFT|WS_CHILD|WS_VISIBLE)
125 #define CHECK_CLASS wxT("BUTTON")
126 #define CHECK_FLAGS (BS_AUTOCHECKBOX|WS_TABSTOP|WS_CHILD)
127 #define CHECK_IS_FAFA FALSE
128 #define RADIO_CLASS wxT("BUTTON")
129 #define RADIO_FLAGS (BS_AUTORADIOBUTTON|WS_CHILD|WS_VISIBLE)
130 #define RADIO_SIZE 20
131 #define RADIO_IS_FAFA FALSE
133 #define GROUP_CLASS wxT("BUTTON")
134 #define GROUP_FLAGS (BS_GROUPBOX|WS_CHILD|WS_VISIBLE)
137 #define BITCHECK_FLAGS (FB_BITMAP|FC_BUTTONDRAW|FC_DEFAULT|WS_VISIBLE)
138 #define BITRADIO_FLAGS (FC_BUTTONDRAW|FB_BITMAP|FC_RADIO|WS_CHILD|WS_VISIBLE)
141 // ---------------------------------------------------------------------------
143 // ---------------------------------------------------------------------------
145 #define MEANING_CHARACTER '0'
146 #define DEFAULT_ITEM_WIDTH 100
147 #define DEFAULT_ITEM_HEIGHT 80
149 // Scale font to get edit control height
150 //#define EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) (3*(cy)/2)
151 #define EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) (cy+8)
153 // Generic subclass proc, for panel item moving/sizing and intercept
154 // EDIT control VK_RETURN messages
155 extern LONG APIENTRY _EXPORT
156 wxSubclassedGenericControlProc(WXHWND hWnd
, WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
);
158 // ---------------------------------------------------------------------------
159 // useful macros and functions
160 // ---------------------------------------------------------------------------
162 // a wrapper macro for ZeroMemory()
163 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
164 #define wxZeroMemory(obj) ::ZeroMemory(&obj, sizeof(obj))
166 #define wxZeroMemory(obj) memset((void*) & obj, 0, sizeof(obj))
169 // This one is a macro so that it can be tested with #ifdef, it will be
170 // undefined if it cannot be implemented for a given compiler.
171 // Vc++, bcc, dmc, ow, mingw akk have _get_osfhandle() and Cygwin has
172 // get_osfhandle. Others are currently unknown, e.g. Salford, Intel, Visual
174 #if defined(__WXWINCE__)
175 #define wxGetOSFHandle(fd) ((HANDLE)fd)
176 #define wxOpenOSFHandle(h, flags) ((int)wxPtrToUInt(h))
177 #elif defined(__CYGWIN__)
178 #define wxGetOSFHandle(fd) ((HANDLE)get_osfhandle(fd))
179 #elif defined(__VISUALC__) \
180 || defined(__BORLANDC__) \
181 || defined(__DMC__) \
182 || defined(__WATCOMC__) \
183 || defined(__MINGW32__)
184 #define wxGetOSFHandle(fd) ((HANDLE)_get_osfhandle(fd))
185 #define wxOpenOSFHandle(h, flags) (_open_osfhandle(wxPtrToUInt(h), flags))
186 #define wx_fdopen _fdopen
189 // close the handle in the class dtor
193 wxEXPLICIT
AutoHANDLE(HANDLE handle
) : m_handle(handle
) { }
195 bool IsOk() const { return m_handle
!= INVALID_HANDLE_VALUE
; }
196 operator HANDLE() const { return m_handle
; }
198 ~AutoHANDLE() { if ( IsOk() ) ::CloseHandle(m_handle
); }
204 // a template to make initializing Windows styructs less painful: it zeroes all
205 // the struct fields and also sets cbSize member to the correct value (and so
206 // can be only used with structures which have this member...)
208 struct WinStruct
: public T
212 ::ZeroMemory(this, sizeof(T
));
214 // explicit qualification is required here for this to be valid C++
215 this->cbSize
= sizeof(T
);
220 // Macros for converting wxString to the type expected by API functions.
222 // Normally it is enough to just use wxString::t_str() which is implicitly
223 // convertible to LPCTSTR, but in some cases an explicit conversion is required.
225 // In such cases wxMSW_CONV_LPCTSTR() should be used. But if an API function
226 // takes a non-const pointer, wxMSW_CONV_LPTSTR() which casts away the
227 // constness (but doesn't make it possible to really modify the returned
228 // pointer, of course) should be used. And if a string is passed as LPARAM, use
229 // wxMSW_CONV_LPARAM() which does the required ugly reinterpret_cast<> too.
230 #define wxMSW_CONV_LPCTSTR(s) static_cast<const wxChar *>((s).t_str())
231 #define wxMSW_CONV_LPTSTR(s) const_cast<wxChar *>(wxMSW_CONV_LPCTSTR(s))
232 #define wxMSW_CONV_LPARAM(s) reinterpret_cast<LPARAM>(wxMSW_CONV_LPCTSTR(s))
237 #include "wx/gdicmn.h"
238 #include "wx/colour.h"
240 // make conversion from wxColour and COLORREF a bit less painful
241 inline COLORREF
wxColourToRGB(const wxColour
& c
)
243 return RGB(c
.Red(), c
.Green(), c
.Blue());
246 inline COLORREF
wxColourToPalRGB(const wxColour
& c
)
248 return PALETTERGB(c
.Red(), c
.Green(), c
.Blue());
251 inline wxColour
wxRGBToColour(COLORREF rgb
)
253 return wxColour(GetRValue(rgb
), GetGValue(rgb
), GetBValue(rgb
));
256 inline void wxRGBToColour(wxColour
& c
, COLORREF rgb
)
258 c
.Set(GetRValue(rgb
), GetGValue(rgb
), GetBValue(rgb
));
261 // get the standard colour map for some standard colours - see comment in this
262 // function to understand why is it needed and when should it be used
264 // it returns a wxCOLORMAP (can't use COLORMAP itself here as comctl32.dll
265 // might be not included/available) array of size wxSTD_COLOUR_MAX
267 // NB: if you change these colours, update wxBITMAP_STD_COLOURS in the
268 // resources as well: it must have the same number of pixels!
274 wxSTD_COL_BTNHIGHLIGHT
,
278 struct WXDLLIMPEXP_CORE wxCOLORMAP
283 // this function is implemented in src/msw/window.cpp
284 extern wxCOLORMAP
*wxGetStdColourMap();
286 // create a wxRect from Windows RECT
287 inline wxRect
wxRectFromRECT(const RECT
& rc
)
289 return wxRect(rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
292 // copy Windows RECT to our wxRect
293 inline void wxCopyRECTToRect(const RECT
& rc
, wxRect
& rect
)
295 rect
= wxRectFromRECT(rc
);
299 inline void wxCopyRectToRECT(const wxRect
& rect
, RECT
& rc
)
301 // note that we don't use wxRect::GetRight() as it is one of compared to
302 // wxRectFromRECT() above
305 rc
.right
= rect
.x
+ rect
.width
;
306 rc
.bottom
= rect
.y
+ rect
.height
;
309 // translations between HIMETRIC units (which OLE likes) and pixels (which are
310 // liked by all the others) - implemented in msw/utilsexc.cpp
311 extern void HIMETRICToPixel(LONG
*x
, LONG
*y
);
312 extern void HIMETRICToPixel(LONG
*x
, LONG
*y
, HDC hdcRef
);
313 extern void PixelToHIMETRIC(LONG
*x
, LONG
*y
);
314 extern void PixelToHIMETRIC(LONG
*x
, LONG
*y
, HDC hdcRef
);
316 // Windows convention of the mask is opposed to the wxWidgets one, so we need
317 // to invert the mask each time we pass one/get one to/from Windows
318 extern HBITMAP
wxInvertMask(HBITMAP hbmpMask
, int w
= 0, int h
= 0);
320 // Creates an icon or cursor depending from a bitmap
322 // The bitmap must be valid and it should have a mask. If it doesn't, a default
323 // mask is created using light grey as the transparent colour.
324 extern HICON
wxBitmapToHICON(const wxBitmap
& bmp
);
326 // Same requirments as above apply and the bitmap must also have the correct
329 HCURSOR
wxBitmapToHCURSOR(const wxBitmap
& bmp
, int hotSpotX
, int hotSpotY
);
332 #if wxUSE_OWNER_DRAWN
334 // Draw the bitmap in specified state (this is used by owner drawn controls)
343 BOOL
wxDrawStateBitmap(HDC hDC
, HBITMAP hBitmap
, int x
, int y
, UINT uState
);
345 #endif // wxUSE_OWNER_DRAWN
347 // get (x, y) from DWORD - notice that HI/LOWORD can *not* be used because they
348 // will fail on system with multiple monitors where the coords may be negative
350 // these macros are standard now (Win98) but some older headers don't have them
352 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
353 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
354 #endif // GET_X_LPARAM
356 // get the current state of SHIFT/CTRL/ALT keys
357 inline bool wxIsModifierDown(int vk
)
359 // GetKeyState() returns different negative values on WinME and WinNT,
360 // so simply test for negative value.
361 return ::GetKeyState(vk
) < 0;
364 inline bool wxIsShiftDown()
366 return wxIsModifierDown(VK_SHIFT
);
369 inline bool wxIsCtrlDown()
371 return wxIsModifierDown(VK_CONTROL
);
374 inline bool wxIsAltDown()
376 return wxIsModifierDown(VK_MENU
);
379 inline bool wxIsAnyModifierDown()
381 return wxIsShiftDown() || wxIsCtrlDown() || wxIsAltDown();
384 // wrapper around GetWindowRect() and GetClientRect() APIs doing error checking
386 inline RECT
wxGetWindowRect(HWND hwnd
)
390 if ( !::GetWindowRect(hwnd
, &rect
) )
392 wxLogLastError(wxT("GetWindowRect"));
398 inline RECT
wxGetClientRect(HWND hwnd
)
402 if ( !::GetClientRect(hwnd
, &rect
) )
404 wxLogLastError(wxT("GetClientRect"));
410 // ---------------------------------------------------------------------------
411 // small helper classes
412 // ---------------------------------------------------------------------------
414 // create an instance of this class and use it as the HDC for screen, will
415 // automatically release the DC going out of scope
419 ScreenHDC() { m_hdc
= ::GetDC(NULL
); }
420 ~ScreenHDC() { ::ReleaseDC(NULL
, m_hdc
); }
422 operator HDC() const { return m_hdc
; }
427 wxDECLARE_NO_COPY_CLASS(ScreenHDC
);
430 // the same as ScreenHDC but for window DCs
434 WindowHDC() : m_hwnd(NULL
), m_hdc(NULL
) { }
435 WindowHDC(HWND hwnd
) { m_hdc
= ::GetDC(m_hwnd
= hwnd
); }
436 ~WindowHDC() { if ( m_hwnd
&& m_hdc
) { ::ReleaseDC(m_hwnd
, m_hdc
); } }
438 operator HDC() const { return m_hdc
; }
444 wxDECLARE_NO_COPY_CLASS(WindowHDC
);
447 // the same as ScreenHDC but for memory DCs: creates the HDC compatible with
448 // the given one (screen by default) in ctor and destroys it in dtor
452 MemoryHDC(HDC hdc
= 0) { m_hdc
= ::CreateCompatibleDC(hdc
); }
453 ~MemoryHDC() { ::DeleteDC(m_hdc
); }
455 operator HDC() const { return m_hdc
; }
460 wxDECLARE_NO_COPY_CLASS(MemoryHDC
);
463 // a class which selects a GDI object into a DC in its ctor and deselects in
468 void DoInit(HGDIOBJ hgdiobj
) { m_hgdiobj
= ::SelectObject(m_hdc
, hgdiobj
); }
471 SelectInHDC() : m_hdc(NULL
), m_hgdiobj(NULL
) { }
472 SelectInHDC(HDC hdc
, HGDIOBJ hgdiobj
) : m_hdc(hdc
) { DoInit(hgdiobj
); }
474 void Init(HDC hdc
, HGDIOBJ hgdiobj
)
476 wxASSERT_MSG( !m_hdc
, wxT("initializing twice?") );
483 ~SelectInHDC() { if ( m_hdc
) ::SelectObject(m_hdc
, m_hgdiobj
); }
485 // return true if the object was successfully selected
486 operator bool() const { return m_hgdiobj
!= 0; }
492 wxDECLARE_NO_COPY_CLASS(SelectInHDC
);
495 // a class which cleans up any GDI object
499 AutoGDIObject() { m_gdiobj
= NULL
; }
500 AutoGDIObject(HGDIOBJ gdiobj
) : m_gdiobj(gdiobj
) { }
501 ~AutoGDIObject() { if ( m_gdiobj
) ::DeleteObject(m_gdiobj
); }
503 void InitGdiobj(HGDIOBJ gdiobj
)
505 wxASSERT_MSG( !m_gdiobj
, wxT("initializing twice?") );
510 HGDIOBJ
GetObject() const { return m_gdiobj
; }
516 // TODO: all this asks for using a AutoHandler<T, CreateFunc> template...
518 // a class for temporary brushes
519 class AutoHBRUSH
: private AutoGDIObject
522 AutoHBRUSH(COLORREF col
)
523 : AutoGDIObject(::CreateSolidBrush(col
)) { }
525 operator HBRUSH() const { return (HBRUSH
)GetObject(); }
528 // a class for temporary fonts
529 class AutoHFONT
: private AutoGDIObject
534 : AutoGDIObject() { }
536 AutoHFONT(const LOGFONT
& lf
)
537 : AutoGDIObject(::CreateFontIndirect(&lf
)) { }
539 void Init(const LOGFONT
& lf
) { InitGdiobj(::CreateFontIndirect(&lf
)); }
541 operator HFONT() const { return (HFONT
)GetObject(); }
544 // a class for temporary pens
545 class AutoHPEN
: private AutoGDIObject
548 AutoHPEN(COLORREF col
)
549 : AutoGDIObject(::CreatePen(PS_SOLID
, 0, col
)) { }
551 operator HPEN() const { return (HPEN
)GetObject(); }
554 // classes for temporary bitmaps
555 class AutoHBITMAP
: private AutoGDIObject
559 : AutoGDIObject() { }
561 AutoHBITMAP(HBITMAP hbmp
) : AutoGDIObject(hbmp
) { }
563 void Init(HBITMAP hbmp
) { InitGdiobj(hbmp
); }
565 operator HBITMAP() const { return (HBITMAP
)GetObject(); }
568 class CompatibleBitmap
: public AutoHBITMAP
571 CompatibleBitmap(HDC hdc
, int w
, int h
)
572 : AutoHBITMAP(::CreateCompatibleBitmap(hdc
, w
, h
))
577 class MonoBitmap
: public AutoHBITMAP
580 MonoBitmap(int w
, int h
)
581 : AutoHBITMAP(::CreateBitmap(w
, h
, 1, 1, 0))
586 // class automatically destroys the region object
587 class AutoHRGN
: private AutoGDIObject
590 AutoHRGN(HRGN hrgn
) : AutoGDIObject(hrgn
) { }
592 operator HRGN() const { return (HRGN
)GetObject(); }
595 // class sets the specified clipping region during its life time
599 HDCClipper(HDC hdc
, HRGN hrgn
)
602 if ( !::SelectClipRgn(hdc
, hrgn
) )
604 wxLogLastError(wxT("SelectClipRgn"));
610 ::SelectClipRgn(m_hdc
, NULL
);
616 wxDECLARE_NO_COPY_CLASS(HDCClipper
);
619 // set the given map mode for the life time of this object
621 // NB: SetMapMode() is not supported by CE so we also define a helper macro
622 // to avoid using it there
624 #define wxCHANGE_HDC_MAP_MODE(hdc, mm)
625 #else // !__WXWINCE__
626 class HDCMapModeChanger
629 HDCMapModeChanger(HDC hdc
, int mm
)
632 m_modeOld
= ::SetMapMode(hdc
, mm
);
635 wxLogLastError(wxT("SelectClipRgn"));
642 ::SetMapMode(m_hdc
, m_modeOld
);
649 wxDECLARE_NO_COPY_CLASS(HDCMapModeChanger
);
652 #define wxCHANGE_HDC_MAP_MODE(hdc, mm) \
653 HDCMapModeChanger wxMAKE_UNIQUE_NAME(wxHDCMapModeChanger)(hdc, mm)
654 #endif // __WXWINCE__/!__WXWINCE__
656 // smart pointer using GlobalAlloc/GlobalFree()
660 // default ctor, call Init() later
666 // allocates a block of given size
667 void Init(size_t size
, unsigned flags
= GMEM_MOVEABLE
)
669 m_hGlobal
= ::GlobalAlloc(flags
, size
);
672 wxLogLastError(wxT("GlobalAlloc"));
676 GlobalPtr(size_t size
, unsigned flags
= GMEM_MOVEABLE
)
683 if ( m_hGlobal
&& ::GlobalFree(m_hGlobal
) )
685 wxLogLastError(wxT("GlobalFree"));
689 // implicit conversion
690 operator HGLOBAL() const { return m_hGlobal
; }
695 wxDECLARE_NO_COPY_CLASS(GlobalPtr
);
698 // when working with global pointers (which is unfortunately still necessary
699 // sometimes, e.g. for clipboard) it is important to unlock them exactly as
700 // many times as we lock them which just asks for using a "smart lock" class
704 // default ctor, use Init() later -- should only be used if the HGLOBAL can
705 // be NULL (in which case Init() shouldn't be called)
712 // initialize the object, may be only called if we were created using the
713 // default ctor; HGLOBAL must not be NULL
714 void Init(HGLOBAL hGlobal
)
718 // NB: GlobalLock() is a macro, not a function, hence don't use the
719 // global scope operator with it (and neither with GlobalUnlock())
720 m_ptr
= GlobalLock(hGlobal
);
723 wxLogLastError(wxT("GlobalLock"));
727 // initialize the object, HGLOBAL must not be NULL
728 GlobalPtrLock(HGLOBAL hGlobal
)
735 if ( m_hGlobal
&& !GlobalUnlock(m_hGlobal
) )
737 // this might happen simply because the block became unlocked
738 DWORD dwLastError
= ::GetLastError();
739 if ( dwLastError
!= NO_ERROR
)
741 wxLogApiError(wxT("GlobalUnlock"), dwLastError
);
746 void *Get() const { return m_ptr
; }
747 operator void *() const { return m_ptr
; }
753 wxDECLARE_NO_COPY_CLASS(GlobalPtrLock
);
756 // register the class when it is first needed and unregister it in dtor
760 // ctor doesn't register the class, call Initialize() for this
761 ClassRegistrar() { m_registered
= -1; }
763 // return true if the class is already registered
764 bool IsInitialized() const { return m_registered
!= -1; }
766 // return true if the class had been already registered
767 bool IsRegistered() const { return m_registered
== 1; }
769 // try to register the class if not done yet, return true on success
770 bool Register(const WNDCLASS
& wc
)
772 // we should only be called if we hadn't been initialized yet
773 wxASSERT_MSG( m_registered
== -1,
774 wxT("calling ClassRegistrar::Register() twice?") );
776 m_registered
= ::RegisterClass(&wc
) ? 1 : 0;
777 if ( !IsRegistered() )
779 wxLogLastError(wxT("RegisterClassEx()"));
783 m_clsname
= wc
.lpszClassName
;
786 return m_registered
== 1;
789 // get the name of the registered class (returns empty string if not
791 const wxString
& GetName() const { return m_clsname
; }
793 // unregister the class if it had been registered
796 if ( IsRegistered() )
798 if ( !::UnregisterClass(m_clsname
.t_str(), wxGetInstance()) )
800 wxLogLastError(wxT("UnregisterClass"));
806 // initial value is -1 which means that we hadn't tried registering the
807 // class yet, it becomes true or false (1 or 0) when Initialize() is called
810 // the name of the class, only non empty if it had been registered
814 // ---------------------------------------------------------------------------
815 // macros to make casting between WXFOO and FOO a bit easier: the GetFoo()
816 // returns Foo cast to the Windows type for oruselves, while GetFooOf() takes
817 // an argument which should be a pointer or reference to the object of the
818 // corresponding class (this depends on the macro)
819 // ---------------------------------------------------------------------------
821 #define GetHwnd() ((HWND)GetHWND())
822 #define GetHwndOf(win) ((HWND)((win)->GetHWND()))
824 #define GetWinHwnd GetHwndOf
826 #define GetHdc() ((HDC)GetHDC())
827 #define GetHdcOf(dc) ((HDC)(dc).GetHDC())
829 #define GetHbitmap() ((HBITMAP)GetHBITMAP())
830 #define GetHbitmapOf(bmp) ((HBITMAP)(bmp).GetHBITMAP())
832 #define GetHicon() ((HICON)GetHICON())
833 #define GetHiconOf(icon) ((HICON)(icon).GetHICON())
835 #define GetHaccel() ((HACCEL)GetHACCEL())
836 #define GetHaccelOf(table) ((HACCEL)((table).GetHACCEL()))
838 #define GetHbrush() ((HBRUSH)GetResourceHandle())
839 #define GetHbrushOf(brush) ((HBRUSH)(brush).GetResourceHandle())
841 #define GetHmenu() ((HMENU)GetHMenu())
842 #define GetHmenuOf(menu) ((HMENU)(menu)->GetHMenu())
844 #define GetHcursor() ((HCURSOR)GetHCURSOR())
845 #define GetHcursorOf(cursor) ((HCURSOR)(cursor).GetHCURSOR())
847 #define GetHfont() ((HFONT)GetHFONT())
848 #define GetHfontOf(font) ((HFONT)(font).GetHFONT())
850 #define GetHimagelist() ((HIMAGELIST)GetHIMAGELIST())
851 #define GetHimagelistOf(imgl) ((HIMAGELIST)(imgl)->GetHIMAGELIST())
853 #define GetHpalette() ((HPALETTE)GetHPALETTE())
854 #define GetHpaletteOf(pal) ((HPALETTE)(pal).GetHPALETTE())
856 #define GetHpen() ((HPEN)GetResourceHandle())
857 #define GetHpenOf(pen) ((HPEN)(pen).GetResourceHandle())
859 #define GetHrgn() ((HRGN)GetHRGN())
860 #define GetHrgnOf(rgn) ((HRGN)(rgn).GetHRGN())
864 // ---------------------------------------------------------------------------
866 // ---------------------------------------------------------------------------
868 // return the full path of the given module
869 inline wxString
wxGetFullModuleName(HMODULE hmod
)
872 if ( !::GetModuleFileName
875 wxStringBuffer(fullname
, MAX_PATH
),
879 wxLogLastError(wxT("GetModuleFileName"));
885 // return the full path of the program file
886 inline wxString
wxGetFullModuleName()
888 return wxGetFullModuleName((HMODULE
)wxGetInstance());
891 // return the run-time version of the OS in a format similar to
892 // WINVER/_WIN32_WINNT compile-time macros:
894 // 0x0300 Windows NT 3.51
895 // 0x0400 Windows 95, NT4
897 // 0x0500 Windows ME, 2000
898 // 0x0501 Windows XP, 2003
899 // 0x0502 Windows XP SP2, 2003 SP1
900 // 0x0600 Windows Vista, 2008
903 // for the other Windows versions 0 is currently returned
906 wxWinVersion_Unknown
= 0,
908 wxWinVersion_3
= 0x0300,
909 wxWinVersion_NT3
= wxWinVersion_3
,
911 wxWinVersion_4
= 0x0400,
912 wxWinVersion_95
= wxWinVersion_4
,
913 wxWinVersion_NT4
= wxWinVersion_4
,
914 wxWinVersion_98
= 0x0410,
916 wxWinVersion_5
= 0x0500,
917 wxWinVersion_ME
= wxWinVersion_5
,
918 wxWinVersion_NT5
= wxWinVersion_5
,
919 wxWinVersion_2000
= wxWinVersion_5
,
920 wxWinVersion_XP
= 0x0501,
921 wxWinVersion_2003
= 0x0501,
922 wxWinVersion_XP_SP2
= 0x0502,
923 wxWinVersion_2003_SP1
= 0x0502,
925 wxWinVersion_6
= 0x0600,
926 wxWinVersion_Vista
= wxWinVersion_6
,
927 wxWinVersion_NT6
= wxWinVersion_6
,
929 wxWinVersion_7
= 0x601
932 WXDLLIMPEXP_BASE wxWinVersion
wxGetWinVersion();
934 #if wxUSE_GUI && defined(__WXMSW__)
937 extern HCURSOR
wxGetCurrentBusyCursor(); // from msw/utils.cpp
938 extern const wxCursor
*wxGetGlobalCursor(); // from msw/cursor.cpp
940 // GetCursorPos can fail without populating the POINT. This falls back to GetMessagePos.
941 WXDLLIMPEXP_CORE
void wxGetCursorPosMSW(POINT
* pt
);
943 WXDLLIMPEXP_CORE
void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
& the_font
);
944 WXDLLIMPEXP_CORE
void wxFillLogFont(LOGFONT
*logFont
, const wxFont
*font
);
945 WXDLLIMPEXP_CORE wxFont
wxCreateFontFromLogFont(const LOGFONT
*logFont
);
946 WXDLLIMPEXP_CORE wxFontEncoding
wxGetFontEncFromCharSet(int charset
);
948 WXDLLIMPEXP_CORE
void wxSliderEvent(WXHWND control
, WXWORD wParam
, WXWORD pos
);
949 WXDLLIMPEXP_CORE
void wxScrollBarEvent(WXHWND hbar
, WXWORD wParam
, WXWORD pos
);
951 // Find maximum size of window/rectangle
952 extern WXDLLIMPEXP_CORE
void wxFindMaxSize(WXHWND hwnd
, RECT
*rect
);
954 // Safely get the window text (i.e. without using fixed size buffer)
955 extern WXDLLIMPEXP_CORE wxString
wxGetWindowText(WXHWND hWnd
);
957 // get the window class name
958 extern WXDLLIMPEXP_CORE wxString
wxGetWindowClass(WXHWND hWnd
);
960 // get the window id (should be unsigned, hence this is not wxWindowID which
961 // is, for mainly historical reasons, signed)
962 extern WXDLLIMPEXP_CORE
int wxGetWindowId(WXHWND hWnd
);
964 // check if hWnd's WNDPROC is wndProc. Return true if yes, false if they are
966 extern WXDLLIMPEXP_CORE
bool wxCheckWindowWndProc(WXHWND hWnd
, WXFARPROC wndProc
);
968 // Does this window style specify any border?
969 inline bool wxStyleHasBorder(long style
)
971 return (style
& (wxSIMPLE_BORDER
| wxRAISED_BORDER
|
972 wxSUNKEN_BORDER
| wxDOUBLE_BORDER
)) != 0;
975 inline long wxGetWindowExStyle(const wxWindowMSW
*win
)
977 return ::GetWindowLong(GetHwndOf(win
), GWL_EXSTYLE
);
980 inline bool wxHasWindowExStyle(const wxWindowMSW
*win
, long style
)
982 return (wxGetWindowExStyle(win
) & style
) != 0;
985 inline long wxSetWindowExStyle(const wxWindowMSW
*win
, long style
)
987 return ::SetWindowLong(GetHwndOf(win
), GWL_EXSTYLE
, style
);
990 // ----------------------------------------------------------------------------
991 // functions mapping HWND to wxWindow
992 // ----------------------------------------------------------------------------
994 // this function simply checks whether the given hwnd corresponds to a wxWindow
995 // and returns either that window if it does or NULL otherwise
996 extern WXDLLIMPEXP_CORE wxWindow
* wxFindWinFromHandle(HWND hwnd
);
998 // find the window for HWND which is part of some wxWindow, i.e. unlike
999 // wxFindWinFromHandle() above it will also work for "sub controls" of a
1002 // returns the wxWindow corresponding to the given HWND or NULL.
1003 extern WXDLLIMPEXP_CORE wxWindow
*wxGetWindowFromHWND(WXHWND hwnd
);
1005 // Get the size of an icon
1006 extern WXDLLIMPEXP_CORE wxSize
wxGetHiconSize(HICON hicon
);
1008 // Lines are drawn differently for WinCE and regular WIN32
1009 WXDLLIMPEXP_CORE
void wxDrawLine(HDC hdc
, int x1
, int y1
, int x2
, int y2
);
1011 // fill the client rect of the given window on the provided dc using this brush
1012 inline void wxFillRect(HWND hwnd
, HDC hdc
, HBRUSH hbr
)
1015 ::GetClientRect(hwnd
, &rc
);
1016 ::FillRect(hdc
, &rc
, hbr
);
1019 // ----------------------------------------------------------------------------
1020 // 32/64 bit helpers
1021 // ----------------------------------------------------------------------------
1025 inline void *wxGetWindowProc(HWND hwnd
)
1027 return (void *)::GetWindowLongPtr(hwnd
, GWLP_WNDPROC
);
1030 inline void *wxGetWindowUserData(HWND hwnd
)
1032 return (void *)::GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
1035 inline WNDPROC
wxSetWindowProc(HWND hwnd
, WNDPROC func
)
1037 return (WNDPROC
)::SetWindowLongPtr(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)func
);
1040 inline void *wxSetWindowUserData(HWND hwnd
, void *data
)
1042 return (void *)::SetWindowLongPtr(hwnd
, GWLP_USERDATA
, (LONG_PTR
)data
);
1047 // note that the casts to LONG_PTR here are required even on 32-bit machines
1048 // for the 64-bit warning mode of later versions of MSVC (C4311/4312)
1049 inline WNDPROC
wxGetWindowProc(HWND hwnd
)
1051 return (WNDPROC
)(LONG_PTR
)::GetWindowLong(hwnd
, GWL_WNDPROC
);
1054 inline void *wxGetWindowUserData(HWND hwnd
)
1056 return (void *)(LONG_PTR
)::GetWindowLong(hwnd
, GWL_USERDATA
);
1059 inline WNDPROC
wxSetWindowProc(HWND hwnd
, WNDPROC func
)
1061 return (WNDPROC
)(LONG_PTR
)::SetWindowLong(hwnd
, GWL_WNDPROC
, (LONG_PTR
)func
);
1064 inline void *wxSetWindowUserData(HWND hwnd
, void *data
)
1066 return (void *)(LONG_PTR
)::SetWindowLong(hwnd
, GWL_USERDATA
, (LONG_PTR
)data
);
1069 #endif // __WIN64__/__WIN32__
1071 #endif // wxUSE_GUI && __WXMSW__
1073 #endif // _WX_PRIVATE_H_