public void CreateWindow(String className = "VurdalakovMessageOnlyWindow")
        {
            // intentionally here, prevents garbage collection
            this.windowProc = this.OnWindowProc;

            this.hInstance = GetModuleHandle(null);

            WNDCLASSEX wndClassEx = new WNDCLASSEX();
            wndClassEx.cbSize = Marshal.SizeOf(typeof(WNDCLASSEX));
            wndClassEx.lpfnWndProc = this.windowProc;
            wndClassEx.hInstance = this.hInstance;
            wndClassEx.lpszClassName = className;

            UInt16 atom = RegisterClassEx(ref wndClassEx);
            if (0 == atom)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "RegisterClassEx failed");
            }

            this.classAtom = new IntPtr(atom);

            this.WindowHandle = CreateWindowEx(0, this.classAtom, IntPtr.Zero, 0, 0, 0, 0, 0, new IntPtr(HWND_MESSAGE), IntPtr.Zero, this.hInstance, IntPtr.Zero);
            if (IntPtr.Zero == this.WindowHandle)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "CreateWindowEx failed");
            }
        }
예제 #2
0
        /// <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()
        {
            var result = false;

            var wc = new WNDCLASS();

            wc.style         = 0;
            wc.lpfnWndProc   = WindowProcedure = 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);
        }
예제 #3
0
        public unsafe virtual void CreateWindow()
        {
            _keyboadHandler?.SetNativeHost(this);
            _windowFrameless = _options.WindowFrameless;

            _wndProc = WndProc;
            _consoleParentInstance = GetConsoleWindow();
            _options.WindowState   = (_options.Fullscreen || _options.KioskMode) ?  WindowState.Fullscreen : _options.WindowState;
            _windoStylePlacement   = new WindowStylePlacement(_options);

            User32.WNDCLASS wcex = new User32.WNDCLASS();
            wcex.style         = User32.CS.HREDRAW | User32.CS.VREDRAW;
            wcex.lpfnWndProc   = Marshal.GetFunctionPointerForDelegate(_wndProc);
            wcex.cbClsExtra    = 0;
            wcex.cbWndExtra    = 0;
            wcex.hIcon         = GetIconHandle();
            wcex.hCursor       = User32.LoadCursorW(IntPtr.Zero, (IntPtr)CursorResourceId.IDC_ARROW);
            wcex.hbrBackground = Gdi32.GetStockObject(Gdi32.StockObject.WHITE_BRUSH);
            wcex.lpszMenuName  = null;
            wcex.hInstance     = _consoleParentInstance;

            fixed(char *c = Chromely_WINDOW_CLASS)
            {
                wcex.lpszClassName = c;
            }

            if (User32.RegisterClassW(ref wcex) == 0)
            {
                Logger.Instance.Log.LogError("Chromelywindow registration failed");
                return;
            }

            var stylePlacement = GetWindowStylePlacement(_options.WindowState);

            var hWnd = User32.CreateWindowExW(
                stylePlacement.ExStyles,
                Chromely_WINDOW_CLASS,
                _options.Title,
                stylePlacement.Styles,
                stylePlacement.RECT.left,
                stylePlacement.RECT.top,
                stylePlacement.RECT.Width,
                stylePlacement.RECT.Height,
                IntPtr.Zero,
                IntPtr.Zero,
                _consoleParentInstance,
                null);

            if (hWnd == IntPtr.Zero)
            {
                Logger.Instance.Log.LogError("Chromelywindow creation failed");
                return;
            }

            PlaceWindow(hWnd, stylePlacement);
            InstallHooks(hWnd);
            ShowWindow(hWnd, stylePlacement.ShowCommand);
            UpdateWindow(hWnd);
            RegisterHotKeys(hWnd);
        }
        private void PlatformConstruct()
        {
            _wndProc = ProcessWindowMessage;
            var wndClassEx = new WNDCLASSEX
            {
                Size                  = Unsafe.SizeOf <WNDCLASSEX>(),
                Styles                = WindowClassStyles.CS_HREDRAW | WindowClassStyles.CS_VREDRAW | WindowClassStyles.CS_OWNDC,
                WindowProc            = _wndProc,
                InstanceHandle        = HInstance,
                CursorHandle          = User32.LoadCursor(IntPtr.Zero, SystemCursor.IDC_ARROW),
                BackgroundBrushHandle = IntPtr.Zero,
                IconHandle            = IntPtr.Zero,
                ClassName             = WndClassName,
            };

            var atom = User32.RegisterClassEx(ref wndClassEx);

            if (atom == 0)
            {
                throw new InvalidOperationException(
                          $"Failed to register window class. Error: {Marshal.GetLastWin32Error()}"
                          );
            }

            // Create main window.
            MainWindow = new Window("Vortice Tutorial 15 - Primitives", 1280, 720);
        }
