예제 #1
0
        void CreateNativeWindow(WindowClass @class, WindowAttributes attrib, Rect r)
        {
            Debug.Print("Creating window...");

            OSStatus err = API.CreateNewWindow(@class, attrib, ref r, out WinHandle);

            API.CheckReturn(err);
            Debug.Print("Created window " + WinHandle.ToString());

            IntPtr titleCF = CF.CFSTR(title);

            Debug.Print("Setting window title: {0},   CFstring : {1},  Text : {2}", WinHandle, titleCF, title);
            API.SetWindowTitleWithCFString(WinHandle, titleCF);

            SetLocation(r.X, r.Y);
            SetSize(r.Width, r.Height);
            LoadSize();

            Rect titleSize = API.GetWindowBounds(WinHandle, WindowRegionCode.TitleBarRegion);

            mTitlebarHeight = titleSize.Height;
            Debug.Print("Titlebar size: {0}", titleSize);
            ConnectEvents();
            Debug.Print("Attached window events.");
        }
예제 #2
0
        public AppKitDisplay()
        {
            NSApplication.Init();

            CGRect     screenFrame = NSScreen.MainScreen.Frame;
            RectangleF frame       = new RectangleF((float)screenFrame.X, (float)screenFrame.Y,
                                                    (float)screenFrame.Width * 0.74f, (float)screenFrame.Height * 0.74f);
            NSWindowStyle style = NSWindowStyle.Titled | NSWindowStyle.Closable |
                                  NSWindowStyle.Miniaturizable | NSWindowStyle.Resizable;

            _window = new WindowClass(frame, style, NSBackingStore.Buffered, false);
            _window.AppKitDisplay           = this;
            _window.ReleasedWhenClosed      = false;
            _window.BackgroundColor         = NSColor.Black;
            _window.IsOpaque                = true;
            _window.AcceptsMouseMovedEvents = true;
            string[] draggedTypes = { NSPasteboard.NSFilenamesType.ToString() };
            _window.RegisterForDraggedTypes(draggedTypes);
            _delegate        = new WindowDelegate(this, _window);
            _window.Delegate = _delegate;

            _textinputClient = new TextInputClient(this);
            _window.ContentView.AddSubview(_textinputClient);

            FillKeyTable();
        }
예제 #3
0
        public void RegisterClass_UnregisterClassName()
        {
            WindowClass myClass = new WindowClass
            {
                ClassName       = "RegisterClass_UnregisterClassName",
                Style           = ClassStyle.HorizontalRedraw,
                WindowProcedure = CallDefaultProcedure
            };

            Atom atom = WindowMethods.RegisterClass(ref myClass);

            atom.IsValid.Should().BeTrue();

            try
            {
                var info = WindowMethods.GetClassInfo(ModuleMethods.GetModuleHandle(null), "RegisterClass_UnregisterClassName");
                info.ClassName.Should().Be("RegisterClass_UnregisterClassName");
                info.ClassAtom.Should().Be(Atom.Null);
                info.Style.Should().Be(ClassStyle.HorizontalRedraw);
            }
            finally
            {
                WindowMethods.UnregisterClass("RegisterClass_UnregisterClassName", null);
                Action action =
                    () => WindowMethods.GetClassInfo(ModuleMethods.GetModuleHandle(null), "RegisterClass_UnregisterClassName");
                action.ShouldThrow <IOException>().And
                .HResult.Should().Be((int)ErrorMacros.HRESULT_FROM_WIN32(WindowsError.ERROR_CLASS_DOES_NOT_EXIST));
            }
        }
