using System.Runtime.Remoting;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
+using System.Threading;
using System.Collections;
using System.Diagnostics;
namespace System.Windows.Forms
{
- public class NativeWindow : MarshalByRefObject {
+ public class NativeWindow : MarshalByRefObject
+#if NET_2_0
+ , IWin32Window
+#endif
+ {
internal IntPtr window_handle;
static internal Hashtable window_collection = new Hashtable();
+ [ThreadStatic]
+ static NativeWindow WindowCreating;
+
#region Public Constructors
public NativeWindow()
{
public void AssignHandle(IntPtr handle)
{
lock (window_collection) {
- if (window_handle != IntPtr.Zero) {
+ if (window_handle != IntPtr.Zero)
window_collection.Remove(window_handle);
- }
window_handle=handle;
window_collection.Add(window_handle, this);
}
public virtual void CreateHandle(CreateParams create_params)
{
if (create_params != null) {
+ WindowCreating = this;
+
window_handle=XplatUI.CreateWindow(create_params);
+ WindowCreating = null;
+
if (window_handle != IntPtr.Zero) {
lock (window_collection) {
- window_collection.Add(window_handle, this);
+ window_collection[window_handle] = this;
}
}
}
+
}
public void DefWndProc(ref Message m)
{
Message m = new Message();
NativeWindow window = null;
+
+#if debug
+ Console.WriteLine("NativeWindow.cs ({0}, {1}, {2}, {3}): result {4}", hWnd, msg, wParam, lParam, m.Result);
+#endif
+
- try {
+ //try {
lock (window_collection) {
window = (NativeWindow)window_collection[hWnd];
}
if (window != null)
window.WndProc(ref m);
+ else if (WindowCreating != null) {
+ // we need to do this AssignHandle here instead of relying on
+ // Control.WndProc to do it, because subclasses can override
+ // WndProc, install their own WM_CREATE block, and look at
+ // this.Handle, and it needs to be set. Otherwise, we end up
+ // recursively creating windows and emitting WM_CREATE.
+ window = WindowCreating;
+ WindowCreating = null;
+ if (window.window_handle == IntPtr.Zero)
+ window.AssignHandle (hWnd);
+
+ window.WndProc (ref m);
+ }
else
m.Result=XplatUI.DefWndProc(ref m);
- }
- catch (Exception ex) {
-#if !ExternalExceptionHandler
- if (window != null)
- window.OnThreadException(ex);
-#else
- throw;
-#endif
- }
+// }
+// catch (Exception ex) {
+//#if !ExternalExceptionHandler
+// if (window != null)
+// window.OnThreadException(ex);
+//#else
+// throw;
+//#endif
+// }
#if debug
Console.WriteLine("NativeWindow.cs: Message {0}, result {1}", msg, m.Result);