예제 #5
0
        public Boolean CreateWindow(String className)
        {
            // intentionally here, prevents garbage collection
            this.windowProc = this.OnWindowProc;

            this.hInstance = GetModuleHandle(null);

            var wndClassEx = new WNDCLASSEX();

            wndClassEx.cbSize      = Marshal.SizeOf(typeof(WNDCLASSEX));
            wndClassEx.lpfnWndProc = this.windowProc;
            wndClassEx.hInstance   = this.hInstance;

            wndClassEx.lpszClassName = className;

            var atom = RegisterClassEx(ref wndClassEx);

            if (0 == atom)
            {
                Tracer.Trace($"RegisterClassEx failed with error {Marshal.GetLastWin32Error()}");
                return(false);
            }

            this.classAtom = new IntPtr(atom);

            this.WindowHandle = CreateWindowEx(0, this.classAtom, IntPtr.Zero, 0, 0, 0, 0, 0, new IntPtr(HWND_MESSAGE), IntPtr.Zero, this.hInstance, IntPtr.Zero);
            if (IntPtr.Zero == this.WindowHandle)
            {
                Tracer.Trace($"CreateWindowEx failed with error {Marshal.GetLastWin32Error()}");
                return(false);
            }

            return(true);
        }
예제 #6
0
        protected Application()
        {
            _wndProc = ProcessWindowMessage;
            var wndClassEx = new WNDCLASSEX
            {
                Size                  = Unsafe.SizeOf <WNDCLASSEX>(),
                Styles                = WindowClassStyles.CS_HREDRAW | WindowClassStyles.CS_VREDRAW | WindowClassStyles.CS_OWNDC,
                WindowProc            = _wndProc,
                InstanceHandle        = HInstance,
                CursorHandle          = LoadCursor(IntPtr.Zero, SystemCursor.IDC_ARROW),
                BackgroundBrushHandle = IntPtr.Zero,
                IconHandle            = IntPtr.Zero,
                ClassName             = WndClassName,
            };

            var atom = RegisterClassEx(ref wndClassEx);

            if (atom == 0)
            {
                throw new InvalidOperationException(
                          $"Failed to register window class. Error: {Marshal.GetLastWin32Error()}"
                          );
            }

            // Create main window.
            MainWindow = new Window("Vortice", 800, 600);
        }
예제 #7
0
            public static IntPtr SetWindowLong(IntPtr hWnd, GWL nIndex, WNDPROC dwNewLong)
            {
                IntPtr pointer = Marshal.GetFunctionPointerForDelegate(dwNewLong);
                IntPtr result  = SetWindowLong(hWnd, nIndex, pointer);

                GC.KeepAlive(dwNewLong);
                return(result);
            }