예제 #4
0
 private static void OnShutdown(object sender, EventArgs e)
 {
     if (handleCount > 0)
     {
         lock (internalSyncObject)
         {
             for (int i = 0; i < hashBuckets.Length; i++)
             {
                 HandleBucket wrapper = hashBuckets[i];
                 if ((wrapper.handle != IntPtr.Zero) && (wrapper.handle != new IntPtr(-1)))
                 {
                     HandleRef hWnd = new HandleRef(wrapper, wrapper.handle);
                     System.Windows.Forms.UnsafeNativeMethods.SetWindowLong(hWnd, -4, new HandleRef(null, userDefWindowProc));
                     System.Windows.Forms.UnsafeNativeMethods.SetClassLong(hWnd, -24, userDefWindowProc);
                     System.Windows.Forms.UnsafeNativeMethods.PostMessage(hWnd, 0x10, 0, 0);
                     if (wrapper.window.IsAllocated)
                     {
                         NativeWindow target = (NativeWindow)wrapper.window.Target;
                         if (target != null)
                         {
                             target.handle = IntPtr.Zero;
                         }
                     }
                     wrapper.window.Free();
                 }
                 hashBuckets[i].handle    = IntPtr.Zero;
                 hashBuckets[i].hash_coll = 0;
             }
             handleCount = 0;
         }
     }
     WindowClass.DisposeCache();
 }
예제 #5
0
        void CreateNativeWindow(WindowClass @class, WindowAttributes attrib, Rect r)
        {
            Debug.Print("Creating window...");
            Debug.Indent();

            IntPtr windowRef = API.CreateNewWindow(@class, attrib, r);

            API.SetWindowTitle(windowRef, title);

            window = new CarbonWindowInfo(windowRef, true, false);

            SetLocation(r.X, r.Y);
            SetSize(r.Width, r.Height);

            Debug.Unindent();
            Debug.Print("Created window.");

            mWindows.Add(windowRef, new WeakReference(this));

            LoadSize();

            Rect titleSize = API.GetWindowBounds(window.WindowRef, WindowRegionCode.TitleBarRegion);

            mTitlebarHeight = titleSize.Height;

            Debug.Print("Titlebar size: {0}", titleSize);

            ConnectEvents();

            System.Diagnostics.Debug.Print("Attached window events.");
        }
예제 #6
0
        public void RegisterClass_UnregisterActiveWindow()
        {
            WindowClass myClass = new WindowClass
            {
                ClassName       = "RegisterClass_UnregisterActiveWindow",
                WindowProcedure = CallDefaultProcedure,
            };

            Atom atom = WindowMethods.RegisterClass(ref myClass);

            atom.IsValid.Should().BeTrue();

            try
            {
                WindowHandle window = WindowMethods.CreateWindow(atom,
                                                                 "RegisterClass_UnregisterActiveWindow", WindowStyles.Diabled | WindowStyles.Minimize);
                window.IsValid.Should().BeTrue();

                try
                {
                    Action action = () => WindowMethods.UnregisterClass(atom, null);
                    action.ShouldThrow <IOException>().And
                    .HResult.Should().Be((int)ErrorMacros.HRESULT_FROM_WIN32(WindowsError.ERROR_CLASS_HAS_WINDOWS));
                }
                finally
                {
                    WindowMethods.DestroyWindow(window);
                }
            }
            finally
            {
                WindowMethods.UnregisterClass(atom, null);
            }
        }
예제 #7
0
            public void Convert(ref Win16.CREATESTRUCT cs16, out Win32.CREATESTRUCT cs32)
            {
                if (cs16.lpCreateParams != 0 && !WindowClass.IsRegistered(_machine.ReadString(cs16.lpszClassName)))
                {
                    throw new NotImplementedException("CREATESTRUCT.lpCreateParams not supported");
                }

                // Convert it
                cs32.lpCreateParams = BitUtils.DWordToIntPtr(cs16.lpCreateParams);
                cs32.hInstance      = IntPtr.Zero;
                cs32.x             = (short)(cs16.cx == Win16.CW_USEDEFAULT ? Win16.CW_USEDEFAULT : cs16.x);
                cs32.y             = (short)(cs16.cx == Win16.CW_USEDEFAULT ? Win16.CW_USEDEFAULT : cs16.y);
                cs32.cx            = (short)(cs16.cx == Win16.CW_USEDEFAULT ? Win16.CW_USEDEFAULT : cs16.cx);
                cs32.cy            = (short)(cs16.cx == Win16.CW_USEDEFAULT ? Win16.CW_USEDEFAULT : cs16.cy);
                cs32.dwExStyle     = cs16.dwExStyle;
                cs32.style         = cs16.style;
                cs32.lpszClassName = GetString(cs16.lpszClassName);
                cs32.lpszName      = GetString(cs16.lpszName);

                if ((cs16.style & Win16.WS_CHILD) != 0)
                {
                    cs32.hMenu = (IntPtr)cs16.hMenu;
                }
                else
                {
                    cs32.hMenu = HMENU.Map.To32(cs16.hMenu);
                }

                cs32.hWndParent = HWND.Map.To32(cs16.hWndParent);
            }
