2 // System.Windows.Forms.NativeWindow.cs
5 // stubbed out by Paul Osman (paul.osman@sympatico.ca)
6 // Dennis Hayes (dennish@Raytek.com)
7 // WINELib implementation started by John Sohn (jsohn@columbus.rr.com)
9 // (C) 2002 Ximian, Inc
12 using System
.Runtime
.Remoting
;
13 using System
.Runtime
.InteropServices
;
14 using System
.Runtime
.CompilerServices
;
15 using System
.Collections
;
17 namespace System
.Windows
.Forms
{
20 // Implementation started.
24 public class NativeWindow
: MarshalByRefObject
{
27 private IntPtr windowHandle
;
28 static private Hashtable windowCollection
= new Hashtable ();
29 static bool registeredClass
= false;
34 public NativeWindow ()
36 windowHandle
= (IntPtr
) 0;
40 // --- Public Properties
52 public void AssignHandle (IntPtr handle
)
54 if (windowHandle
!= (IntPtr
) 0)
55 windowCollection
.Remove (windowHandle
);
57 windowHandle
= handle
;
58 windowCollection
.Add (windowHandle
, this);
62 public virtual void CreateHandle (CreateParams cp
)
64 IntPtr createdHWnd
= (IntPtr
) 0;
65 Object lpParam
= new Object();
67 if (!registeredClass
) {
68 Win32
.WndProc wp
= new Win32
.WndProc (WndProc
);
69 if (Win32
.MonoRegisterClass(
70 (int) (Win32
.CS_OWNDC
|
73 wp
, 0, 0, (IntPtr
) 0, (IntPtr
) 0,
74 (IntPtr
) 0, (IntPtr
) 6, "",
75 "mono_native_window") != 0) {
76 registeredClass
= true;
78 windowHandle
= (IntPtr
) 0;
83 windowHandle
= Win32
.CreateWindowExA (
84 (uint) cp
.ExStyle
, cp
.ClassName
,
85 cp
.Caption
,(uint) cp
.Style
,
86 cp
.X
, cp
.Y
, cp
.Width
, cp
.Height
,
87 (IntPtr
) cp
.Parent
, (IntPtr
) 0,
88 (IntPtr
) 0, ref lpParam
);
90 if (windowHandle
!= (IntPtr
) 0)
91 windowCollection
.Add (windowHandle
, this);
95 public override ObjRef
CreateObjRef (Type requestedType
)
97 throw new NotImplementedException ();
100 public void DefWndProc (ref Message m
)
102 m
.Result
= Win32
.DefWindowProcA (m
.HWnd
, m
.Msg
,
106 public virtual void DestroyHandle ()
108 windowCollection
.Remove (windowHandle
);
109 Win32
.DestroyWindow (windowHandle
);
113 public override bool Equals (object o
)
115 throw new NotImplementedException ();
119 //public static bool Equals(object o1, object o2)
121 // throw new NotImplementedException ();
124 public override int GetHashCode ()
126 //FIXME add our proprities
127 return base.GetHashCode ();
130 public static NativeWindow
FromHandle (IntPtr handle
)
132 NativeWindow window
= new NativeWindow ();
133 window
.AssignHandle (handle
);
138 //public object GetLifetimeService() {
139 // throw new NotImplementedException ();
142 //public Type GetType() {
143 // throw new NotImplementedException ();
146 //public virtual object InitializeLifetimeService(){
147 // throw new NotImplementedException ();
150 public virtual void ReleaseHandle ()
152 windowHandle
= (IntPtr
) 0;
157 public override string ToString ()
159 throw new NotImplementedException ();
163 // --- Protected Methods
166 //protected object MemberwiseClone() {
167 // throw new NotImplementedException ();
171 protected virtual void OnHandleChange ()
177 protected virtual void OnThreadException (Exception e
)
179 throw new NotImplementedException ();
182 protected virtual void WndProc (ref Message m
)
184 if (m
.Msg
== Win32
.WM_CREATE
)
185 Console
.WriteLine ("NW WndProc WM_CREATE");
197 static private IntPtr
WndProc (
198 IntPtr hWnd
, int msg
, IntPtr wParam
, IntPtr lParam
)
200 // windowCollection is a collection of all the
201 // NativeWindow(s) that have been created.
202 // Dispatch the current message to the approriate
204 NativeWindow window
=
205 (NativeWindow
) windowCollection
[hWnd
];
206 Message message
= new Message ();
209 message
.WParam
= wParam
;
210 message
.LParam
= lParam
;
211 message
.Result
= (IntPtr
) 0;
213 if (msg
== Win32
.WM_CREATE
)
214 Console
.WriteLine ("WM_CREATE (static)");
216 if (window
!= null) {
217 if (msg
== Win32
.WM_CREATE
)
218 Console
.WriteLine ("WM_CREATE (static != null)");
219 window
.WndProc(ref message
);
221 Console
.WriteLine ("no window, defwndproc");
222 // even though we are not managing the
223 // window let the window get the message
224 message
.Result
= Win32
.DefWindowProcA (
225 hWnd
, msg
, wParam
, lParam
);
228 return message
.Result
;