예제 #8
0
        public Window(string title, int width, int height)
        {
            var instance = Kernel32.GetModuleHandleW(null);
            var icon     = User32.LoadIconW(IntPtr.Zero, IDI.APPLICATION);

            wndproc = WndProc;

            // register the window class
            var wndclass = new WNDCLASSEXW {
                cbSize        = (uint)Marshal.SizeOf <WNDCLASSEXW>(),
                style         = CS.HREDRAW | CS.VREDRAW | CS.OWNDC,
                hInstance     = instance,
                hIcon         = icon,
                hIconSm       = icon,
                hCursor       = User32.LoadCursorW(IntPtr.Zero, IDC.ARROW),
                lpszClassName = ClassName,
                lpfnWndProc   = Marshal.GetFunctionPointerForDelegate(wndproc)
            };

            var atom = User32.RegisterClassExW(ref wndclass);

            if (atom == 0)
            {
                throw new InvalidOperationException("Failed to register window class");
            }

            // size the client area appropriately
            var styles = WS.OVERLAPPEDWINDOW;
            var rect   = new RECT {
                left = 0, top = 0, right = width, bottom = height
            };

            if (User32.AdjustWindowRectEx(ref rect, styles, 0, 0))
            {
                width  = rect.right - rect.left;
                height = rect.bottom - rect.top;
            }

            // create the window
            hwnd = User32.CreateWindowExW(
                0,
                new IntPtr(atom),
                title,
                styles,
                CW.USEDEFAULT,
                CW.USEDEFAULT,
                width,
                height,
                IntPtr.Zero,
                IntPtr.Zero,
                instance,
                IntPtr.Zero
                );
            if (hwnd == IntPtr.Zero)
            {
                throw new InvalidOperationException("Failed to create window");
            }
        }
예제 #9
0
        public CustomPopupComboBox()
        {
            _dropDownHideTime   = DateTime.UtcNow;
            base.IntegralHeight = false;
            base.DropDownHeight = 1;
            base.DropDownWidth  = 1;

            _listBoxWndProc = new WNDPROC(ListBoxWndProc);
        }
예제 #10
0
        public CustomPopupComboBox()
        {
            _dropDownHideTime = DateTime.UtcNow;
            base.IntegralHeight = false;
            base.DropDownHeight = 1;
            base.DropDownWidth = 1;

            _listBoxWndProc = new WNDPROC(ListBoxWndProc);
        }
예제 #11
0
        public HCPopupForm()
        {
            FPopupWindow = IntPtr.Zero;
            FOpened      = false;
            FWidth       = 50;
            FHeight      = 100;

            WndProc += WindowProcedure;
            RegFormClass();
        }
예제 #12
0
 public static Int32 SetWindowLong(IntPtr hWnd, Int32 code, WNDPROC newLong)
 {
     if (Marshal.SizeOf(IntPtr.Zero) == 4)
     {
         return(SetWindowLongW(hWnd, code, newLong));
     }
     else
     {
         return(SetWindowLongPtrW(hWnd, code, newLong));
     }
 }
예제 #13
0
        public static IntPtr SetWindowProc(IntPtr hwnd, WNDPROC newWndProc)
        {
            const int GWLP_WNDPROC = -4;

            if(IntPtr.Size == 8)
            {
                return User32.SetWindowLongPtr(
                    hwnd, GWLP_WNDPROC, newWndProc);
            }
            else
            {
                return User32.SetWindowLong(
                    hwnd, GWLP_WNDPROC, newWndProc);
            }
        }
예제 #14
0
        public static IntPtr SetWindowProc(IntPtr hwnd, WNDPROC newWndProc)
        {
            const int GWLP_WNDPROC = -4;

            if (IntPtr.Size == 8)
            {
                return(User32.SetWindowLongPtr(
                           hwnd, GWLP_WNDPROC, newWndProc));
            }
            else
            {
                return(User32.SetWindowLong(
                           hwnd, GWLP_WNDPROC, newWndProc));
            }
        }
예제 #15
0
        private void CreateFormHandle()
        {
            if (User.IsWindow(FPopupWindow) == 0)
            {
                WndProc -= WindowProcedure;
                WndProc += WindowProcedure;
                RegFormClass();
                IntPtr hInstance = Marshal.GetHINSTANCE(this.GetType().Module);// (IntPtr)Kernel.GetModuleHandle(null);// Marshal.GetHINSTANCE(null);

                FPopupWindow = (IntPtr)User.CreateWindowEx(User.WS_EX_TOPMOST | User.WS_EX_TOOLWINDOW,
                                                           "HCPopupForm",
                                                           "",
                                                           User.WS_POPUP,
                                                           0, 0, FWidth, FHeight, IntPtr.Zero, IntPtr.Zero, hInstance, IntPtr.Zero);
            }
        }
