コード例 #1
0
        /// <summary>
        /// Registers the window class.
        /// </summary>
        private void RegisterWindowClass()
        {
            var wndClass = new NativeMethods.WNDCLASSEX();

            wndClass.cbSize        = (uint)Marshal.SizeOf(wndClass);
            wndClass.hInstance     = NativeMethods.GetModuleHandle(null);
            wndClass.lpfnWndProc   = NativeMethods.DefaultWindowProc;
            wndClass.lpszClassName = WindowClass;
            wndClass.hCursor       = NativeMethods.LoadCursor(IntPtr.Zero, NativeMethods.IDC_ARROW);

            NativeMethods.RegisterClassEx(ref wndClass);
        }
コード例 #2
0
        public void RegisterClass(ClassCreateParams ccp)
        {
            NativeMethods.WNDCLASSEX wc = new NativeMethods.WNDCLASSEX()
            {
                cbSize        = Marshal.SizeOf(typeof(NativeMethods.WNDCLASSEX)),
                lpszClassName = ccp.Name,
                lpfnWndProc   = ccp.WndProc,
                style         = (int)ccp.Style,
                cbClsExtra    = ccp.ExtraClassBytes,
                cbWndExtra    = ccp.ExtraWindowBytes,
                hbrBackground = ccp.BackgroundBrush,
                hInstance     = Marshal.GetHINSTANCE(this.GetType().Module)
            };

            if (NativeMethods.RegisterClassEx(ref wc) != 0)
            {
                throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());
            }
        }
コード例 #3
0
        /// <summary>
        /// Registers the window class.
        /// </summary>
        private void RegisterWindowClass()
        {
            var wndClass = new NativeMethods.WNDCLASSEX();
            wndClass.cbSize = (uint) Marshal.SizeOf(wndClass);
            wndClass.hInstance = NativeMethods.GetModuleHandle(null);
            wndClass.lpfnWndProc = NativeMethods.DefaultWindowProc;
            wndClass.lpszClassName = WindowClass;
            wndClass.hCursor = NativeMethods.LoadCursor(IntPtr.Zero, NativeMethods.IDC_ARROW);

            NativeMethods.RegisterClassEx(ref wndClass);
        }
コード例 #4
0
        private void RunMessagePump() {
            _threadId = NativeMethods.GetCurrentThreadId();

            //create the window to track sibling threads
            IntPtr user32 = NativeMethods.GetModuleHandle(NativeMethods.USER32);

            string name_DefWindowProc = Marshal.SystemDefaultCharSize == 1 ?
                "DefWindowProcA" : "DefWindowProcW";

            NativeMethods.WNDCLASSEX classEx = new NativeMethods.WNDCLASSEX();
            classEx.lpszClassName = CLASS_NAME;
            classEx.lpfnWndProc = NativeMethods.GetProcAddress(user32, name_DefWindowProc);
            classEx.cbSize = Marshal.SizeOf(typeof(NativeMethods.WNDCLASSEX));

            IntPtr classHandle = (IntPtr)NativeMethods.RegisterClassEx(classEx);
            IntPtr winHandle = NativeMethods.CreateWindowEx(0, classHandle, string.Empty
                , 0, 0, 0, 0, 0, (IntPtr)0, (IntPtr)0, (IntPtr)0, (IntPtr)0);

            //signal the message pump is up and running
            lock (_threadLock)
                Monitor.Pulse(_threadLock);
            //run message pump
            try {
                DispatchThreadMessages();
            } catch { }
        }