예제 #8
0
        static void Main()
        {
            const string szAppName = "Environ";

            ModuleInstance module   = Marshal.GetHINSTANCE(typeof(Program).Module);
            WindowClass    wndclass = new WindowClass
            {
                Style           = ClassStyle.HorizontalRedraw | ClassStyle.VerticalRedraw,
                WindowProcedure = WindowProcedure,
                Instance        = module,
                Icon            = IconId.Application,
                Cursor          = CursorId.Arrow,
                Background      = StockBrush.White,
                ClassName       = szAppName
            };

            Windows.RegisterClass(ref wndclass);

            WindowHandle window = Windows.CreateWindow(
                module,
                szAppName,
                "Environment List Box",
                WindowStyles.OverlappedWindow);

            window.ShowWindow(ShowWindow.Normal);
            window.UpdateWindow();

            while (Windows.GetMessage(out MSG message))
            {
                Windows.TranslateMessage(ref message);
                Windows.DispatchMessage(ref message);
            }
        }
        public void WindowCallback_SendMessage()
        {
            WindowClass myClass = new WindowClass
            {
                ClassName       = "WindowCallback_SendMessage",
                WindowProcedure = (window, message, wParam, lParam) =>
                {
                    return(42);
                }
            };

            Atom atom = WindowMethods.RegisterClass(ref myClass);

            atom.IsValid.Should().BeTrue();

            try
            {
                WindowHandle window = WindowMethods.CreateWindow(atom, null, WindowStyles.Minimize | WindowStyles.Diabled);
                window.IsValid.Should().BeTrue();

                try
                {
                    WindowMethods.SendMessage(window, WindowMessage.Activate, 0, 0).Should().Be((LRESULT)42);
                }
                finally
                {
                    WindowMethods.DestroyWindow(window);
                }
            }
            finally
            {
                WindowMethods.UnregisterClass(atom, null);
            }
        }
예제 #10
0
        static void Main()
        {
            ModuleInstance module   = Marshal.GetHINSTANCE(typeof(Program).Module);
            WindowClass    wndclass = new WindowClass
            {
                Style           = ClassStyle.HorizontalRedraw | ClassStyle.VerticalRedraw,
                WindowProcedure = WindowProcedure,
                Instance        = module,
                Icon            = IconId.Application,
                Cursor          = CursorId.Arrow,
                Background      = StockBrush.White,
                ClassName       = "SysMets3"
            };

            Windows.RegisterClass(ref wndclass);

            WindowHandle window = Windows.CreateWindow(
                module,
                "SysMets3",
                "Get System Metrics No. 3",
                WindowStyles.OverlappedWindow | WindowStyles.VerticalScroll | WindowStyles.HorizontalScroll);

            window.ShowWindow(ShowWindow.Normal);
            window.UpdateWindow();

            while (Windows.GetMessage(out MSG message))
            {
                Windows.TranslateMessage(ref message);
                Windows.DispatchMessage(ref message);
            }
        }
예제 #11
0
        public static void DisableControlBox(this Window window)
        {
            WindowInteropHelper windowInteropHelper = new WindowInteropHelper(window);

            Int64 windowLong = WindowClass.GetWindowLong(windowInteropHelper.EnsureHandle(), WindowClass.GWL_STYLE);

            WindowClass.SetWindowLong(windowInteropHelper.EnsureHandle(), WindowClass.GWL_STYLE, (Int32)(windowLong & ~WindowStyles.WS_SYSMENU));
        }
