Пример #1
0
 public static extern short RegisterClassEx(ref WNDCLASSEX lpwcx);
        public NativeWindowEx()
        {
            _CtrlWndProc = new WndProcDelegate(WndProc);
            _DefWndProc  = new WndProcDelegate(Win32Interop.DefWindowProc);

            #region Control Window

            WNDCLASSEX ctrlWndClsEx = new WNDCLASSEX();
            ctrlWndClsEx.Init();
            ctrlWndClsEx.style         = 0;
            ctrlWndClsEx.lpfnWndProc   = _CtrlWndProc;
            ctrlWndClsEx.cbClsExtra    = 0;
            ctrlWndClsEx.cbWndExtra    = 0;
            ctrlWndClsEx.hInstance     = Win32Interop.GetModuleHandle(null);
            ctrlWndClsEx.hIcon         = IntPtr.Zero;
            ctrlWndClsEx.hIconSm       = IntPtr.Zero;
            ctrlWndClsEx.hCursor       = IntPtr.Zero;
            ctrlWndClsEx.hbrBackground = IntPtr.Zero;
            ctrlWndClsEx.lpszClassName = _CtrlWndClassName;
            ctrlWndClsEx.lpszMenuName  = null;

            if (Win32Interop.RegisterClassEx(ref ctrlWndClsEx) == 0)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "RegisterClassEx failed.");
            }
            Handle = Win32Interop.CreateWindowEx(ExtendedWndStyle.WS_EX_LAYERED | ExtendedWndStyle.WS_EX_NOACTIVATE, _CtrlWndClassName, null, WndStyle.WS_POPUP, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, Win32Interop.GetModuleHandle(null), IntPtr.Zero);
            if (Handle == IntPtr.Zero)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "CreateWindowEx failed.");
            }
            Win32Interop.SetLayeredWindowAttributes(Handle, 0, 1, UpdateLayerWindowParameter.ULW_ALPHA);

            #endregion

            #region Rendering Window

            WNDCLASSEX renderingWndClsEx = new WNDCLASSEX();
            renderingWndClsEx.Init();
            renderingWndClsEx.style         = WndClassType.CS_VREDRAW | WndClassType.CS_HREDRAW;
            renderingWndClsEx.lpfnWndProc   = _DefWndProc;
            renderingWndClsEx.cbClsExtra    = 0;
            renderingWndClsEx.cbWndExtra    = 0;
            renderingWndClsEx.hInstance     = Win32Interop.GetModuleHandle(null);
            renderingWndClsEx.hIcon         = IntPtr.Zero;
            renderingWndClsEx.hIconSm       = IntPtr.Zero;
            renderingWndClsEx.hCursor       = IntPtr.Zero;
            renderingWndClsEx.hbrBackground = IntPtr.Zero;
            renderingWndClsEx.lpszClassName = _RenderingWndClassName;
            renderingWndClsEx.lpszMenuName  = null;

            if (Win32Interop.RegisterClassEx(ref renderingWndClsEx) == 0)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "RegisterClassEx failed.");
            }
            _RenderingHwnd = Win32Interop.CreateWindowEx(ExtendedWndStyle.WS_EX_LAYERED | ExtendedWndStyle.WS_EX_TRANSPARENT | ExtendedWndStyle.WS_EX_NOACTIVATE, _RenderingWndClassName, null, WndStyle.WS_POPUP, 0, 0, 0, 0, Handle, IntPtr.Zero, Win32Interop.GetModuleHandle(null), IntPtr.Zero);
            if (_RenderingHwnd == IntPtr.Zero)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "CreateWindowEx failed.");
            }

            #endregion
        }