Exemple #1
0
        public Msn(List<IMsnGetter> msnHandlers)
        {
            _msnHandlers = msnHandlers;
            lpWndClass = new WNDCLASS
            {
                lpszClassName = lpClassName,
                lpfnWndProc = new WndProc(this.CustomWndProc)
            };

            ushort num = RegisterClassW(ref lpWndClass);
            int num2 = Marshal.GetLastWin32Error();
            if ((num == 0) && (num2 != 0x582))
            {
                throw new Exception("Could not register window class");
            }
            this.m_hwnd = CreateWindowExW(0, lpClassName, string.Empty, 0, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
        }
 public static extern short RegisterClassW(ref WNDCLASS wc);
 public static extern UInt16 RegisterClassW([In] ref WNDCLASS lpWndClass);
	[DllImport("user32", CallingConvention = CallingConvention.Winapi)] //ANSI
	public static extern int RegisterClassA(ref WNDCLASS wc);
        /// <summary>
        ///  Registers the native window class associated with the window
        ///  generated to display the splash window.
        /// </summary>
        /// <returns>True if the registration succeeded, false otherwise.</returns>
        private bool RegisterWindowClass()
        {
            bool result = false;

            WNDCLASS wc = new WNDCLASS();
            wc.style = 0;
            wc.lpfnWndProc = WindowProcedure = new WNDPROC(this.WndProc);
            wc.hInstance = GetModuleHandle(null);
            wc.hbrBackground = (IntPtr)(COLOR_WINDOW + 1);
            wc.lpszClassName = WindowClassName;
            wc.cbClsExtra = 0;
            wc.cbWndExtra = 0;
            wc.hIcon = IntPtr.Zero;
            wc.hCursor = IntPtr.Zero;
            wc.lpszMenuName = null;

            if (_showShadow && IsDropShadowSupported())
            {
                wc.style |= CS_DROPSHADOW;
            }

            if (RegisterClass(wc) != IntPtr.Zero)
            {
                result = true;
            }

            return result;
        }
Exemple #6
0
 internal static extern uint RegisterClass(ref WNDCLASS lpWndClass);
Exemple #7
0
 public static extern ushort RegisterClass(ref WNDCLASS lpWndClass);
Exemple #8
0
 static extern System.UInt16 RegisterClassW(
     [System.Runtime.InteropServices.In] ref WNDCLASS lpWndClass
     );
Exemple #9
0
 public static extern bool GetClassInfo(IntPtr hInstance, string lpClassName, out WNDCLASS lpWndClass);
 public static extern short RegisterClassW([In] ref WNDCLASS lpwc);
Exemple #11
0
        void Init()
        {
            var hInstance = Process.GetCurrentProcess().Handle;

            wndc = new WNDCLASS();

            wndProcDelegate = new WndProc(WindowProc);
            wndProcPtr      = Marshal.GetFunctionPointerForDelegate(wndProcDelegate);
            wndProcHandle   = GCHandle.Alloc(wndProcDelegate);

            wndc.style         = ClassStyles.HorizontalRedraw | ClassStyles.VerticalRedraw;
            wndc.lpfnWndProc   = wndProcPtr;
            wndc.cbClsExtra    = 0;
            wndc.cbWndExtra    = 0;
            wndc.hInstance     = hInstance;
            wndc.hIcon         = LoadIcon(IntPtr.Zero, new IntPtr((int)External.SystemIcons.IDI_APPLICATION));
            wndc.hCursor       = LoadCursor(IntPtr.Zero, (int)IdcStandardCursors.IDC_ARROW);
            wndc.hbrBackground = (IntPtr)(External.Color.WINDOW + 1);
            wndc.lpszMenuName  = null;
            wndc.lpszClassName = Title;

            var regResult = RegisterClass(ref wndc);

            if (regResult == 0)
            {
                Console.WriteLine("RegisterClassEx failed");
                Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
                return;
            }

            var hWnd = CreateWindowEx(
                WindowStylesEx.WS_EX_OVERLAPPEDWINDOW,
                new IntPtr((int)(uint)regResult),
                Title,
                WindowStyles.WS_OVERLAPPEDWINDOW,
                Constants.CW_USEDEFAULT,
                Constants.CW_USEDEFAULT,
                Width,
                Height,
                IntPtr.Zero,
                IntPtr.Zero,
                hInstance,
                IntPtr.Zero);

            if (hWnd == IntPtr.Zero)
            {
                Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
            }

            this.hWnd = hWnd;

            bitmap        = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);
            data          = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
            byteCount     = data.Stride * bitmap.Height;
            bytesPerColor = data.Stride / bitmap.Width;
            bytes         = new byte[byteCount];
            //Marshal.Copy(data.Scan0, bytes, 0, byteCount);

            bitmapHdc = CreateCompatibleDC(IntPtr.Zero);

            ShowWindow(hWnd, ShowWindowCommands.Normal);
            UpdateWindow(hWnd);
        }