예제 #12
0
        public static void DisableMinimizeBox(this Window window)
        {
            WindowInteropHelper windowInteropHelper = new WindowInteropHelper(window);

            Int64 windowLong = WindowClass.GetWindowLong(windowInteropHelper.EnsureHandle(), WindowClass.GWL_STYLE);

            WindowClass.SetWindowLong(windowInteropHelper.EnsureHandle(), WindowClass.GWL_STYLE, (Int32)(windowLong & ~WindowStyles.WS_MINIMIZEBOX));
        }
예제 #13
0
            }             // ctor

            protected override WindowClass CreateWindowClass()
            {
                if (glowWindowClassCount++ == 0)
                {
                    glowWindowClass = new WindowClass("PpsWindowGlowWnd");
                }
                return(glowWindowClass);
            }             // func CreateWindowClass
 static RedirectedHwndHost()
 {
     _redirectionWindowFactory = new WindowClass<RedirectedWindow>();
     _redirectionWindowFactory.BeginInit();
     _redirectionWindowFactory.Type = WindowClassType.ApplicationLocal;
     //_redirectionWindowFactory.Background = NativeMethods.GetStockObject(5);
     _redirectionWindowFactory.EndInit();
 }
예제 #15
0
파일: API.cs 프로젝트: tanis2000/FEZ
 internal static IntPtr CreateNewWindow(WindowClass @class, WindowAttributes attributes, Rect r)
 {
     IntPtr window;
       OSStatus newWindow = API._CreateNewWindow(@class, attributes, ref r, out window);
       if (newWindow != OSStatus.NoError)
     throw new MacOSException(newWindow);
       else
     return window;
 }
예제 #16
0
/*		private void SetClass(UInt16 windowClass) {
 *
 *                      KnownWindowClass winClass = (KnownWindowClass)windowClass;
 *                      switch(winClass) {
 *                              case KnownWindowClass.Button:
 *                                      Class = ControlClass.
 *
 *                              case KnownWindowClass.Edit:
 *                                      return new TextBox() { Multiline = true };
 *
 *                              case KnownWindowClass.Static:
 *                                      return new Label();
 *
 *                              case KnownWindowClass.ListBox:
 *                                      return new ListBox() { IntegralHeight = false };
 *
 *                              case KnownWindowClass.ScrollBar:
 *                                      //return new ScrollBar();
 *                                      return new Button();
 *
 *                              case KnownWindowClass.ComboBox:
 *                                      return new ComboBox() { IntegralHeight = false };
 *                      }
 *
 *              }
 *
 *              public ControlClass Class { get; set; }  */

        public override string ToString()
        {
            if (WindowClass == null)
            {
                return("Null - " + Text);
            }

            return(WindowClass.ToString() + " - " + Text);
        }