예제 #16
0
파일: clipboard.cs 프로젝트: qmgindi/Au
            /// <summary>
            /// Subclasses clipOwner.
            /// </summary>
            /// <param name="paste">true if used for paste, false if for copy.</param>
            /// <param name="data">If used for paste, can be string containing Unicode text or int/string dictionary containing clipboard format/data.</param>
            /// <param name="clipOwner">Our clipboard owner window.</param>
            /// <param name="wFocus">The target control or window.</param>
            public _ClipboardListener(bool paste, object data, wnd clipOwner, wnd wFocus)
            {
                _paste   = paste;
                _data    = data;
                _wndProc = _WndProc;
                _wFocus  = wFocus;
                WndUtil.SubclassUnsafe_(clipOwner, _wndProc);

                //rejected: use SetClipboardViewer to block clipboard managers/viewers/etc. This was used in QM2.
                //	Nowadays most such programs don't use SetClipboardViewer. They use AddClipboardFormatListener+WM_CLIPBOARDUPDATE.
                //	known apps that have clipboard viewer installed with SetClipboardViewer:
                //		OpenOffice, LibreOffice: tested Writer, Calc.
                //		VLC: after first Paste.
                //_wPrevClipViewer = Api.SetClipboardViewer(clipOwner);
                //print.it(_wPrevClipViewer);
            }
예제 #17
0
        public void WindowCallback_Subclass()
        {
            int             value   = 42;
            WindowClassInfo myClass = new WindowClassInfo
            {
                ClassName       = "WindowCallback_Subclass",
                WindowProcedure = (window, message, wParam, lParam) =>
                {
                    return(value);
                }
            };

            Atom atom = Windows.RegisterClass(ref myClass);

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

            try
            {
                WindowHandle window = Windows.CreateWindow(atom, style: WindowStyles.Minimize | WindowStyles.Diabled);
                window.IsInvalid.Should().BeFalse();

                try
                {
                    Windows.SendMessage(window, MessageType.Activate, 0, 0).Should().Be((LResult)42);

                    WNDPROC         previous = default;
                    WindowProcedure subClass = (w, m, wParam, lParam) =>
                    {
                        return(Windows.CallWindowProcedure(previous, w, m, wParam, lParam));
                    };

                    value    = 1999;
                    previous = Windows.SetWindowProcedure(window, subClass);
                    Windows.SendMessage(window, MessageType.Activate, 0, 0).Should().Be((LResult)1999);
                    GC.KeepAlive(subClass);
                }
                finally
                {
                    Windows.DestroyWindow(window);
                }
            }
            finally
            {
                Windows.UnregisterClass(atom, null);
            }
        }
예제 #18
0
        private ATOM WindowRegister(HINSTANCE hInstance)
        {
            WndMainProc = new WNDPROC(WndProc);

            WNDCLASSEX wnd;

            wnd.cbClsExtra    = 0;
            wnd.cbSize        = (UInt32)Marshal.SizeOf(typeof(WNDCLASSEX));
            wnd.cbWndExtra    = 0;
            wnd.hbrBackground = IntPtr.Zero;
            wnd.hCursor       = Cursors.Arrow.Handle;
            wnd.hIcon         = IntPtr.Zero;
            wnd.hIconSm       = IntPtr.Zero;
            wnd.hInstance     = hInstance;
            wnd.lpfnWndProc   = WndMainProc;
            wnd.lpszClassName = "Form2";
            wnd.lpszMenuName  = null;
            wnd.style         = 0x0008;

            return(RegisterClassEx(ref wnd));
        }