Exemple #12
0
        public RGSSPlayer(string class_name)
        {
            if (class_name == null)
            {
                throw new System.Exception("class_name is null");
            }
            if (class_name == String.Empty)
            {
                throw new System.Exception("class_name is empty");
            }

            m_wnd_proc_delegate = CustomWndProc;

            // Create WNDCLASS
            WNDCLASS wind_class = new WNDCLASS();

            wind_class.lpszClassName = class_name;
            wind_class.lpfnWndProc   = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(m_wnd_proc_delegate);

            Bitmap myIco = new Bitmap("icon.ico");

            wind_class.hIcon = myIco.GetHicon();

            int Black_Brush = 4;

            wind_class.hbrBackground = GetStockObject(Black_Brush);

            uint dwStyle = ClassStyles.CS_DBLCLKS | ClassStyles.CS_OWNDC | ClassStyles.CS_HREDRAW | ClassStyles.CS_VREDRAW;

            wind_class.style     = dwStyle;
            wind_class.hInstance = Process.GetCurrentProcess().Handle;

            UInt16 class_atom = RegisterClassW(ref wind_class);

            int last_error = System.Runtime.InteropServices.Marshal.GetLastWin32Error();

            if (class_atom == 0 && last_error != ERROR_CLASS_ALREADY_EXISTS)
            {
                MessageBox.Show("Houve uma falha ao inicializar o Game.exe - Código 1");
                Application.Exit();
            }

            int width  = Defaults.nScreenWidth + System.Windows.Forms.SystemInformation.FixedFrameBorderSize.Width * 2;
            int height = Defaults.nScreenHeight + System.Windows.Forms.SystemInformation.FixedFrameBorderSize.Height * 2 + System.Windows.Forms.SystemInformation.CaptionHeight;

            uint wStyle = WindowStyles.WS_POPUP | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU | WindowStyles.WS_MINIMIZEBOX | WindowStyles.WS_VISIBLE;

            // Create window
            m_hwnd = CreateWindowExW(
                ExtendedWindowStyles.WS_EX_WINDOWEDGE,
                class_name,
                Defaults.pDefaultTitle,
                wStyle,
                (System.Windows.Forms.SystemInformation.PrimaryMonitorSize.Width - width) / 2,
                ((System.Windows.Forms.SystemInformation.PrimaryMonitorMaximizedWindowSize.Height - Defaults.nScreenHeight) / 2 - System.Windows.Forms.SystemInformation.CaptionHeight),
                Defaults.nScreenWidth,
                Defaults.nScreenHeight,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero
                );

            int SW_SHOW = 5;

            ShowWindow(m_hwnd, SW_SHOW);

            Port RPort, WPort;

            RPort = new Port();
            WPort = new Port();


            RGSS.Initialize(m_hwnd);
            RGSS.SetupFonts();

            //Thread thr = new Thread(WingOfDomain);
            //thr.Start();

            //	1、设置RTP
            StringBuilder szRtpName = new StringBuilder(1024);

            if (!RGSS.SetupRTP(System.Environment.CurrentDirectory + Defaults.pDefaultRTP, szRtpName, 1024))
            {
                MessageBox.Show("Houve uma falha ao inicializar o Game.exe - Código 2");
                Application.Exit();
            }

            RGSS.Eval(String.Format("WriterLock = {0}\nWriteBuffer = {1}\n", RPort.Lock.ToString(), RPort.Buffer.ToString()));
            RGSS.Eval(String.Format("ReaderLock = {0}\nReaderBuffer = {1}\n", WPort.Lock.ToString(), WPort.Buffer.ToString()));

            //byte[] charb = new byte[8];
            //Defaults.DecryptFile(AppDomain.CurrentDomain.BaseDirectory + "Parse\\parse.wingofdev", AppDomain.CurrentDomain.BaseDirectory + "Parse\\parsecached.wingofdev", "0011011W");

            RGSS.GameMain(m_hwnd, Defaults.pDefaultScripts, "\0\0\0\0");
        }
Exemple #13
0
 internal static extern IntPtr RegisterClass(WNDCLASS wc);