예제 #17
0
            public RenderTargetFixture()
            {
                _factory = Direct2d.CreateFactory(FactoryType.SingleThreaded, DebugLevel.None);

                // Create a memory only copy of the primary monitor DC
                // _dc = Gdi.CreateCompatibleDeviceContext(Gdi.GetDeviceContext());

                _windowClass = new WindowClass(backgroundBrush: BrushHandle.NoBrush);
                _windowClass.Register();
                _window      = _windowClass.CreateWindow("RenderTargetTest");
                RenderTarget = _factory.CreateWindowRenderTarget(default,
                /// <summary>
                /// Creates a message-only window with the specified procedures
                /// for processing messages.
                /// </summary>
                /// <param name="procs">
                /// The procedures for processing messages received by the window,
                /// in the order to which the procedures should be deferred.
                /// </param>
                /// <exception cref="ArgumentNullException">
                /// <paramref name="procs"/> is null or contains an element
                /// that is null.
                /// </exception>
                public MessageWindow(IReadOnlyCollection <WindowProcedure> procs)
                {
                    // Create new list to avoid unintended side effects of
                    // modifying the collection we were passed as a parameter.
                    //
                    // This initialisation needs to be before the window is
                    // created, as a message is sent to the window immediately
                    // on creation and an NRE will result if this is not set.
                    this.Procedures = procs.ToList();

                    _windowClassName = Guid.NewGuid();

                    var hInstance = Process.GetCurrentProcess().Handle;

                    // Keep a reference around for our window procedure to avoid
                    // the GC collecting it. Important that this is not removed.
                    _procRef = _proc;

                    var wndClass = new WindowClass
                    {
                        // Always use [_procRef] and not [_proc]; see above.
                        lpfnWndProc   = _procRef,
                        lpszClassName = _windowClassName.ToString(),
                        hInstance     = hInstance,
                    };

                    _windowAtom = RegisterClass(ref wndClass);

                    if (_windowAtom == 0)
                    {
                        throw Helpers.LastWin32Exception();
                    }

                    this.Handle = CreateWindowEx(
                        dwExtStyle:     0,
                        lpClassName:    (UIntPtr)_windowAtom,
                        lpWindowName:   IntPtr.Zero,
                        dwStyle:        0,
                        x:              0,
                        y:              0,
                        nWidth:         0,
                        nHeight:        0,
                        hWndParent:     IntPtr.Zero,
                        hMenu:          IntPtr.Zero,
                        hInstance:      hInstance,
                        lpParam:        IntPtr.Zero
                        );

                    if (this.Handle == IntPtr.Zero)
                    {
                        throw Helpers.LastWin32Exception();
                    }
                }
예제 #19
0
        private void CreateNativeWindow(WindowClass @class, WindowAttributes attrib, Rect r)
        {
            IntPtr newWindow = API.CreateNewWindow(@class, attrib, r);

            API.SetWindowTitle(newWindow, this.title);
            this.window = new CarbonWindowInfo(newWindow, true, false);
            this.SetLocation(r.X, r.Y);
            this.SetSize(r.Width, r.Height);
            CarbonGLNative.mWindows.Add(newWindow, new WeakReference((object)this));
            this.LoadSize();
            this.mTitlebarHeight = (int)API.GetWindowBounds(this.window.WindowRef, WindowRegionCode.TitleBarRegion).Height;
            this.ConnectEvents();
        }
예제 #20
0
        internal static IntPtr CreateNewWindow(WindowClass @class, WindowAttributes attributes, Rect r)
        {
            IntPtr   retval;
            OSStatus stat = _CreateNewWindow(@class, attributes, ref r, out retval);

            Debug.Print("Created Window: {0}", retval);
            if (stat != OSStatus.NoError)
            {
                throw new MacOSException(stat);
            }

            return(retval);
        }
예제 #21
0
 public static extern Window XCreateWindow(
     DisplayPtr display,
     Window parent,
     int x, int y,
     uint width,
     uint height,
     uint border_width,
     int depth,
     WindowClass windowClass,
     VisualPtr visual,
     XSetWindowAttributeMask valuemask,
     ref XSetWindowAttributes attributes
     );
예제 #22
0
            }             // func CreateWindowClass

            protected override void DestroyWindowClass(WindowClass windowClass)
            {
                if (windowClass != glowWindowClass)
                {
                    throw new InvalidOperationException();
                }

                if (--glowWindowClassCount == 0)
                {
                    glowWindowClass.Dispose();
                    glowWindowClass = null;
                }
            }             // proc DestroyWindowClass
예제 #23
0
        internal static IntPtr CreateNewWindow(WindowClass @class, WindowAttributes attributes, Rect r)
        {
            IntPtr   window;
            OSStatus newWindow = API._CreateNewWindow(@class, attributes, ref r, out window);

            if (newWindow != OSStatus.NoError)
            {
                throw new MacOSException(newWindow);
            }
            else
            {
                return(window);
            }
        }
예제 #24
0
        public void WindowCallback_Subclass()
        {
            int         value   = 42;
            WindowClass myClass = new WindowClass
            {
                ClassName       = "WindowCallback_Subclass",
                WindowProcedure = (window, message, wParam, lParam) =>
                {
                    return(value);
                }
            };

            Atom atom = WindowMethods.RegisterClass(ref myClass);

            atom.IsValid.Should().BeTrue();

            try
            {
                WindowHandle window = WindowMethods.CreateWindow(atom, null, WindowStyles.Minimize | WindowStyles.Diabled);
                window.IsValid.Should().BeTrue();

                try
                {
                    WindowMethods.SendMessage(window, WindowMessage.Activate, 0, 0).Should().Be((LRESULT)42);

                    IntPtr          previous = IntPtr.Zero;
                    WindowProcedure subClass = (w, m, wParam, lParam) =>
                    {
                        return(WindowMethods.CallWindowProcedure(previous, w, m, wParam, lParam));
                    };

                    value    = 1999;
                    previous = WindowMethods.SetWindowProcedure(window, subClass);
                    WindowMethods.SendMessage(window, WindowMessage.Activate, 0, 0).Should().Be((LRESULT)1999);
                    GC.KeepAlive(subClass);
                }
                finally
                {
                    WindowMethods.DestroyWindow(window);
                }
            }
            finally
            {
                WindowMethods.UnregisterClass(atom, null);
            }
        }
예제 #25
0
        static void Main()
        {
            const string szAppName = "RandRect";

            ModuleInstance module   = Marshal.GetHINSTANCE(typeof(Program).Module);
            WindowClass    wndclass = new WindowClass
            {
                Style           = ClassStyle.HorizontalRedraw | ClassStyle.VerticalRedraw,
                WindowProcedure = WindowProcedure,
                Instance        = module,
                Icon            = IconId.Application,
                Cursor          = CursorId.Arrow,
                Background      = StockBrush.White,
                ClassName       = szAppName
            };

            Windows.RegisterClass(ref wndclass);

            WindowHandle window = Windows.CreateWindow(
                module,
                szAppName,
                "Random Rectangles",
                WindowStyles.OverlappedWindow);

            window.ShowWindow(ShowWindow.Normal);
            window.UpdateWindow();

            while (true)
            {
                if (Windows.PeekMessage(out MSG message, 0, 0, PeekMessageOptions.PM_REMOVE))
                {
                    if (message.message == WindowMessage.Quit)
                    {
                        break;
                    }
                    Windows.TranslateMessage(ref message);
                    Windows.DispatchMessage(ref message);
                }

                // We're crazy fast 20 years past the source sample,
                // sleeping to make this a bit more interesting.
                Thread.Sleep(100);
                DrawRectangle(window);
            }
        }
예제 #26
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);
        }