예제 #19
0
        private bool RegisterWindowClass()
        {
            bool     registerSuccess;
            WNDCLASS wndClass;

            SplashScreen.splashWindowProcedure = new WNDPROC(SplashWindowProcedure);

            registerSuccess = false;
            wndClass        = new WNDCLASS();

            wndClass.style         = (int)((int)ClassStylesFlags.CS_VREDRAW | (int)ClassStylesFlags.CS_HREDRAW);
            wndClass.hInstance     = APIDynamicLinkLibrary.GetModuleHandle(null);          //(IntPtr) 0;
            wndClass.hIcon         = (IntPtr)0;
            wndClass.hCursor       = (IntPtr)0;
            wndClass.hbrBackground = ((IntPtr)SystemColorsIndex.COLOR_WINDOWFRAME);
            wndClass.lpszMenuName  = "";
            wndClass.cbClsExtra    = 0;
            wndClass.cbWndExtra    = 0;
            wndClass.lpfnWndProc   = SplashScreen.splashWindowProcedure;
            wndClass.lpszClassName = WindowClassName;


            if (this._showShadow && this.IsDropShadowSupported())
            {
                wndClass.style = (wndClass.style | (int)WindowClassStyles.CS_DROPSHADOW);
            }
            else
            {
                wndClass.style &= ~((int)WindowClassStyles.CS_DROPSHADOW);
            }

            if (APIWindow.RegisterClass(ref wndClass) != IntPtr.Zero)
            {
                registerSuccess = true;
            }

            return(registerSuccess);
        }
예제 #20
0
 public static IntPtr SetWindowLongPtr(HWND hWnd, int nIndex, WNDPROC wndProc)
 {
     return SetWindowLongPtr(hWnd, nIndex, Marshal.GetFunctionPointerForDelegate(wndProc));
 }
예제 #21
0
 public static extern IntPtr SetWindowProc(IntPtr hWnd, int index, WNDPROC wndProc);
