1 ///////////////////////////////////////////////////////////////////////////////
2 // Name:        src/msw/nativewin.cpp
3 // Purpose:     wxNativeWindow implementation
4 // Author:      Vadim Zeitlin
5 // Created:     2008-03-05
6 // Copyright:   (c) 2008 Vadim Zeitlin <vadim@wxwindows.org>
7 // Licence:     wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9 
10 // ============================================================================
11 // declarations
12 // ============================================================================
13 
14 // ----------------------------------------------------------------------------
15 // headers
16 // ----------------------------------------------------------------------------
17 
18 // for compilers that support precompilation, includes "wx.h".
19 #include "wx/wxprec.h"
20 
21 #ifdef __BORLANDC__
22     #pragma hdrstop
23 #endif
24 
25 #ifndef WX_PRECOMP
26 #endif // WX_PRECOMP
27 
28 #include "wx/nativewin.h"
29 #include "wx/msw/private.h"
30 
31 // ============================================================================
32 // implementation
33 // ============================================================================
34 
Create(wxNativeContainerWindowHandle hwnd)35 bool wxNativeContainerWindow::Create(wxNativeContainerWindowHandle hwnd)
36 {
37     if ( !::IsWindow(hwnd) )
38     {
39         // strictly speaking, the fact that IsWindow() returns true doesn't
40         // mean that the window handle is valid -- it could be being deleted
41         // right now, for example
42         //
43         // but if it returns false, the handle is definitely invalid
44         return false;
45     }
46 
47     // make this HWND really a wxWindow
48     SubclassWin(hwnd);
49 
50     // inherit the other attributes we can from the native HWND
51     AdoptAttributesFromHWND();
52 
53     return true;
54 }
55 
IsShown() const56 bool wxNativeContainerWindow::IsShown() const
57 {
58     return (IsWindowVisible(static_cast<HWND>(m_hWnd)) != 0);
59 }
60 
OnNativeDestroyed()61 void wxNativeContainerWindow::OnNativeDestroyed()
62 {
63     // don't use Close() or even Destroy() here, we really don't want to keep
64     // an object using a no more existing HWND around for longer than necessary
65     delete this;
66 }
67 
MSWWindowProc(WXUINT nMsg,WXWPARAM wParam,WXLPARAM lParam)68 WXLRESULT wxNativeContainerWindow::MSWWindowProc(WXUINT nMsg,
69                                                  WXWPARAM wParam,
70                                                  WXLPARAM lParam)
71 {
72     if ( nMsg == WM_DESTROY )
73     {
74         OnNativeDestroyed();
75 
76         return 0;
77     }
78 
79     return wxTopLevelWindow::MSWWindowProc(nMsg, wParam, lParam);
80 }
81 
~wxNativeContainerWindow()82 wxNativeContainerWindow::~wxNativeContainerWindow()
83 {
84     // prevent the base class dtor from destroying the window, it doesn't
85     // belong to us so we should leave it alive
86     DissociateHandle();
87 }
88 
89