예제 #27
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);
             }
         }
     }
 }
예제 #28
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");
        }
예제 #29
0
        public void RegisterClass_GetSetClassLong()
        {
            // Some docs claim that 40 is the max, but that isn't true (at least in recent OSes)
            // https://msdn.microsoft.com/en-us/library/windows/desktop/ms633574.aspx
            WindowClass myClass = new WindowClass
            {
                ClassName       = "RegisterClass_GetSetClassLong",
                Style           = ClassStyle.HorizontalRedraw,
                WindowProcedure = CallDefaultProcedure,
                ClassExtraBytes = 80
            };

            Atom atom = WindowMethods.RegisterClass(ref myClass);

            atom.IsValid.Should().BeTrue();

            try
            {
                WindowHandle window = WindowMethods.CreateWindow(atom,
                                                                 "RegisterClass_GetSetClassLong_Window", WindowStyles.Diabled | WindowStyles.Minimize);
                window.IsValid.Should().BeTrue();

                try
                {
                    var info = WindowMethods.GetClassInfo(ModuleMethods.GetModuleHandle(null), atom);
                    info.ClassExtraBytes.Should().Be(80);

                    IntPtr result = WindowMethods.SetClassLong(window, (ClassLong)72, (IntPtr)0x0000BEEF);
                    result.Should().Be(IntPtr.Zero);

                    WindowMethods.GetClassLong(window, (ClassLong)72).Should().Be((IntPtr)0x0000BEEF);
                }
                finally
                {
                    WindowMethods.DestroyWindow(window);
                }
            }
            finally
            {
                WindowMethods.UnregisterClass(atom, null);
            }
        }
