]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/nonownedwnd.cpp
8cfe2e20645e091dbe7d7d08abb5371271d361bb
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)
7 // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
27 #include "wx/frame.h" // Only for wxFRAME_SHAPED.
28 #include "wx/region.h"
29 #include "wx/msw/private.h"
32 #include "wx/nonownedwnd.h"
34 // ============================================================================
35 // wxNonOwnedWindow implementation
36 // ============================================================================
40 bool wxNonOwnedWindow::SetShape(const wxRegion
& region
)
42 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
43 wxT("Shaped windows must be created with the wxFRAME_SHAPED style."));
45 // The empty region signifies that the shape should be removed from the
47 if ( region
.IsEmpty() )
49 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
51 wxLogLastError(wxT("SetWindowRgn"));
57 // Windows takes ownership of the region, so
58 // we'll have to make a copy of the region to give to it.
59 DWORD noBytes
= ::GetRegionData(GetHrgnOf(region
), 0, NULL
);
60 RGNDATA
*rgnData
= (RGNDATA
*) new char[noBytes
];
61 ::GetRegionData(GetHrgnOf(region
), noBytes
, rgnData
);
62 HRGN hrgn
= ::ExtCreateRegion(NULL
, noBytes
, rgnData
);
63 delete[] (char*) rgnData
;
65 // SetWindowRgn expects the region to be in coordinates
66 // relative to the window, not the client area. Figure
67 // out the offset, if any.
69 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
70 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
71 ::GetClientRect(GetHwnd(), &rect
);
72 ::AdjustWindowRectEx(&rect
, dwStyle
, ::GetMenu(GetHwnd()) != NULL
, dwExStyle
);
73 ::OffsetRgn(hrgn
, -rect
.left
, -rect
.top
);
75 // Now call the shape API with the new region.
76 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
78 wxLogLastError(wxT("SetWindowRgn"));
84 #endif // !__WXWINCE__