Exemplo n.º 1
0
        internal static IntPtr WndProc(IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam)
        {
            IntPtr  result = IntPtr.Zero;
            Message m      = new Message();

            m.HWnd   = hWnd;
            m.Msg    = (int)msg;
            m.WParam = wParam;
            m.LParam = lParam;
            m.Result = IntPtr.Zero;

#if debug
            Console.WriteLine("NativeWindow.cs ({0}, {1}, {2}, {3}): result {4}", hWnd, msg, wParam, lParam, m.Result);
#endif
            NativeWindow window = null;

            try {
                object current = null;
                lock (window_collection) {
                    current = window_collection[hWnd];
                }

                window = current as NativeWindow;
                if (current == null)
                {
                    window = EnsureCreated(window, hWnd);
                }

                if (window != null)
                {
                    window.WndProc(ref m);
                    result = m.Result;
                }
                else if (current is ArrayList)
                {
                    ArrayList windows = (ArrayList)current;
                    lock (windows) {
                        if (windows.Count > 0)
                        {
                            window = EnsureCreated((NativeWindow)windows[0], hWnd);
                            window.WndProc(ref m);
                            // the first one is the control's one. all others are synthetic,
                            // so we want only the result from the control
                            result = m.Result;
                            for (int i = 1; i < windows.Count; i++)
                            {
                                ((NativeWindow)windows[i]).WndProc(ref m);
                            }
                        }
                    }
                }
                else
                {
                    result = XplatUI.DefWndProc(ref m);
                }
            }
            catch (Exception ex) {
#if !ExternalExceptionHandler
                if (window != null)
                {
                    if (msg == Msg.WM_PAINT && window is Control.ControlNativeWindow)
                    {
                        // Replace control with a red cross
                        var control = ((Control.ControlNativeWindow)window).Owner;
                        control.Hide();
                        var redCross = new Control(control.Parent, string.Empty);
                        redCross.BackColor = Color.White;
                        redCross.ForeColor = Color.Red;
                        redCross.Bounds    = control.Bounds;
                        redCross.Paint    += HandleRedCrossPaint;
                    }
                    window.OnThreadException(ex);
                }
#else
                throw;
#endif
            }
                        #if debug
            Console.WriteLine("NativeWindow.cs: Message {0}, result {1}", msg, m.Result);
                        #endif

            return(result);
        }
Exemplo n.º 2
0
        internal static IntPtr WndProc(IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam)
        {
            IntPtr  result = IntPtr.Zero;
            Message m      = new Message();

            m.HWnd   = hWnd;
            m.Msg    = (int)msg;
            m.WParam = wParam;
            m.LParam = lParam;
            m.Result = IntPtr.Zero;

#if debug
            Console.WriteLine("NativeWindow.cs ({0}, {1}, {2}, {3}): result {4}", hWnd, msg, wParam, lParam, m.Result);
#endif
            NativeWindow window = null;

            try
            {
                object current = null;
                lock (window_collection)
                {
                    current = window_collection[hWnd];
                }

                window = current as NativeWindow;
                if (current == null)
                {
                    window = EnsureCreated(window, hWnd);
                }

                if (window != null)
                {
                    window.WndProc(ref m);
                    result = m.Result;
                }
                else if (current is ArrayList)
                {
                    ArrayList windows = (ArrayList)current;
                    lock (windows)
                    {
                        if (windows.Count > 0)
                        {
                            window = EnsureCreated((NativeWindow)windows[0], hWnd);
                            window.WndProc(ref m);
                            // the first one is the control's one. all others are synthetic,
                            // so we want only the result from the control
                            result = m.Result;
                            for (int i = 1; i < windows.Count; i++)
                            {
                                ((NativeWindow)windows[i]).WndProc(ref m);
                            }
                        }
                    }
                }
                else
                {
                    result = XplatUI.DefWndProc(ref m);
                }
            }
            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);
#endif

            return(result);
        }
Exemplo n.º 3
0
 internal override IntPtr SendMessage(IntPtr hwnd, Msg message, IntPtr wParam, IntPtr lParam)
 {
     return(NativeWindow.WndProc(hwnd, message, wParam, lParam));
 }