예제 #30
0
        protected override HandleRef BuildWindowCore(HandleRef parent)
        {
            var callback   = Marshal.GetFunctionPointerForDelegate(procedure = WndProc);
            var width      = Convert.ToInt32(ActualWidth);
            var height     = Convert.ToInt32(ActualHeight);
            var cursor     = LoadCursor(IntPtr.Zero, 32512);
            var menu       = string.Empty;
            var background = new IntPtr(1);
            var zero       = IntPtr.Zero;
            var caption    = string.Empty;
            var style      = 3u;
            var extra      = 0;
            var extended   = 0u;
            var window     = 0x50000000u;
            var point      = 0;
            var name       = "Win32";

            var wnd = new WindowClass
            {
                Style       = style,
                Callback    = callback,
                ClassExtra  = extra,
                WindowExtra = extra,
                Instance    = zero,
                Icon        = zero,
                Cursor      = cursor,
                Background  = background,
                Menu        = menu,
                Class       = name
            };

            RegisterClass(ref wnd);
            Handle = CreateWindowEx(extended, name, caption,
                                    window, point, point, width, height,
                                    parent.Handle, zero, zero, zero);


            ThomasWrapper.CreateThomasWindow(Handle, IsEditor);

            return(new HandleRef(this, Handle));
        }
예제 #31
0
        static void Main()
        {
#if GDIPLUS
            UIntPtr token = GdiPlusMethods.Startup();
#endif
            const string szAppName = "Clock";

            ModuleInstance module = Marshal.GetHINSTANCE(typeof(Program).Module);
            WindowClass wndclass = new WindowClass
            {
                Style = ClassStyle.HorizontalRedraw | ClassStyle.VerticalRedraw,
                WindowProcedure = WindowProcedure,
                Instance = module,
                Icon = IconId.Application,
                Cursor = CursorId.Arrow,
                Background = StockBrush.White,
                ClassName = szAppName
            };

            Windows.RegisterClass(ref wndclass);

            WindowHandle window = Windows.CreateWindow(
                module,
                szAppName,
                "Analog Clock",
                WindowStyles.OverlappedWindow);

            window.ShowWindow(ShowWindow.Normal);
            window.UpdateWindow();

            while (Windows.GetMessage(out MSG message))
            {
                Windows.TranslateMessage(ref message);
                Windows.DispatchMessage(ref message);
            }

#if GDIPLUS
            GdiPlusMethods.Shutdown(token);
#endif
        }
예제 #32
0
            internal static WindowClass Create(string className, User32.CS classStyle)
            {
                lock (s_wcInternalSyncObject)
                {
                    WindowClass wc = s_cache;
                    if (className is null)
                    {
                        // If we weren't given a class name, look for a window
                        // that has the exact class style.
                        while (wc != null &&
                               (wc._className != null || wc._classStyle != classStyle))
                        {
                            wc = wc._next;
                        }
                    }
                    else
                    {
                        while (wc != null && !className.Equals(wc._className))
                        {
                            wc = wc._next;
                        }
                    }

                    if (wc is null)
                    {
                        // Didn't find an existing class, create one and attatch it to
                        // the end of the linked list.
                        wc = new WindowClass(className, classStyle)
                        {
                            _next = s_cache
                        };
                        s_cache = wc;
                    }

                    return(wc);
                }
            }
예제 #33
0
 public static extern short RegisterClass(ref WindowClass lpWndClass);
예제 #34
0
 internal static extern ushort RegisterClass(ref WindowClass windowClass);
예제 #35
0
 public static extern IntPtr RegisterClass(ref WindowClass wndClass);
예제 #36
0
 public static extern OSStatus CreateNewWindow(WindowClass @class, WindowAttributes attributes, ref Rect r, out IntPtr window);
예제 #37
0
 CarbonGLNative(WindowClass @class, WindowAttributes attrib)
 {
     mWindowClass = @class;
     mWindowAttrib = attrib;
 }
예제 #38
0
 public static extern int RegisterClass(ref WindowClass windowClass);
예제 #39
0
        internal static IntPtr CreateNewWindow(WindowClass @class, WindowAttributes attributes, Rect r)
        {
            IntPtr retval;
            OSStatus stat = _CreateNewWindow(@class, attributes, ref r, out retval);

            Debug.Print("Created Window: {0}", retval);

            if (stat != OSStatus.NoError)
            {
                throw new MacOSException(stat);
            }

            return retval;
        }
