1 /////////////////////////////////////////////////////////////////////////////
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"
24 // Include fixes for MSLU:
25 #include "wx/msw/mslu.h"
29 class WXDLLEXPORT wxFont
;
30 class WXDLLEXPORT wxWindow
;
32 // ---------------------------------------------------------------------------
34 // ---------------------------------------------------------------------------
36 // 260 was taken from windef.h
41 // ---------------------------------------------------------------------------
42 // standard icons from the resources
43 // ---------------------------------------------------------------------------
47 WXDLLEXPORT_DATA(extern HICON
) wxSTD_FRAME_ICON
;
48 WXDLLEXPORT_DATA(extern HICON
) wxSTD_MDIPARENTFRAME_ICON
;
49 WXDLLEXPORT_DATA(extern HICON
) wxSTD_MDICHILDFRAME_ICON
;
50 WXDLLEXPORT_DATA(extern HICON
) wxDEFAULT_FRAME_ICON
;
51 WXDLLEXPORT_DATA(extern HICON
) wxDEFAULT_MDIPARENTFRAME_ICON
;
52 WXDLLEXPORT_DATA(extern HICON
) wxDEFAULT_MDICHILDFRAME_ICON
;
53 WXDLLEXPORT_DATA(extern HFONT
) wxSTATUS_LINE_FONT
;
57 // ---------------------------------------------------------------------------
58 // define things missing from some compilers' headers
59 // ---------------------------------------------------------------------------
61 #if defined(__WXWINCE__) || (defined(__GNUWIN32__) && !wxUSE_NORLANDER_HEADERS)
63 inline void ZeroMemory(void *buf
, size_t len
) { memset(buf
, 0, len
); }
67 // this defines a CASTWNDPROC macro which casts a pointer to the type of a
69 #if defined(STRICT) || defined(__GNUC__)
70 typedef WNDPROC WndProcCast
;
72 typedef FARPROC WndProcCast
;
76 #define CASTWNDPROC (WndProcCast)
80 // ---------------------------------------------------------------------------
81 // some stuff for old Windows versions (FIXME: what does it do here??)
82 // ---------------------------------------------------------------------------
84 #if !defined(APIENTRY) // NT defines APIENTRY, 3.x not
85 #define APIENTRY FAR PASCAL
91 #define _EXPORT _export
95 typedef signed short int SHORT
;
98 #if !defined(__WIN32__) // 3.x uses FARPROC for dialogs
100 #define DLGPROC FARPROC
105 WXDLLEXPORT
void wxRegisterPenWin();
106 WXDLLEXPORT
void wxCleanUpPenWin();
107 WXDLLEXPORT
void wxEnablePenAppHooks (bool hook
);
108 #endif // wxUSE_PENWIN
111 #define IBS_HORZCAPTION 0x4000L
112 #define IBS_VERTCAPTION 0x8000L
114 UINT WINAPI
ibGetCaptionSize( HWND hWnd
) ;
115 UINT WINAPI
ibSetCaptionSize( HWND hWnd
, UINT nSize
) ;
116 LRESULT WINAPI
ibDefWindowProc( HWND hWnd
, UINT uiMsg
, WPARAM wParam
, LPARAM lParam
) ;
117 VOID WINAPI
ibAdjustWindowRect( HWND hWnd
, LPRECT lprc
) ;
118 #endif // wxUSE_ITSY_BITSY
121 * Decide what window classes we're going to use
122 * for this combination of CTl3D/FAFA settings
125 #define STATIC_CLASS wxT("STATIC")
126 #define STATIC_FLAGS (SS_LEFT|WS_CHILD|WS_VISIBLE)
127 #define CHECK_CLASS wxT("BUTTON")
128 #define CHECK_FLAGS (BS_AUTOCHECKBOX|WS_TABSTOP|WS_CHILD)
129 #define CHECK_IS_FAFA FALSE
130 #define RADIO_CLASS wxT("BUTTON")
131 #define RADIO_FLAGS (BS_AUTORADIOBUTTON|WS_CHILD|WS_VISIBLE)
132 #define RADIO_SIZE 20
133 #define RADIO_IS_FAFA FALSE
135 #define GROUP_CLASS wxT("BUTTON")
136 #define GROUP_FLAGS (BS_GROUPBOX|WS_CHILD|WS_VISIBLE)
139 #define BITCHECK_FLAGS (FB_BITMAP|FC_BUTTONDRAW|FC_DEFAULT|WS_VISIBLE)
140 #define BITRADIO_FLAGS (FC_BUTTONDRAW|FB_BITMAP|FC_RADIO|WS_CHILD|WS_VISIBLE)
143 // ---------------------------------------------------------------------------
145 // ---------------------------------------------------------------------------
147 #define MEANING_CHARACTER '0'
148 #define DEFAULT_ITEM_WIDTH 100
149 #define DEFAULT_ITEM_HEIGHT 80
151 // Scale font to get edit control height
152 //#define EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) (3*(cy)/2)
153 #define EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) (cy+8)
155 // Generic subclass proc, for panel item moving/sizing and intercept
156 // EDIT control VK_RETURN messages
157 extern LONG APIENTRY _EXPORT
158 wxSubclassedGenericControlProc(WXHWND hWnd
, WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
);
160 // ---------------------------------------------------------------------------
161 // useful macros and functions
162 // ---------------------------------------------------------------------------
164 // a wrapper macro for ZeroMemory()
165 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
166 #define wxZeroMemory(obj) ::ZeroMemory(&obj, sizeof(obj))
168 #define wxZeroMemory(obj) memset((void*) & obj, 0, sizeof(obj))
173 #include <wx/gdicmn.h>
174 #include <wx/colour.h>
176 // make conversion from wxColour and COLORREF a bit less painful
177 inline COLORREF
wxColourToRGB(const wxColour
& c
)
179 return RGB(c
.Red(), c
.Green(), c
.Blue());
182 inline COLORREF
wxColourToPalRGB(const wxColour
& c
)
184 return PALETTERGB(c
.Red(), c
.Green(), c
.Blue());
187 inline wxColour
wxRGBToColour(COLORREF rgb
)
189 return wxColour(GetRValue(rgb
), GetGValue(rgb
), GetBValue(rgb
));
192 inline void wxRGBToColour(wxColour
& c
, COLORREF rgb
)
194 c
.Set(GetRValue(rgb
), GetGValue(rgb
), GetBValue(rgb
));
197 // get the standard colour map for some standard colours - see comment in this
198 // function to understand why is it needed and when should it be used
200 // it returns a wxCOLORMAP (can't use COLORMAP itself here as comctl32.dll
201 // might be not included/available) array of size wxSTD_COLOUR_MAX
203 // NB: if you change these colours, update wxBITMAP_STD_COLOURS in the
204 // resources as well: it must have the same number of pixels!
210 wxSTD_COL_BTNHIGHLIGHT
,
214 struct WXDLLEXPORT wxCOLORMAP
219 // this function is implemented in src/msw/window.cpp
220 extern wxCOLORMAP
*wxGetStdColourMap();
222 // create a wxRect from Windows RECT
223 inline wxRect
wxRectFromRECT(const RECT
& r
)
225 return wxRect(r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
);
228 // copy Windows RECT to our wxRect
229 inline void wxCopyRECTToRect(const RECT
& r
, wxRect
& rect
)
231 rect
= wxRectFromRECT(r
);
234 // translations between HIMETRIC units (which OLE likes) and pixels (which are
235 // liked by all the others) - implemented in msw/utilsexc.cpp
236 extern void HIMETRICToPixel(LONG
*x
, LONG
*y
);
237 extern void PixelToHIMETRIC(LONG
*x
, LONG
*y
);
239 // Windows convention of the mask is opposed to the wxWidgets one, so we need
240 // to invert the mask each time we pass one/get one to/from Windows
241 extern HBITMAP
wxInvertMask(HBITMAP hbmpMask
, int w
= 0, int h
= 0);
243 // Creates an icon or cursor depending from a bitmap
245 // The bitmap must be valid and it should have a mask. If it doesn't, a default
246 // mask is created using light grey as the transparent colour.
247 extern HICON
wxBitmapToHICON(const wxBitmap
& bmp
);
249 // Same requirments as above apply and the bitmap must also have the correct
252 HCURSOR
wxBitmapToHCURSOR(const wxBitmap
& bmp
, int hotSpotX
, int hotSpotY
);
254 // get (x, y) from DWORD - notice that HI/LOWORD can *not* be used because they
255 // will fail on system with multiple monitors where the coords may be negative
257 // these macros are standard now (Win98) but some older headers don't have them
259 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
260 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
261 #endif // GET_X_LPARAM
263 // get the current state of SHIFT/CTRL keys
264 inline bool wxIsShiftDown()
266 // return (::GetKeyState(VK_SHIFT) & 0x100) != 0;
267 // Returns different negative values on WinME and WinNT,
268 // so simply test for negative value.
269 return ::GetKeyState(VK_SHIFT
) < 0;
272 inline bool wxIsCtrlDown()
274 // return (::GetKeyState(VK_CONTROL) & 0x100) != 0;
275 // Returns different negative values on WinME and WinNT,
276 // so simply test for negative value.
277 return ::GetKeyState(VK_CONTROL
) < 0;
280 // wrapper around GetWindowRect() and GetClientRect() APIs doing error checking
282 inline RECT
wxGetWindowRect(HWND hwnd
)
286 if ( !::GetWindowRect(hwnd
, &rect
) )
288 wxLogLastError(_T("GetWindowRect"));
294 inline RECT
wxGetClientRect(HWND hwnd
)
298 if ( !::GetClientRect(hwnd
, &rect
) )
300 wxLogLastError(_T("GetClientRect"));
306 // ---------------------------------------------------------------------------
307 // small helper classes
308 // ---------------------------------------------------------------------------
310 // a template to make initializing Windows styructs less painful: it zeroes all
311 // the struct fields and also sets cbSize member to the correct value (and so
312 // can be only used with structures which have this member...)
314 struct WinStruct
: public T
318 ::ZeroMemory(this, sizeof(T
));
320 // explicit qualification is required here for this to be valid C++
321 this->cbSize
= sizeof(T
);
326 // create an instance of this class and use it as the HDC for screen, will
327 // automatically release the DC going out of scope
331 ScreenHDC() { m_hdc
= ::GetDC(NULL
); }
332 ~ScreenHDC() { ::ReleaseDC(NULL
, m_hdc
); }
334 operator HDC() const { return m_hdc
; }
339 DECLARE_NO_COPY_CLASS(ScreenHDC
)
342 // the same as ScreenHDC but for window DCs
346 WindowHDC(HWND hwnd
) { m_hdc
= ::GetDC(m_hwnd
= hwnd
); }
347 ~WindowHDC() { ::ReleaseDC(m_hwnd
, m_hdc
); }
349 operator HDC() const { return m_hdc
; }
355 DECLARE_NO_COPY_CLASS(WindowHDC
)
358 // the same as ScreenHDC but for memory DCs: creates the HDC compatible with
359 // the given one (screen by default) in ctor and destroys it in dtor
363 MemoryHDC(HDC hdc
= 0) { m_hdc
= ::CreateCompatibleDC(hdc
); }
364 ~MemoryHDC() { ::DeleteDC(m_hdc
); }
366 operator HDC() const { return m_hdc
; }
371 DECLARE_NO_COPY_CLASS(MemoryHDC
)
374 // a class which selects a GDI object into a DC in its ctor and deselects in
379 SelectInHDC(HDC hdc
, HGDIOBJ hgdiobj
) : m_hdc(hdc
)
380 { m_hgdiobj
= ::SelectObject(hdc
, hgdiobj
); }
382 ~SelectInHDC() { ::SelectObject(m_hdc
, m_hgdiobj
); }
384 // return true if the object was successfully selected
385 operator bool() const { return m_hgdiobj
!= 0; }
391 DECLARE_NO_COPY_CLASS(SelectInHDC
)
394 // a class for temporary bitmaps
395 class CompatibleBitmap
398 CompatibleBitmap(HDC hdc
, int w
, int h
)
400 m_hbmp
= ::CreateCompatibleBitmap(hdc
, w
, h
);
406 ::DeleteObject(m_hbmp
);
409 operator HBITMAP() const { return m_hbmp
; }
415 // when working with global pointers (which is unfortunately still necessary
416 // sometimes, e.g. for clipboard) it is important to unlock them exactly as
417 // many times as we lock them which just asks for using a "smart lock" class
421 GlobalPtr(HGLOBAL hGlobal
) : m_hGlobal(hGlobal
)
423 m_ptr
= GlobalLock(hGlobal
);
426 wxLogLastError(_T("GlobalLock"));
432 if ( !GlobalUnlock(m_hGlobal
) )
435 // this might happen simply because the block became unlocked
436 DWORD dwLastError
= ::GetLastError();
437 if ( dwLastError
!= NO_ERROR
)
439 wxLogApiError(_T("GlobalUnlock"), dwLastError
);
441 #endif // __WXDEBUG__
445 operator void *() const { return m_ptr
; }
451 DECLARE_NO_COPY_CLASS(GlobalPtr
)
454 // ---------------------------------------------------------------------------
455 // macros to make casting between WXFOO and FOO a bit easier: the GetFoo()
456 // returns Foo cast to the Windows type for oruselves, while GetFooOf() takes
457 // an argument which should be a pointer or reference to the object of the
458 // corresponding class (this depends on the macro)
459 // ---------------------------------------------------------------------------
461 #define GetHwnd() ((HWND)GetHWND())
462 #define GetHwndOf(win) ((HWND)((win)->GetHWND()))
464 #define GetWinHwnd GetHwndOf
466 #define GetHdc() ((HDC)GetHDC())
467 #define GetHdcOf(dc) ((HDC)(dc).GetHDC())
469 #define GetHbitmap() ((HBITMAP)GetHBITMAP())
470 #define GetHbitmapOf(bmp) ((HBITMAP)(bmp).GetHBITMAP())
472 #define GetHicon() ((HICON)GetHICON())
473 #define GetHiconOf(icon) ((HICON)(icon).GetHICON())
475 #define GetHaccel() ((HACCEL)GetHACCEL())
476 #define GetHaccelOf(table) ((HACCEL)((table).GetHACCEL()))
478 #define GetHbrush() ((HPEN)GetResourceHandle())
479 #define GetHbrushOf(brush) ((HPEN)(brush).GetResourceHandle())
481 #define GetHmenu() ((HMENU)GetHMenu())
482 #define GetHmenuOf(menu) ((HMENU)menu->GetHMenu())
484 #define GetHcursor() ((HCURSOR)GetHCURSOR())
485 #define GetHcursorOf(cursor) ((HCURSOR)(cursor).GetHCURSOR())
487 #define GetHfont() ((HFONT)GetHFONT())
488 #define GetHfontOf(font) ((HFONT)(font).GetHFONT())
490 #define GetHpalette() ((HPALETTE)GetHPALETTE())
491 #define GetHpaletteOf(pal) ((HPALETTE)(pal).GetHPALETTE())
493 #define GetHpen() ((HPEN)GetResourceHandle())
494 #define GetHpenOf(pen) ((HPEN)(pen).GetResourceHandle())
496 #define GetHrgn() ((HRGN)GetHRGN())
497 #define GetHrgnOf(rgn) ((HRGN)(rgn).GetHRGN())
501 // ---------------------------------------------------------------------------
503 // ---------------------------------------------------------------------------
505 WXDLLIMPEXP_DATA_BASE(extern HINSTANCE
) wxhInstance
;
507 // ---------------------------------------------------------------------------
509 // ---------------------------------------------------------------------------
513 WXDLLIMPEXP_BASE HINSTANCE
wxGetInstance();
516 WXDLLIMPEXP_BASE
void wxSetInstance(HINSTANCE hInst
);
518 // return the full path of the given module
519 inline wxString
wxGetFullModuleName(HMODULE hmod
)
522 if ( !::GetModuleFileName
525 wxStringBuffer(fullname
, MAX_PATH
),
529 wxLogLastError(_T("GetModuleFileName"));
535 // return the full path of the program file
536 inline wxString
wxGetFullModuleName()
538 return wxGetFullModuleName((HMODULE
)wxGetInstance());
544 extern HCURSOR
wxGetCurrentBusyCursor(); // from msw/utils.cpp
545 extern const wxCursor
*wxGetGlobalCursor(); // from msw/cursor.cpp
547 WXDLLEXPORT
void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
& the_font
);
548 WXDLLEXPORT
void wxFillLogFont(LOGFONT
*logFont
, const wxFont
*font
);
549 WXDLLEXPORT wxFont
wxCreateFontFromLogFont(const LOGFONT
*logFont
);
550 WXDLLEXPORT wxFontEncoding
wxGetFontEncFromCharSet(int charset
);
552 WXDLLEXPORT
void wxSliderEvent(WXHWND control
, WXWORD wParam
, WXWORD pos
);
553 WXDLLEXPORT
void wxScrollBarEvent(WXHWND hbar
, WXWORD wParam
, WXWORD pos
);
555 // Find maximum size of window/rectangle
556 WXDLLEXPORT
extern void wxFindMaxSize(WXHWND hwnd
, RECT
*rect
);
558 // Safely get the window text (i.e. without using fixed size buffer)
559 WXDLLEXPORT
extern wxString
wxGetWindowText(WXHWND hWnd
);
561 // get the window class name
562 WXDLLEXPORT
extern wxString
wxGetWindowClass(WXHWND hWnd
);
564 // get the window id (should be unsigned, hence this is not wxWindowID which
565 // is, for mainly historical reasons, signed)
566 WXDLLEXPORT
extern WXWORD
wxGetWindowId(WXHWND hWnd
);
568 // check if hWnd's WNDPROC is wndProc. Return true if yes, false if they are
570 WXDLLEXPORT
extern bool wxCheckWindowWndProc(WXHWND hWnd
, WXFARPROC wndProc
);
572 // Does this window style specify any border?
573 inline bool wxStyleHasBorder(long style
)
575 return (style
& (wxSIMPLE_BORDER
| wxRAISED_BORDER
|
576 wxSUNKEN_BORDER
| wxDOUBLE_BORDER
)) != 0;
579 // ----------------------------------------------------------------------------
580 // functions mapping HWND to wxWindow
581 // ----------------------------------------------------------------------------
583 // this function simply checks whether the given hWnd corresponds to a wxWindow
584 // and returns either that window if it does or NULL otherwise
585 WXDLLEXPORT
extern wxWindow
* wxFindWinFromHandle(WXHWND hWnd
);
587 // find the window for HWND which is part of some wxWindow, i.e. unlike
588 // wxFindWinFromHandle() above it will also work for "sub controls" of a
591 // returns the wxWindow corresponding to the given HWND or NULL.
592 WXDLLEXPORT
extern wxWindow
*wxGetWindowFromHWND(WXHWND hwnd
);
594 // Get the size of an icon
595 WXDLLEXPORT
extern wxSize
wxGetHiconSize(HICON hicon
);
597 // Lines are drawn differently for WinCE and regular WIN32
598 WXDLLEXPORT
void wxDrawLine(HDC hdc
, int x1
, int y1
, int x2
, int y2
);
600 // ----------------------------------------------------------------------------
602 // ----------------------------------------------------------------------------
606 inline void *wxGetWindowProc(HWND hwnd
)
608 return (void *)::GetWindowLongPtr(hwnd
, GWLP_WNDPROC
);
611 inline void *wxGetWindowUserData(HWND hwnd
)
613 return (void *)::GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
616 inline WNDPROC
wxSetWindowProc(HWND hwnd
, WNDPROC func
)
618 return (WNDPROC
)::SetWindowLongPtr(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)func
);
621 inline void *wxSetWindowUserData(HWND hwnd
, void *data
)
623 return (void *)::SetWindowLongPtr(hwnd
, GWLP_USERDATA
, (LONG_PTR
)data
);
629 // strangely enough, VC++ 7.1 gives warnings about 32 -> 64 bit conversions
630 // in the functions below, even in spite of the explicit casts
631 #pragma warning(disable:4311)
632 #pragma warning(disable:4312)
635 inline void *wxGetWindowProc(HWND hwnd
)
637 return (void *)::GetWindowLong(hwnd
, GWL_WNDPROC
);
640 inline void *wxGetWindowUserData(HWND hwnd
)
642 return (void *)::GetWindowLong(hwnd
, GWL_USERDATA
);
645 inline WNDPROC
wxSetWindowProc(HWND hwnd
, WNDPROC func
)
647 return (WNDPROC
)::SetWindowLong(hwnd
, GWL_WNDPROC
, (LONG
)func
);
650 inline void *wxSetWindowUserData(HWND hwnd
, void *data
)
652 return (void *)::SetWindowLong(hwnd
, GWL_USERDATA
, (LONG
)data
);
656 #pragma warning(default:4311)
657 #pragma warning(default:4312)
660 #endif // __WIN64__/__WIN32__