예제 #1
0
        private static IntPtr _WndProc(IntPtr hwnd, WM msg, IntPtr wParam, IntPtr lParam)
        {
            IntPtr        result        = IntPtr.Zero;
            MessageWindow messageWindow = null;

            if (msg == WM.CREATE)
            {
                CREATESTRUCT createstruct = (CREATESTRUCT)Marshal.PtrToStructure(lParam, typeof(CREATESTRUCT));
                messageWindow = (MessageWindow)GCHandle.FromIntPtr(createstruct.lpCreateParams).Target;
                MessageWindow.s_windowLookup.Add(hwnd, messageWindow);
            }
            else if (!MessageWindow.s_windowLookup.TryGetValue(hwnd, out messageWindow))
            {
                return(NativeMethods.DefWindowProc(hwnd, msg, wParam, lParam));
            }
            WndProc wndProcCallback = messageWindow._wndProcCallback;

            if (wndProcCallback != null)
            {
                result = wndProcCallback(hwnd, msg, wParam, lParam);
            }
            else
            {
                result = NativeMethods.DefWindowProc(hwnd, msg, wParam, lParam);
            }
            if (msg == WM.NCDESTROY)
            {
                messageWindow._Dispose(true, true);
                GC.SuppressFinalize(messageWindow);
            }
            return(result);
        }
예제 #2
0
        private static IntPtr _WndProc(IntPtr hwnd, WM msg, IntPtr wParam, IntPtr lParam)
        {
            IntPtr        zero   = IntPtr.Zero;
            MessageWindow target = null;

            if (msg == WM.CREATE)
            {
                CREATESTRUCT structure = (CREATESTRUCT)Marshal.PtrToStructure(lParam, typeof(CREATESTRUCT));
                target = (MessageWindow)GCHandle.FromIntPtr(structure.lpCreateParams).Target;
                MessageWindow.s_windowLookup.Add(hwnd, target);
            }
            else if (!MessageWindow.s_windowLookup.TryGetValue(hwnd, out target))
            {
                return(Standard.NativeMethods.DefWindowProcW(hwnd, msg, wParam, lParam));
            }
            WndProc wndProc = target._wndProcCallback;

            zero = (wndProc == null ? Standard.NativeMethods.DefWindowProcW(hwnd, msg, wParam, lParam) : wndProc(hwnd, msg, wParam, lParam));
            if (msg == WM.NCDESTROY)
            {
                target._Dispose(true, true);
                GC.SuppressFinalize(target);
            }
            return(zero);
        }
예제 #3
0
        private static IntPtr _WndProc(IntPtr hwnd, WM msg, IntPtr wParam, IntPtr lParam)
        {
            IntPtr        ret         = IntPtr.Zero;
            MessageWindow hwndWrapper = null;

            if (msg == WM.CREATE)
            {
                var      createStruct = (CREATESTRUCT)Marshal.PtrToStructure(lParam, typeof(CREATESTRUCT));
                GCHandle gcHandle     = GCHandle.FromIntPtr(createStruct.lpCreateParams);
                hwndWrapper = (MessageWindow)gcHandle.Target;
                s_windowLookup.Add(hwnd, hwndWrapper);
            }
            else
            {
                if (!s_windowLookup.TryGetValue(hwnd, out hwndWrapper))
                {
                    return(NativeMethods.DefWindowProc(hwnd, msg, wParam, lParam));
                }
            }

            Assert.IsNotNull(hwndWrapper);

            WndProc callback = hwndWrapper.wndProcCallback;

            if (callback != null)
            {
                ret = callback(hwnd, msg, wParam, lParam);
            }
            else
            {
                ret = NativeMethods.DefWindowProc(hwnd, msg, wParam, lParam);
            }

            if (msg == WM.NCDESTROY)
            {
                hwndWrapper._Dispose(true, true);
                GC.SuppressFinalize(hwndWrapper);
            }

            return(ret);
        }