예제 #40
0
        void CreateNativeWindow(WindowClass @class, WindowAttributes attrib, Rect r)
        {
            Debug.Print("Creating window...");
            Debug.Indent();

            IntPtr windowRef = API.CreateNewWindow(@class, attrib, r);
            API.SetWindowTitle(windowRef, title);

            window = new CarbonWindowInfo(windowRef, true, false);

            SetLocation(r.X, r.Y);
            SetSize(r.Width, r.Height);

            Debug.Unindent();
            Debug.Print("Created window.");

            mWindows.Add(windowRef, new WeakReference(this));

            LoadSize();

            Rect titleSize = API.GetWindowBounds(window.WindowRef, WindowRegionCode.TitleBarRegion);
            mTitlebarHeight = titleSize.Height;

            Debug.Print("Titlebar size: {0}", titleSize);

            ConnectEvents();

            System.Diagnostics.Debug.Print("Attached window events.");
        }
예제 #41
0
파일: API.cs 프로젝트: tanis2000/FEZ
 private static OSStatus _CreateNewWindow(WindowClass @class, WindowAttributes attributes, ref Rect r, out IntPtr window);
예제 #42
0
 private CarbonGLNative(WindowClass @class, WindowAttributes attrib)
 {
   this.mWindowClass = @class;
   this.mWindowAttrib = attrib;
 }
예제 #43
0
        protected override HandleRef BuildWindowCore(HandleRef parent)
        {
            var callback = Marshal.GetFunctionPointerForDelegate(procedure = WndProc);
            var width = Convert.ToInt32(ActualWidth);
            var height = Convert.ToInt32(ActualHeight);
            var cursor = LoadCursor(IntPtr.Zero, 32512);
            var menu = string.Empty;
            var background = new IntPtr(1);
            var zero = IntPtr.Zero;
            var caption = string.Empty;
            var style = 3u;
            var extra = 0;
            var extended = 0u;
            var window = 0x50000000u;
            var point = 0;
            var name = "Win32";

            var wnd = new WindowClass
            {
                Style = style,
                Callback = callback,
                ClassExtra = extra,
                WindowExtra = extra,
                Instance = zero,
                Icon = zero,
                Cursor = cursor,
                Background = background,
                Menu = menu,
                Class = name
            };

            RegisterClass(ref wnd);
            Handle = CreateWindowEx(extended, name, caption,
                window, point, point, width, height,
                parent.Handle, zero, zero, zero);

            scene = new Scene(Handle);

            return new HandleRef(this, Handle);
        }
예제 #44
0
        void CreateNativeWindow(WindowClass @class, WindowAttributes attrib, Rect r)
        {
            Debug.Print("Creating window...");

            IntPtr windowRef;
            OSStatus err = API.CreateNewWindow(@class, attrib, ref r, out windowRef);
            API.CheckReturn( err );
            Debug.Print( "Created window " + windowRef );
            API.SetWindowTitle(windowRef, title);

            window = new CarbonWindowInfo(windowRef);
            SetLocation(r.X, r.Y);
            SetSize(r.Width, r.Height);
            mWindows.Add(windowRef, new WeakReference(this));
            LoadSize();

            Rect titleSize = API.GetWindowBounds(window.WindowRef, WindowRegionCode.TitleBarRegion);
            mTitlebarHeight = titleSize.Height;
            Debug.Print("Titlebar size: {0}", titleSize);
            ConnectEvents();
            Debug.Print("Attached window events.");
        }
예제 #45
0
 private void CreateNativeWindow(WindowClass @class, WindowAttributes attrib, Rect r)
 {
   IntPtr newWindow = API.CreateNewWindow(@class, attrib, r);
   API.SetWindowTitle(newWindow, this.title);
   this.window = new CarbonWindowInfo(newWindow, true, false);
   this.SetLocation(r.X, r.Y);
   this.SetSize(r.Width, r.Height);
   CarbonGLNative.mWindows.Add(newWindow, new WeakReference((object) this));
   this.LoadSize();
   this.mTitlebarHeight = (int) API.GetWindowBounds(this.window.WindowRef, WindowRegionCode.TitleBarRegion).Height;
   this.ConnectEvents();
 }