예제 #22
0
 public static extern IntPtr CallWindowProc(WNDPROC wndProc, IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
예제 #23
0
 public static extern IntPtr CreateDialogIndirectParam(IntPtr hInstance, IntPtr lpTemplate, IntPtr hWndParent, WNDPROC lpDialogFunc, IntPtr dwInitParam);
예제 #24
0
        private bool PlatformInit()
        {
            WNDCLASS winClass = new WNDCLASS();

            winClass.style         = WinUser.CS_HREDRAW | WinUser.CS_VREDRAW | WinUser.CS_OWNDC;
            proc                   = WndProc;
            winClass.lpfnWndProc   = Marshal.GetFunctionPointerForDelegate(proc);
            winClass.lpszClassName = "Sparky Win32 Window";
            winClass.hCursor       = WinUser.LoadCursorW(IntPtr.Zero, WinUser.IDC_ARROW);
            winClass.hIcon         = WinUser.LoadIconW(IntPtr.Zero, WinUser.IDI_WINLOGO);

            if (WinUser.RegisterClassW(ref winClass) == 0)
            {
                Log.Error("Could not register Win32 class!");
                return(false);
            }

            RECT size = new RECT(0, 0, (int)properties.width, (int)properties.height);

            WinUser.AdjustWindowRectEx(ref size, WinUser.WS_OVERLAPPEDWINDOW | WinUser.WS_CLIPSIBLINGS | WinUser.WS_CLIPCHILDREN, false, WinUser.WS_EX_APPWINDOW | WinUser.WS_EX_WINDOWEDGE);

            hWnd = WinUser.CreateWindowExW(WinUser.WS_EX_APPWINDOW | WinUser.WS_EX_WINDOWEDGE,
                                           winClass.lpszClassName, title,
                                           WinUser.WS_OVERLAPPEDWINDOW | WinUser.WS_CLIPSIBLINGS | WinUser.WS_CLIPCHILDREN,
                                           (int)(WinUser.GetSystemMetrics(WinUser.SM_CXSCREEN) / 2 - properties.width / 2),
                                           (int)(WinUser.GetSystemMetrics(WinUser.SM_CYSCREEN) / 2 - properties.height / 2),
                                           (int)(size.right + (-size.left)), (int)(size.bottom + (-size.top)), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero
                                           );
            if (hWnd.ToInt32() == 0)
            {
                Log.Error("Could not create window!");
                return(false);
            }

            RegisterWindowClass(hWnd, this);

            hDc = WinUser.GetDC(hWnd);
            PIXELFORMATDESCRIPTOR pfd = GetPixelFormat();
            int pixelFormat           = WinGDI.ChoosePixelFormat(hDc, ref pfd);

            if (pixelFormat != 0)
            {
                if (!WinGDI.SetPixelFormat(hDc, pixelFormat, ref pfd))
                {
                    Log.Error("Failed setting pixel format!");
                    return(false);
                }
            }
            else
            {
                Log.Error("Failed choosing pixel format!");
                return(false);
            }

            Context.Create(properties, hWnd);

            WinUser.ShowWindow(hWnd, WinUser.SW_SHOW);
            WinUser.SetFocus(hWnd);

            return(true);
        }
예제 #25
0
파일: API.cs 프로젝트: jpbruyere/opentk
 internal static extern LRESULT CallWindowProc(WNDPROC lpPrevWndFunc, HWND hWnd, WindowMessage Msg,
     WPARAM wParam, LPARAM lParam);
예제 #26
0
        protected unsafe override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            const string filter = "*.*";

            switch (message)
            {
            case MessageType.Create:
                Size baseUnits = Windows.GetDialogBaseUnits();
                rect = Rectangle.FromLTRB(20 * baseUnits.Width, 3 * baseUnits.Height, rect.Right, rect.Bottom);

                // Create listbox and static text windows.
                hwndList = Windows.CreateWindow(
                    className: "listbox",
                    style: WindowStyles.Child | WindowStyles.Visible | (WindowStyles)ListBoxStyles.Standard,
                    bounds: new Rectangle(baseUnits.Width, baseUnits.Height * 3,
                                          baseUnits.Width * 13 + Windows.GetSystemMetrics(SystemMetric.VerticalScrollWidth), baseUnits.Height * 10),
                    parentWindow: window,
                    menuHandle: (MenuHandle)ID_LIST,
                    instance: ModuleInstance);

                hwndText = Windows.CreateWindow(
                    className: "static",
                    windowName: Storage.GetCurrentDirectory(),
                    style: WindowStyles.Child | WindowStyles.Visible | (WindowStyles)StaticStyles.Left,
                    bounds: new Rectangle(baseUnits.Width, baseUnits.Height, baseUnits.Width * 260, baseUnits.Height),
                    parentWindow: window,
                    menuHandle: (MenuHandle)ID_TEXT,
                    instance: ModuleInstance);

                _existingListBoxWndProc = hwndList.SetWindowProcedure(_listBoxProcedure = ListBoxProcedure);

                fixed(char *f = filter)
                hwndList.SendMessage(ListBoxMessage.Directory, (uint)DIRATTR, f);

                return(0);

            case MessageType.Size:
                rect = Rectangle.FromLTRB(rect.Left, rect.Top, lParam.LowWord, lParam.HighWord);
                return(0);

            case MessageType.SetFocus:
                hwndList.SetFocus();
                return(0);

            case MessageType.Command:
                if (wParam.LowWord == ID_LIST &&
                    (wParam.HighWord == (ushort)ListBoxNotification.DoubleClick))
                {
                    uint i = hwndList.SendMessage(ListBoxMessage.GetCurrentSelection, 0, 0);
                    if (i == WindowDefines.LB_ERR)
                    {
                        break;
                    }

                    int iLength = hwndList.SendMessage(ListBoxMessage.GetTextLength, i, 0) + 1;
                    fixed(char *textBuffer = szFile)
                    {
                        int            result = hwndList.SendMessage(ListBoxMessage.GetText, i, textBuffer);
                        SafeFileHandle hFile  = null;

                        try
                        {
                            using (hFile = Storage.CreateFile(szFile.AsSpan(0, result),
                                                              CreationDisposition.OpenExisting, DesiredAccess.GenericRead, ShareModes.Read))
                            {
                                if (!hFile.IsInvalid)
                                {
                                    bValidFile = true;
                                    hwndText.SetWindowText(Storage.GetCurrentDirectory());
                                }
                            }
                            hFile = null;
                        }
                        catch
                        {
                        }

                        Span <char> dir = stackalloc char[2];

                        if (hFile == null && szFile[0] == ('['))
                        {
                            bValidFile = false;

                            // If setting the directory doesn’t work, maybe it’s a drive change, so try that.
                            try
                            {
                                szFile[result - 1] = '\0';
                                Storage.SetCurrentDirectory(szFile.AsSpan(1, result - 2));
                            }
                            catch
                            {
                                dir[0] = szFile[2];
                                dir[1] = ':';

                                try { Storage.SetCurrentDirectory(dir); }
                                catch { }
                            }

                            // Get the new directory name and fill the list box.
                            hwndText.SetWindowText(Storage.GetCurrentDirectory());
                            hwndList.SendMessage(ListBoxMessage.ResetContent, 0, 0);

                            fixed(char *f = filter)
                            hwndList.SendMessage(ListBoxMessage.Directory, (uint)DIRATTR, f);
                        }
                    }

                    window.Invalidate();
                }
                return(0);

            case MessageType.Paint:
                if (!bValidFile)
                {
                    break;
                }

                uint bytesRead;
                using (var hFile = Storage.CreateFile(szFile, CreationDisposition.OpenExisting,
                                                      DesiredAccess.GenericRead, ShareModes.Read))
                {
                    if (hFile.IsInvalid)
                    {
                        bValidFile = false;
                        break;
                    }

                    bytesRead = Storage.ReadFile(hFile, _buffer);
                }

                using (DeviceContext dc = window.BeginPaint())
                {
                    dc.SelectObject(StockFont.SystemFixed);
                    dc.SetTextColor(SystemColor.ButtonText);
                    dc.SetBackgroundColor(SystemColor.ButtonFace);
                    Encoding.UTF8.GetDecoder().Convert(_buffer.AsSpan(0, (int)bytesRead), _decoded.AsSpan(), true, out _, out int charCount, out _);
                    dc.DrawText(_decoded.AsSpan(0, charCount), rect, DTFLAGS);
                }

                return(0);
            }

            return(base.WindowProcedure(window, message, wParam, lParam));
        }
