]> git.saurik.com Git - wxWidgets.git/blame - src/msw/nonownedwnd.cpp
No changes, just fix a typo in a header comment.
[wxWidgets.git] / src / msw / nonownedwnd.cpp
CommitLineData
5bd0ee99
VZ
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
164db177
VZ
26// This class can't be implemented and hence is not used under Win CE.
27#ifndef __WXWINCE__
28
5bd0ee99 29#ifndef WX_PRECOMP
3648be1f
VZ
30 #include "wx/frame.h" // Only for wxFRAME_SHAPED.
31 #include "wx/region.h"
32 #include "wx/msw/private.h"
5bd0ee99
VZ
33#endif // WX_PRECOMP
34
35#include "wx/nonownedwnd.h"
36
37// ============================================================================
38// wxNonOwnedWindow implementation
39// ============================================================================
40
5bd0ee99
VZ
41bool wxNonOwnedWindow::SetShape(const wxRegion& region)
42{
43 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false,
44 wxT("Shaped windows must be created with the wxFRAME_SHAPED style."));
45
46 // The empty region signifies that the shape should be removed from the
47 // window.
48 if ( region.IsEmpty() )
49 {
50 if (::SetWindowRgn(GetHwnd(), NULL, TRUE) == 0)
51 {
52 wxLogLastError(wxT("SetWindowRgn"));
53 return false;
54 }
55 return true;
56 }
57
58 // Windows takes ownership of the region, so
59 // we'll have to make a copy of the region to give to it.
60 DWORD noBytes = ::GetRegionData(GetHrgnOf(region), 0, NULL);
61 RGNDATA *rgnData = (RGNDATA*) new char[noBytes];
62 ::GetRegionData(GetHrgnOf(region), noBytes, rgnData);
63 HRGN hrgn = ::ExtCreateRegion(NULL, noBytes, rgnData);
64 delete[] (char*) rgnData;
65
66 // SetWindowRgn expects the region to be in coordinates
67 // relative to the window, not the client area. Figure
68 // out the offset, if any.
69 RECT rect;
70 DWORD dwStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE);
71 DWORD dwExStyle = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE);
72 ::GetClientRect(GetHwnd(), &rect);
73 ::AdjustWindowRectEx(&rect, dwStyle, ::GetMenu(GetHwnd()) != NULL, dwExStyle);
74 ::OffsetRgn(hrgn, -rect.left, -rect.top);
75
76 // Now call the shape API with the new region.
77 if (::SetWindowRgn(GetHwnd(), hrgn, TRUE) == 0)
78 {
79 wxLogLastError(wxT("SetWindowRgn"));
80 return false;
81 }
82 return true;
83}
84
85#endif // !__WXWINCE__