]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/nonownedwnd.cpp
d5818a21e50cf70ce5a6e23dfb2443039ca79544
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"
29 #include "wx/nonownedwnd.h"
31 // ============================================================================
32 // wxNonOwnedWindow implementation
33 // ============================================================================
37 bool wxNonOwnedWindow::SetShape(const wxRegion
& region
)
39 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
40 wxT("Shaped windows must be created with the wxFRAME_SHAPED style."));
42 // The empty region signifies that the shape should be removed from the
44 if ( region
.IsEmpty() )
46 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
48 wxLogLastError(wxT("SetWindowRgn"));
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
;
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.
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
);
72 // Now call the shape API with the new region.
73 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
75 wxLogLastError(wxT("SetWindowRgn"));
81 #endif // !__WXWINCE__