예제 #27
0
 Window(string title, int count)
 {
     m_title     = title;
     m_delegate  = new WNDPROC(WndProc);
     m_className = $"{CLASS_NAME}{count}";
 }
예제 #28
0
 public static extern IntPtr CallWindowProc(WNDPROC lpPrevWndFunc, IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam);
예제 #29
0
 Window(int count)
 {
     m_delegate  = new WNDPROC(WndProc);
     m_className = $"{CLASS_NAME}{count}";
 }
 public static extern IntPtr CallWindowProc(WNDPROC lpPrevWndFunc, HWND hWnd, int Msg, IntPtr wParam, IntPtr lParam);
예제 #31
0
 public static extern IntPtr CreateDialogIndirectParam(IntPtr hInstance, IntPtr lpTemplate, IntPtr hWndParent, WNDPROC lpDialogFunc, IntPtr dwInitParam);
예제 #32
0
        /// <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;
        }
예제 #33
0
        private HWND _hwnd; // Will be a StrongHWND after TransferHandleOwnership

        internal WindowBase()
        {
            _wndProc = WndProc;
        }
예제 #34
0
 public static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, WNDPROC dwNewLong);
예제 #35
0
 internal WindowBase()
 {
     _wndProc = new WNDPROC(WndProc);
 }
예제 #36
0
 internal WindowBase()
 {
     _wndProc = new WNDPROC(WndProc);
 }
예제 #37
0
 static extern Int32 SetWindowLongW(IntPtr hWnd, Int32 code, WNDPROC newLong);
