Пример #1
0
        private IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam)
        {
            switch (msg)
            {
            case 0x118:     // Cursor blink message
                return(new IntPtr(0));

            case Win32Native.WM_KEYDOWN:
            case Win32Native.WM_SYSKEYDOWN:
                winformSource.HandleKeyDown(wParam, lParam);
                if (richTextBox.TextLength == 0)
                {
                    var virtualKey = (System.Windows.Forms.Keys)wParam.ToInt64();
                    if (virtualKey == System.Windows.Forms.Keys.Back ||
                        virtualKey == System.Windows.Forms.Keys.Left ||
                        virtualKey == System.Windows.Forms.Keys.Right ||
                        virtualKey == System.Windows.Forms.Keys.Delete ||
                        virtualKey == System.Windows.Forms.Keys.Home ||
                        virtualKey == System.Windows.Forms.Keys.End ||
                        virtualKey == System.Windows.Forms.Keys.Up ||
                        virtualKey == System.Windows.Forms.Keys.Down)
                    {
                        // Swallow some keys when the text box is empty to prevent ding sound
                        return(new IntPtr(0));
                    }
                }
                break;

            case Win32Native.WM_KEYUP:
            case Win32Native.WM_SYSKEYUP:
                winformSource.HandleKeyUp(wParam, lParam);
                break;

            case Win32Native.WM_IME_COMPOSITION:
                OnComposition(hWnd, (int)lParam);
                break;

            case Win32Native.WM_NCPAINT:
            case Win32Native.WM_PAINT:
                var paintStruct = new Win32Native.PAINTSTRUCT();
                Win32Native.BeginPaint(hWnd, ref paintStruct);
                Win32Native.EndPaint(hWnd, ref paintStruct);

                // Don't paint the control
                return(new IntPtr(0));
            }
            return(Win32Native.CallWindowProc(oldWndProc, hWnd, msg, wParam, lParam));
        }