Esempio n. 1
0
        public WindowsMessageSink(uint id)
        {
            this.Callback = (IntPtr hwnd, uint uMsg, IntPtr wparam, IntPtr lparam) =>
            {
                if (uMsg == id)
                {
                    switch ((int)lparam)
                    {
                    case MOUSE_MOVE:
                        this.OnMouseMove();
                        break;

                    case MOUSE_LEFT_DOWN:
                        this.OnMouseLeftButtonDown();
                        break;

                    case MOUSE_LEFT_UP:
                        this.OnMouseLeftButtonUp();
                        break;

                    case MOUSE_DOUBLE_CLICK:
                        this.OnMouseDoubleClick();
                        break;

                    case MOUSE_RIGHT_DOWN:
                        this.OnMouseRightButtonDown();
                        break;

                    case MOUSE_RIGHT_UP:
                        this.OnMouseRightButtonUp();
                        break;
                    }
                }
                else if (uMsg == WM_TASKBARCREATED)
                {
                    this.OnTaskBarCreated();
                }
                return(DefWindowProc(hwnd, uMsg, wparam, lparam));
            };
            var windowClass = WindowClass.Create(ID, this.Callback);

            RegisterClass(ref windowClass);
            this.Handle = CreateWindowEx(0, ID, string.Empty, 0, 0, 0, 1, 1, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
        }
Esempio n. 2
0
        static void Main()
        {
            const int kWidth  = 480;
            const int kHeight = 272;

            var hwnd = WindowClass.Create(10, 10, kWidth, kHeight);

            WindowClass.ShowWindow(hwnd, WindowClass.ShowWindowCommands.Normal);
            WindowClass.UpdateWindow(hwnd);

            if (EGLContext.InitWindows(hwnd, WindowClass.GetDC(IntPtr.Zero)))
            {
                mApplication = new SmartApp.WVGA.Sparc.SmartApp().GetConfigureApplication(Application.Type.Windows, kWidth, kHeight);
                mApplication.Run(Swap, WindowClass.DispatchMessages);
            }
            EGLContext.Dispose();

            Console.WriteLine("Oops, cann't init OpenVG library");
        }
Esempio n. 3
0
 public virtual void CreateHandle(CreateParams cp)
 {
     System.Windows.Forms.IntSecurity.CreateAnyWindow.Demand();
     if (((cp.Style & 0x40000000) != 0x40000000) || (cp.Parent == IntPtr.Zero))
     {
         System.Windows.Forms.IntSecurity.TopLevelWindow.Demand();
     }
     lock (this)
     {
         this.CheckReleased();
         WindowClass class2 = WindowClass.Create(cp.ClassName, cp.ClassStyle);
         lock (createWindowSyncObject)
         {
             if (this.handle == IntPtr.Zero)
             {
                 class2.targetWindow = this;
                 IntPtr moduleHandle = System.Windows.Forms.UnsafeNativeMethods.GetModuleHandle(null);
                 IntPtr zero         = IntPtr.Zero;
                 int    error        = 0;
                 try
                 {
                     if ((cp.Caption != null) && (cp.Caption.Length > 0x7fff))
                     {
                         cp.Caption = cp.Caption.Substring(0, 0x7fff);
                     }
                     zero  = System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(cp.ExStyle, class2.windowClassName, cp.Caption, cp.Style, cp.X, cp.Y, cp.Width, cp.Height, new HandleRef(cp, cp.Parent), System.Windows.Forms.NativeMethods.NullHandleRef, new HandleRef(null, moduleHandle), cp.Param);
                     error = Marshal.GetLastWin32Error();
                 }
                 catch (NullReferenceException exception)
                 {
                     throw new OutOfMemoryException(System.Windows.Forms.SR.GetString("ErrorCreatingHandle"), exception);
                 }
                 class2.targetWindow = null;
                 if (zero == IntPtr.Zero)
                 {
                     throw new Win32Exception(error, System.Windows.Forms.SR.GetString("ErrorCreatingHandle"));
                 }
                 this.ownHandle = true;
                 System.Internal.HandleCollector.Add(zero, System.Windows.Forms.NativeMethods.CommonHandles.Window);
             }
         }
     }
 }
Esempio n. 4
0
        public virtual void CreateHandle(CreateParams cp)
        {
            lock (this)
            {
                CheckReleased();
                WindowClass windowClass = WindowClass.Create(cp.ClassName, (User32.CS)cp.ClassStyle);
                lock (s_createWindowSyncObject)
                {
                    // The CLR will sometimes pump messages while we're waiting on the lock.
                    // If a message comes through (say a WM_ACTIVATE for the parent) which
                    // causes the handle to be created, we can try to create the handle twice
                    // for NativeWindow. Check the handle again to avoid this.
                    if (Handle != IntPtr.Zero)
                    {
                        return;
                    }

                    windowClass._targetWindow = this;
                    IntPtr createResult   = IntPtr.Zero;
                    int    lastWin32Error = 0;

                    // Parking window dpi awareness context need to match with dpi awareness context of control being
                    // parented to this parking window. Otherwise, reparenting of control will fail.
                    using (DpiHelper.EnterDpiAwarenessScope(DpiAwarenessContext))
                    {
                        IntPtr modHandle = Kernel32.GetModuleHandleW(null);

                        // Older versions of Windows AV rather than returning E_OUTOFMEMORY.
                        // Catch this and then we re-throw an out of memory error.
                        try
                        {
                            // CreateWindowEx throws if WindowText is greater than the max
                            // length of a 16 bit int (32767).
                            // If it exceeds the max, we should take the substring....
                            if (cp.Caption != null && cp.Caption.Length > short.MaxValue)
                            {
                                cp.Caption = cp.Caption.Substring(0, short.MaxValue);
                            }

                            createResult = User32.CreateWindowExW(
                                (User32.WS_EX)cp.ExStyle,
                                windowClass._windowClassName,
                                cp.Caption,
                                (User32.WS)cp.Style,
                                cp.X,
                                cp.Y,
                                cp.Width,
                                cp.Height,
                                cp.Parent,
                                IntPtr.Zero,
                                modHandle,
                                cp.Param);

                            lastWin32Error = Marshal.GetLastWin32Error();
                        }
                        catch (NullReferenceException e)
                        {
                            throw new OutOfMemoryException(SR.ErrorCreatingHandle, e);
                        }
                    }
                    windowClass._targetWindow = null;

                    Debug.WriteLineIf(CoreSwitches.PerfTrack.Enabled, "Handle created of type '" + cp.ClassName + "' with caption '" + cp.Caption + "' from NativeWindow of type '" + GetType().FullName + "'");

                    if (createResult == IntPtr.Zero)
                    {
                        throw new Win32Exception(lastWin32Error, SR.ErrorCreatingHandle);
                    }
                    _ownHandle = true;
                }
            }
        }