예제 #38
0
        protected Application(bool useDirect3D12)
        {
            _wndProc = ProcessWindowMessage;
            var wndClassEx = new WNDCLASSEX
            {
                Size                  = Unsafe.SizeOf <WNDCLASSEX>(),
                Styles                = WindowClassStyles.CS_HREDRAW | WindowClassStyles.CS_VREDRAW | WindowClassStyles.CS_OWNDC,
                WindowProc            = _wndProc,
                InstanceHandle        = HInstance,
                CursorHandle          = LoadCursor(IntPtr.Zero, SystemCursor.IDC_ARROW),
                BackgroundBrushHandle = IntPtr.Zero,
                IconHandle            = IntPtr.Zero,
                ClassName             = WndClassName,
            };

            var atom = RegisterClassEx(ref wndClassEx);

            if (atom == 0)
            {
                throw new InvalidOperationException(
                          $"Failed to register window class. Error: {Marshal.GetLastWin32Error()}"
                          );
            }

            Window = new Window("Vortice", 800, 600);

            if (useDirect3D12 &&
                !ID3D12Device.IsSupported(null, FeatureLevel.Level_11_0))
            {
                useDirect3D12 = false;
            }

            var debugFactory = false;

#if DEBUG
            if (useDirect3D12)
            {
                if (D3D12GetDebugInterface <ID3D12Debug>(out var debug).Success)
                {
                    debug.EnableDebugLayer();
                    debugFactory = true;
                }
            }
#endif

            if (useDirect3D12)
            {
                if (CreateDXGIFactory2(debugFactory, out IDXGIFactory4 dxgiFactory4).Failure)
                {
                    throw new InvalidOperationException("Cannot create IDXGIFactory4");
                }

                _dxgiFactory = dxgiFactory4;
            }
            else
            {
                if (CreateDXGIFactory2(debugFactory, out _dxgiFactory).Failure)
                {
                    throw new InvalidOperationException("Cannot create IDXGIFactory4");
                }
            }

            if (useDirect3D12)
            {
                Debug.Assert(D3D12CreateDevice(null, FeatureLevel.Level_11_0, out _d3d12Device).Success);

                _d3d12CommandQueue = _d3d12Device.CreateCommandQueue(new CommandQueueDescription(CommandListType.Direct, CommandQueuePriority.Normal));
            }
            else
            {
                var featureLevels = new FeatureLevel[]
                {
                    FeatureLevel.Level_11_1,
                    FeatureLevel.Level_11_0
                };
                Debug.Assert(ID3D11Device.TryCreate(
                                 null,
                                 DriverType.Hardware,
                                 DeviceCreationFlags.BgraSupport,
                                 featureLevels,
                                 out _d3d11Device,
                                 out _d3d11DeviceContext).Success);
            }

            var swapChainDesc = new SwapChainDescription1
            {
                BufferCount       = FrameCount,
                Width             = Window.Width,
                Height            = Window.Height,
                Format            = Format.B8G8R8A8_UNorm,
                Usage             = Vortice.Usage.RenderTargetOutput,
                SwapEffect        = SwapEffect.FlipDiscard,
                SampleDescription = new SampleDescription(1, 0)
            };

            SwapChain = DXGIFactory.CreateSwapChainForHwnd(_d3d12CommandQueue, Window.Handle, swapChainDesc);
            DXGIFactory.MakeWindowAssociation(Window.Handle, WindowAssociationFlags.IgnoreAltEnter);

            if (useDirect3D12)
            {
                SwapChain3  = SwapChain.QueryInterface <IDXGISwapChain3>();
                _frameIndex = SwapChain3.GetCurrentBackBufferIndex();
            }

            _rtvHeap           = _d3d12Device.CreateDescriptorHeap(new DescriptorHeapDescription(DescriptorHeapType.RenderTargetView, FrameCount));
            _rtvDescriptorSize = _d3d12Device.GetDescriptorHandleIncrementSize(DescriptorHeapType.RenderTargetView);

            // Create frame resources.
            {
                var rtvHandle = _rtvHeap.GetCPUDescriptorHandleForHeapStart();

                // Create a RTV for each frame.
                _renderTargets = new ID3D12Resource[FrameCount];
                for (var i = 0; i < FrameCount; i++)
                {
                    _renderTargets[i] = SwapChain.GetBuffer <ID3D12Resource>(i);
                    _d3d12Device.CreateRenderTargetView(_renderTargets[i], null, rtvHandle);
                    rtvHandle += _rtvDescriptorSize;
                }
            }

            _commandAllocator = _d3d12Device.CreateCommandAllocator(CommandListType.Direct);
            _commandList      = _d3d12Device.CreateCommandList(CommandListType.Direct, _commandAllocator);
            _commandList.Close();

            // Create synchronization objects.
            _d3d12Fence = _d3d12Device.CreateFence(0);
            _fenceValue = 1;
            _fenceEvent = new AutoResetEvent(false);
        }
예제 #39
0
파일: User32.cs 프로젝트: Kuzq/gitter
 public static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, WNDPROC dwNewLong);