Exemple #14
0
        private void CreateWindow(string className)
        {
            if (className == null)
            {
                throw new Exception("class_name is null");
            }
            if (className == String.Empty)
            {
                throw new Exception("class_name is empty");
            }

            _wndProcDelegate = CustomWndProc;

            gcHandle = System.Runtime.InteropServices.GCHandle.Alloc(_wndProcDelegate);

            WNDCLASS windClass = new WNDCLASS
            {
                cbClsExtra    = 0,
                cbWndExtra    = 0,
                hbrBackground = IntPtr.Zero,
                hCursor       = IntPtr.Zero,
                hIcon         = IntPtr.Zero,
                lpfnWndProc   = Marshal.GetFunctionPointerForDelegate(_wndProcDelegate),
                lpszClassName = className,
                lpszMenuName  = null,
                style         = 0
            };

            ushort classAtom = User32.RegisterClassW(ref windClass);

            int lastError = Marshal.GetLastWin32Error();

            if (classAtom == 0 && lastError != ERROR_CLASS_ALREADY_EXISTS)
            {
                throw new Exception("Could not register window class");
            }


            var owner = User32.GetWindow(_parentHandle, GetWindowCommands.GW_OWNER);

            _handle = User32.CreateWindowEx(
                (int)(WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_LTRREADING | WindowExStyles.WS_EX_LAYERED | WindowExStyles.WS_EX_TOOLWINDOW | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_NOACTIVATE | WindowExStyles.WS_EX_TRANSPARENT),
                new IntPtr(classAtom),
                className,
                //-(WindowStyles.WS_VISIBLE | WindowStyles.WS_MINIMIZE | WindowStyles.WS_CHILDWINDOW | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_DISABLED | WindowStyles.WS_POPUP),
                (WindowStyles.WS_POPUP | WindowStyles.WS_VISIBLE | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_CLIPCHILDREN),
                0, 0, 0, 0, owner, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

            if (_handle == IntPtr.Zero)
            {
                return;
            }

            //const UInt32 extendedStyle = (UInt32)(
            //	WindowExStyles.WS_EX_LEFT |
            //	WindowExStyles.WS_EX_LTRREADING |
            //	WindowExStyles.WS_EX_RIGHTSCROLLBAR |
            //	WindowExStyles.WS_EX_TOOLWINDOW);

            //const UInt32 style = (UInt32)(
            //	WindowStyles.WS_CLIPSIBLINGS |
            //	WindowStyles.WS_CLIPCHILDREN |
            //	WindowStyles.WS_POPUP);

            //// Create window
            //_handle = User32.CreateWindowExW(
            //	extendedStyle,
            //	className,
            //	className,
            //	style,
            //	0,
            //	0,
            //	0,
            //	0,
            //	IntPtr.Zero,
            //	IntPtr.Zero,
            //	IntPtr.Zero,
            //	IntPtr.Zero
            //);

            //if (_handle == IntPtr.Zero)
            //{
            //	return;
            //}

            //uint styles = User32.GetWindowLong(_handle, GetWindowLongFlags.GWL_EXSTYLE);
            //styles = styles | (int)WindowExStyles.WS_EX_LAYERED | (int)WindowExStyles.WS_EX_NOACTIVATE | (int)WindowExStyles.WS_EX_TRANSPARENT;
            //User32.SetWindowLong(_handle, GetWindowLongFlags.GWL_EXSTYLE, styles);
        }
Exemple #15
0
        /// <summary>
        /// Creates a new instance of PageantWindow that acts as a server for
        /// Putty-type clients.    
        /// </summary>
        /// <exception cref="PageantRunningException">
        /// Thrown when another instance of Pageant is running.
        /// </exception>
        /// <remarks>This window is not meant to be used for UI.</remarks>
        public PageantAgent()
        {
            DoOSCheck();

              if (CheckPageantRunning()) {
            throw new PageantRunningException();
              }

              // create reference to delegate so that garbage collector does not eat it.
              customWndProc = new WndProc(CustomWndProc);

              // Create WNDCLASS
              WNDCLASS wind_class = new WNDCLASS();
              wind_class.lpszClassName = className;
              wind_class.lpfnWndProc = customWndProc;

              UInt16 class_atom = RegisterClassW(ref wind_class);

              int last_error = Marshal.GetLastWin32Error();
              if (class_atom == 0 && last_error != ERROR_CLASS_ALREADY_EXISTS) {
            throw new Exception("Could not register window class");
              }

              Thread winThread = new Thread(RunWindowInNewAppcontext);
              winThread.SetApartmentState(ApartmentState.STA);
              winThread.Name = "PageantWindow";
              lock (lockObject) {
            winThread.Start();
            // wait for window to be created before continuing to prevent more than
            // one instance being run at a time.
            if (!Monitor.Wait(lockObject, 5000))
            {
              if (winThread.ThreadState == System.Threading.ThreadState.Running)
              {
            throw new TimeoutException("PageantAgent start timed out.");
              }
              else
              {
            throw new Exception("PageantAgent failed to start.");
              }
            }
              }
        }
Exemple #16
0
 private static extern short RegisterClass(WNDCLASS wc);
 public static partial short RegisterClassW(ref WNDCLASS wc);
Exemple #18
0
            public CustomWindow(string class_name)
            {
                SDL.SDL_SysWMinfo info = new SDL.SDL_SysWMinfo();
                SDL.SDL_VERSION(out info.version);
                SDL.SDL_GetWindowWMInfo(SDL.SDL_GL_GetCurrentWindow(), ref info);

                IntPtr hwnd = IntPtr.Zero;

                if (info.subsystem == SDL.SDL_SYSWM_TYPE.SDL_SYSWM_WINDOWS)
                {
                    hwnd = info.info.win.window;
                }

                if (class_name == null)
                {
                    throw new Exception("class_name is null");
                }
                if (class_name == string.Empty)
                {
                    throw new Exception("class_name is empty");
                }

                m_wnd_proc_delegate = CustomWndProc;

                // Create WNDCLASS
                WNDCLASS wind_class = new WNDCLASS
                {
                    hInstance     = hwnd,
                    lpszClassName = class_name,
                    lpfnWndProc   = Marshal.GetFunctionPointerForDelegate(m_wnd_proc_delegate)
                };

                ushort class_atom = RegisterClassW(ref wind_class);

                int last_error = Marshal.GetLastWin32Error();

                if (class_atom == 0 && last_error != ERROR_CLASS_ALREADY_EXISTS)
                {
                    throw new Exception("Could not register window class");
                }



                // Create window
                m_hwnd = CreateWindowExW(
                    0,
                    class_name,
                    class_name,
                    0,
                    0,
                    0,
                    0,
                    0,
                    IntPtr.Zero,
                    IntPtr.Zero,
                    hwnd,
                    IntPtr.Zero
                    );

                if (m_hwnd != IntPtr.Zero)
                {
                    ShowWindow(m_hwnd, 0);
                }
            }
Exemple #19
0
 public static extern ushort RegisterClass(
     ref WNDCLASS pcWndClassEx);
Exemple #20
0
 public static extern ATOM RegisterClassW(ref WNDCLASS Arg1);
Exemple #21
0
        public RegisterWindow(string className, Action <DataAndType> callback)
        {
            if (className == null)
            {
                throw new System.Exception("class_name is null");
            }
            if (className == String.Empty)
            {
                throw new System.Exception("class_name is empty");
            }


            CustomWndProc = callback;

            m_wnd_proc_delegate = ProxyWndProc;

            // Create WNDCLASS
            WNDCLASS wind_class = new WNDCLASS();

            wind_class.lpszClassName = className;
            wind_class.lpfnWndProc   = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(m_wnd_proc_delegate);

            UInt16 class_atom = RegisterClassW(ref wind_class);

            int last_error = System.Runtime.InteropServices.Marshal.GetLastWin32Error();

            if (class_atom == 0 && last_error != ERROR_CLASS_ALREADY_EXISTS)
            {
                throw new System.Exception("Could not register window class");
            }

            // Create window
            m_hwnd = CreateWindowExW(
                0,
                className,
                String.Empty,
                0,
                0,
                0,
                0,
                0,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero
                );
            logger.Info("Created window with hwnd " + m_hwnd);

            // This should allow IA to receive messages from GD, even if IA is running as admin.
            if (!ChangeWindowMessageFilterEx(m_hwnd, WM_COPYDATA, ChangeWindowMessageFilterExAction.Allow, IntPtr.Zero))
            {
                var isAdmin = (new WindowsPrincipal(WindowsIdentity.GetCurrent())).IsInRole(WindowsBuiltInRole.Administrator);
                logger.Warn("Failed to remove UIPI filter restrictions.");
                if (isAdmin)
                {
                    logger.Fatal("Running as administrator, IA will not be able to communicate with GD due to UIPI filter.");
                }
                else
                {
                    logger.Info("Not running as administrator, UIPI filter not required.");
                }
            }
        }
 private static extern IntPtr RegisterClass(WNDCLASS wc);
Exemple #23
0
 public static extern IntPtr RegisterClass(WNDCLASS wc);
Exemple #24
0
        public static IntPtr CreateDummyWindowHandle()
        {
            // Based on MSDN sample code
            // found at http://msdn.microsoft.com/en-us/library/cc656710.aspx

            const int CS_HREDRAW = 1;
            const int CS_VREDRAW = 2;

            WNDCLASS wc = new WNDCLASS()
            {
                style = CS_HREDRAW | CS_VREDRAW,
                lpfnWndProc = DefWindowProcKeepAlive,
                cbClsExtra = 0,
                cbWndExtra = 0,
                hInstance = IntPtr.Zero,
                hIcon = IntPtr.Zero,
                hCursor = IntPtr.Zero,
                hbrBackground = IntPtr.Zero,
                lpszMenuName = null,
                lpszClassName = Global.AppName,
            };

            var atom = RegisterClassW(ref wc);
            if (0 == atom)
                throw new Win32Exception("Unable to RegisterClassW for dummy window.");

            var hwnd = CreateWindowEx(0, (uint)atom, Global.AppName, WindowStyles.WS_OVERLAPPEDWINDOW,
                0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

            if (hwnd == IntPtr.Zero)
                throw new Win32Exception("Unable to CreateWindowExW for dummy window.");

            return hwnd;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RemovableDriveMonitor"/> class. 
        /// Default Constructor
        /// </summary>
        public RemovableDriveMonitor()
        {
            var wc = new WNDCLASS();

            // Preventing garbage collection of the delegate
            dontGCthis = new WndProc(this.Callback);
            wc.lpfnWndProc = dontGCthis;

            // Note that you need to ensure unique names 
            // for each registered class.
            // For example, if you open the same plugin 
            // in two different tabs of the browser,
            // you still should not end up with 
            // two registered classes with identical names.
            wc.lpszClassName = "foobar" + (new Random()).Next();

            RegisterClass(wc);

            var createResult = CreateWindowEx(0, wc.lpszClassName, "Window title", 0, 100, 100, 500, 500, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, 0);
        }
Exemple #26
0
 private static extern int RegisterClass(ref WNDCLASS wndclass);
 public static extern short RegisterClass(WNDCLASS wc);
Exemple #28
0
 public static extern ushort RegisterClass(
     ref WNDCLASS pcWndClassEx);
Exemple #29
0
 public static extern BOOL GetClassInfoW(HandleRef hInstance, string lpClassName, ref WNDCLASS lpWndClass);
Exemple #30
0
 private static extern IntPtr RegisterClass(WNDCLASS wc);
Exemple #31
0
 public static partial bool GetClassInfoW(IntPtr hInst, string lpszClass, ref WNDCLASS wc);
Exemple #32
0
        private void CreateWindow(string className)
        {
            if (className == null)
            {
                throw new Exception("class_name is null");
            }
            if (className == String.Empty)
            {
                throw new Exception("class_name is empty");
            }

            _wndProcDelegate = CustomWndProc;

            gcHandle = GCHandle.Alloc(_wndProcDelegate);

            WNDCLASS windClass = new WNDCLASS
            {
                lpszClassName = className,
                lpfnWndProc   = Marshal.GetFunctionPointerForDelegate(_wndProcDelegate)
            };

            ushort classAtom = User32.RegisterClassW(ref windClass);

            int lastError = Marshal.GetLastWin32Error();

            if (classAtom == 0 && lastError != ERROR_CLASS_ALREADY_EXISTS)
            {
                throw new Exception("Could not register window class");
            }

            uint extendedStyle = (uint)(
                WindowExStyles.WS_EX_LEFT |
                WindowExStyles.WS_EX_LTRREADING |
                WindowExStyles.WS_EX_RIGHTSCROLLBAR |
                WindowExStyles.WS_EX_TOOLWINDOW);



            const uint style = (uint)(
                WindowStyles.WS_CLIPSIBLINGS |
                WindowStyles.WS_CLIPCHILDREN |
                WindowStyles.WS_POPUP);


            // Create window
            Handle = User32.CreateWindowExW(
                extendedStyle,
                className,
                className,
                style,
                0,
                0,
                0,
                0,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero
                );

            if (Handle == IntPtr.Zero)
            {
                return;
            }

            var styles = (int)User32.GetWindowLongPtr(Handle, WindowLongFlags.GWL_EXSTYLE);

            //var owner = User32.GetWindow(_parentHandle, 4);

            //User32.SetWindowLong(Handle, GetWindowLongFlags.GWL_HWNDPARENT, owner);

            styles |= (int)(WindowExStyles.WS_EX_LAYERED | WindowExStyles.WS_EX_NOACTIVATE | WindowExStyles.WS_EX_NOPARENTNOTIFY);

            if (!_decorator.Resizable)
            {
                styles |= (int)WindowExStyles.WS_EX_TRANSPARENT;
            }

            User32.SetWindowLongPtr(Handle, WindowLongFlags.GWL_EXSTYLE, new IntPtr(styles));

            _screenDC = User32.GetDC(IntPtr.Zero);
            _memDC    = Gdi32.CreateCompatibleDC(_screenDC);

            D2D1.D2D1CreateFactory(FactoryType.SingleThreaded, out _d2dFactory);
        }
Exemple #33
0
 private static extern System.UInt16 RegisterClassW([In] ref WNDCLASS lpWndClass);
Exemple #34
0
        private void CreateWindow(string className)
        {
            if (className == null)
            {
                throw new Exception("class_name is null");
            }
            if (className == String.Empty)
            {
                throw new Exception("class_name is empty");
            }

            _wndProcDelegate = CustomWndProc;

            gcHandle = GCHandle.Alloc(_wndProcDelegate);

            WNDCLASS windClass = new WNDCLASS
            {
                lpszClassName = className,
                lpfnWndProc   = Marshal.GetFunctionPointerForDelegate(_wndProcDelegate)
            };

            ushort classAtom = User32.RegisterClassW(ref windClass);

            int lastError = Marshal.GetLastWin32Error();

            if (classAtom == 0 && lastError != ERROR_CLASS_ALREADY_EXISTS)
            {
                throw new Exception("Could not register window class");
            }

            const UInt32 extendedStyle = (UInt32)(
                WindowExStyles.WS_EX_LEFT |
                WindowExStyles.WS_EX_LTRREADING |
                WindowExStyles.WS_EX_RIGHTSCROLLBAR |
                WindowExStyles.WS_EX_TOOLWINDOW);

            const UInt32 style = (UInt32)(
                WindowStyles.WS_CLIPSIBLINGS |
                WindowStyles.WS_CLIPCHILDREN |
                WindowStyles.WS_POPUP);

            var owner = User32.GetWindow(_parentHandle, 4);

            // Create window
            _handle = User32.CreateWindowExW(
                extendedStyle,
                className,
                className,
                style,
                0,
                0,
                0,
                0,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero
                );

            if (_handle == IntPtr.Zero)
            {
                return;
            }

            uint styles = User32.GetWindowLong(_handle, GetWindowLongFlags.GWL_EXSTYLE);

            styles = styles | (int)WindowExStyles.WS_EX_LAYERED | (int)WindowExStyles.WS_EX_NOACTIVATE | (int)WindowExStyles.WS_EX_TRANSPARENT;
            User32.SetWindowLong(_handle, GetWindowLongFlags.GWL_EXSTYLE, styles);
        }
 public static extern bool GetClassInfoW(IntPtr hInst, string lpszClass, ref WNDCLASS wc);
 public static extern ushort RegisterClass([In] ref WNDCLASS lpWndClass);
 public static extern Atom RegisterClassW(ref WNDCLASS lpWndClass);
Exemple #38
0
 private static extern ushort RegisterClassW(
     [In] ref WNDCLASS lpWndClass
     );
Exemple #39
0
        public IntPtr CreateWindow()
        {
            //TODO: possible race condition if CreateWindow is called from multiple threads.
            if (windowHandle != IntPtr.Zero)
            {
                throw new InvalidOperationException("Only a single call to CreateWindow is allowed per WindowCreator instance.");
            }

            var windowCreatedEvent = new ManualResetEvent(false);

            var windowThreadStart = new ThreadStart(() =>
            {
                // ideally, the HINSTANCE of this dll should be used, not the host application's.
                // we mitigate potential window class name collisions by 'randomizing' the name in the constructor.
                IntPtr instanceHandle = Process.GetCurrentProcess().Handle;

                WNDCLASS windowClass      = new WNDCLASS();
                windowClass.style         = 0;
                windowClass.lpfnWndProc   = new WndProc(WndProcDelegate);
                windowClass.cbClsExtra    = 0;
                windowClass.cbWndExtra    = 0;
                windowClass.hInstance     = instanceHandle;
                windowClass.hIcon         = IntPtr.Zero; //LoadIcon(IntPtr.Zero, new IntPtr((int)SystemIcons.IDI_APPLICATION));
                windowClass.hCursor       = IntPtr.Zero; //LoadCursor(IntPtr.Zero, (int)IdcStandardCursors.IDC_ARROW);
                windowClass.hbrBackground = IntPtr.Zero; //GetStockObject(StockObjects.WHITE_BRUSH);
                windowClass.lpszMenuName  = null;
                windowClass.lpszClassName = windowClassName;

                ushort regResult = RegisterClass(ref windowClass);

                if (regResult == 0)
                {
                    throw new Win32Exception();
                }

                var hwnd = CreateWindowEx(
                    WindowStylesEx.WS_EX_NOACTIVATE | WindowStylesEx.WS_EX_TRANSPARENT,
                    new IntPtr((int)(uint)regResult),
                    "Pluralinput.Sdk Window",
                    WindowStyles.WS_DISABLED,
                    CW_USEDEFAULT,
                    CW_USEDEFAULT,
                    CW_USEDEFAULT,
                    CW_USEDEFAULT,
                    IntPtr.Zero,
                    IntPtr.Zero,
                    instanceHandle,
                    IntPtr.Zero);

                if (hwnd == IntPtr.Zero)
                {
                    throw new Win32Exception();
                }

                windowHandle = hwnd;
                windowCreatedEvent.Set();

                // no need to show a hidden window.
                //ShowWindow(hwnd, (int)ShowWindowCommands.Hide);
                UpdateWindow(hwnd);

                MSG msg;
                while (!isDisposed && GetMessage(out msg, IntPtr.Zero, 0, 0) != 0)
                {
                    TranslateMessage(ref msg);
                    DispatchMessage(ref msg);
                }
            });

            var windowThread = new Thread(windowThreadStart)
            {
                Name = "PluralinputSDKBackgroundWindowThread"
            };

            windowThread.Start();

            windowCreatedEvent.WaitOne();

            return(windowHandle);
        }
Exemple #40
0
		private extern static bool Win32RegisterClass(ref WNDCLASS wndClass);
        private void CreateOpenGLContext(IntPtr hwnd)
        {
            this.hwnd = hwnd;

            this.hDC = GetDC(hwnd);

            var pixelformatdescriptor = new PIXELFORMATDESCRIPTOR();

            pixelformatdescriptor.Init();

#if !USE_MSAA
            int pixelFormat;
            pixelFormat = ChoosePixelFormat(this.hDC, ref pixelformatdescriptor);
            SetPixelFormat(this.hDC, pixelFormat, ref pixelformatdescriptor);

            this.hglrc = wglCreateContext(this.hDC);
            wglMakeCurrent(this.hDC, this.hglrc);
#else
            IntPtr tempContext = IntPtr.Zero;
            IntPtr tempHwnd    = IntPtr.Zero;
            //Create temporary window
            IntPtr hInstance = Process.GetCurrentProcess().SafeHandle.DangerousGetHandle();

            WNDCLASS wndclass = new WNDCLASS()
            {
                style         = 0x0002 /*CS_HREDRAW*/ | 0x0001 /*CS_VREDRAW*/ | 0x0020 /*CS_OWNDC*/,
                lpfnWndProc   = (hWnd, msg, wParam, lParam) => DefWindowProc(hWnd, msg, wParam, lParam),
                hInstance     = hInstance,
                lpszClassName = "tmpWindowForMSAA~" + this.GetHashCode()
            };
            ushort atom = RegisterClassW(ref wndclass);
            if (atom == 0)
            {
                throw new WindowCreateException(string.Format("RegisterClass error: {0}", Marshal.GetLastWin32Error()));
            }

            tempHwnd = CreateWindowEx(
                0,
                new IntPtr(atom),
                "tmpWindow~",
                (uint)(WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_CLIPCHILDREN),
                0, 0, 1, 1, hwnd, IntPtr.Zero,
                hInstance,
                IntPtr.Zero);
            if (tempHwnd == IntPtr.Zero)
            {
                throw new WindowCreateException(string.Format("CreateWindowEx for tempContext error: {0}", Marshal.GetLastWin32Error()));
            }

            IntPtr tempHdc = GetDC(tempHwnd);

            var tempPixelFormat = ChoosePixelFormat(tempHdc, ref pixelformatdescriptor);
            if (tempPixelFormat == 0)
            {
                throw new Exception(string.Format("ChoosePixelFormat failed: error {0}", Marshal.GetLastWin32Error()));
            }

            if (!SetPixelFormat(tempHdc, tempPixelFormat, ref pixelformatdescriptor))
            {
                throw new Exception(string.Format("SetPixelFormat failed: error {0}", Marshal.GetLastWin32Error()));
            }

            tempContext = Wgl.CreateContext(tempHdc);//Crate temp context to load entry points
            if (tempContext == IntPtr.Zero)
            {
                throw new Exception(string.Format("wglCreateContext for tempHdc failed: error {0}", Marshal.GetLastWin32Error()));
            }

            if (!Wgl.MakeCurrent(tempHdc, tempContext))
            {
                throw new Exception(string.Format("wglMakeCurrent for tempContext failed: error {0}", Marshal.GetLastWin32Error()));
            }

            //load wgl entry points for wglChoosePixelFormatARB
            new Wgl().LoadEntryPoints(tempHdc);

            int[] iPixAttribs =
            {
                (int)WGL.WGL_SUPPORT_OPENGL_ARB, (int)GL.GL_TRUE,
                (int)WGL.WGL_DRAW_TO_WINDOW_ARB, (int)GL.GL_TRUE,
                (int)WGL.WGL_DOUBLE_BUFFER_ARB,  (int)GL.GL_TRUE,
                (int)WGL.WGL_PIXEL_TYPE_ARB,     (int)WGL.WGL_TYPE_RGBA_ARB,
                (int)WGL.WGL_ACCELERATION_ARB,   (int)WGL.WGL_FULL_ACCELERATION_ARB,
                (int)WGL.WGL_COLOR_BITS_ARB,                                     32,
                (int)WGL.WGL_DEPTH_BITS_ARB,                                     24,
                (int)WGL.WGL_STENCIL_BITS_ARB,                                    8,
                (int)WGL.WGL_SWAP_METHOD_ARB,    (int)WGL.WGL_SWAP_EXCHANGE_ARB,
                (int)WGL.WGL_SAMPLE_BUFFERS_ARB, (int)GL.GL_TRUE,//Enable MSAA
                (int)WGL.WGL_SAMPLES_ARB,                                        16,
                0
            };

            int  pixelFormat;
            uint numFormats;
            var  result = Wgl.ChoosePixelFormatARB(this.hDC, iPixAttribs, null, 1, out pixelFormat, out numFormats);
            if (result == false || numFormats == 0)
            {
                throw new Exception(string.Format("wglChoosePixelFormatARB failed: error {0}", Marshal.GetLastWin32Error()));
            }

            if (!DescribePixelFormat(this.hDC, pixelFormat, (uint)Marshal.SizeOf <PIXELFORMATDESCRIPTOR>(), ref pixelformatdescriptor))
            {
                throw new Exception(string.Format("DescribePixelFormat failed: error {0}", Marshal.GetLastWin32Error()));
            }

            if (!SetPixelFormat(this.hDC, pixelFormat, ref pixelformatdescriptor))
            {
                throw new Exception(string.Format("SetPixelFormat failed: error {0}", Marshal.GetLastWin32Error()));
            }

            if ((this.hglrc = wglCreateContext(this.hDC)) == IntPtr.Zero)
            {
                throw new Exception(string.Format("wglCreateContext failed: error {0}", Marshal.GetLastWin32Error()));
            }

            Wgl.MakeCurrent(IntPtr.Zero, IntPtr.Zero);
            Wgl.DeleteContext(tempContext);
            ReleaseDC(tempHwnd, tempHdc);
            DestroyWindow(tempHwnd);

            if (!wglMakeCurrent(this.hDC, this.hglrc))
            {
                throw new Exception(string.Format("wglMakeCurrent failed: error {0}", Marshal.GetLastWin32Error()));
            }

            Utility.CheckGLError();
#endif

            GL.GetIntegerv(GL.GL_STENCIL_BITS, IntBuffer);
            var stencilBits = IntBuffer[0];
            if (stencilBits != 8)
            {
                throw new Exception("Failed to set stencilBits to 9.");
            }
            PrintGraphicInfo();
        }
 private static extern int RegisterClass(ref WNDCLASS wndclass);
Exemple #43
0
        public void registerClassName(string class_name)
        {
            if (class_name == null) throw new System.Exception("class_name is null");
            if (class_name == String.Empty) throw new System.Exception("class_name is empty");

            WndProc m_wnd_proc_delegate = CustomWndProc;

            // Create WNDCLASS
            WNDCLASS wind_class = new WNDCLASS();
            wind_class.lpszClassName = class_name;
            wind_class.lpfnWndProc = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(m_wnd_proc_delegate);

            UInt16 class_atom = RegisterClassW(ref wind_class);

            int last_error = System.Runtime.InteropServices.Marshal.GetLastWin32Error();

            if (class_atom == 0 && last_error != ERROR_CLASS_ALREADY_EXISTS)
            {
                throw new System.Exception("Could not register window class");
            }
        }