]> git.saurik.com Git - wxWidgets.git/blob - src/msw/nonownedwnd.cpp
d5818a21e50cf70ce5a6e23dfb2443039ca79544
[wxWidgets.git] / src / msw / nonownedwnd.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/nonownedwnd.cpp
3 // Purpose: wxNonOwnedWindow implementation for MSW.
4 // Author: Vadim Zeitlin
5 // Created: 2011-10-09 (extracted from src/msw/toplevel.cpp)
6 // RCS-ID: $Id: $
7 // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #ifndef WX_PRECOMP
27 #endif // WX_PRECOMP
28
29 #include "wx/nonownedwnd.h"
30
31 // ============================================================================
32 // wxNonOwnedWindow implementation
33 // ============================================================================
34
35 #ifndef __WXWINCE__
36
37 bool wxNonOwnedWindow::SetShape(const wxRegion& region)
38 {
39 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false,
40 wxT("Shaped windows must be created with the wxFRAME_SHAPED style."));
41
42 // The empty region signifies that the shape should be removed from the
43 // window.
44 if ( region.IsEmpty() )
45 {
46 if (::SetWindowRgn(GetHwnd(), NULL, TRUE) == 0)
47 {
48 wxLogLastError(wxT("SetWindowRgn"));
49 return false;
50 }
51 return true;
52 }
53
54 // Windows takes ownership of the region, so
55 // we'll have to make a copy of the region to give to it.
56 DWORD noBytes = ::GetRegionData(GetHrgnOf(region), 0, NULL);
57 RGNDATA *rgnData = (RGNDATA*) new char[noBytes];
58 ::GetRegionData(GetHrgnOf(region), noBytes, rgnData);
59 HRGN hrgn = ::ExtCreateRegion(NULL, noBytes, rgnData);
60 delete[] (char*) rgnData;
61
62 // SetWindowRgn expects the region to be in coordinates
63 // relative to the window, not the client area. Figure
64 // out the offset, if any.
65 RECT rect;
66 DWORD dwStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE);
67 DWORD dwExStyle = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE);
68 ::GetClientRect(GetHwnd(), &rect);
69 ::AdjustWindowRectEx(&rect, dwStyle, ::GetMenu(GetHwnd()) != NULL, dwExStyle);
70 ::OffsetRgn(hrgn, -rect.left, -rect.top);
71
72 // Now call the shape API with the new region.
73 if (::SetWindowRgn(GetHwnd(), hrgn, TRUE) == 0)
74 {
75 wxLogLastError(wxT("SetWindowRgn"));
76 return false;
77 }
78 return true;
79 }
80
81 #endif // !__WXWINCE__