コード例 #1
0
        static void Main(string[] args)
        {
            var manager = new D3DManager();

            var windowProc = new WNDPROC((Win32API.HWND _hwnd, WM uMsg, Win32API.WPARAM wParam, Win32API.LPARAM lParam) =>
            {
                if (ImGui.ImGui_ImplWin32_WndProcHandler(_hwnd.Value, (uint)uMsg, wParam.Value, lParam.Value) != IntPtr.Zero)
                {
                    return(1);
                }

                switch (uMsg)
                {
                case WM.DESTROY:
                    manager.Dispose();
                    User32.PostQuitMessage(0);
                    return(0);

                case WM.RESIZE:
                    // manager.Resize(lParam.LowWord, lParam.HiWord);
                    s_width  = lParam.LowWord;
                    s_height = lParam.HiWord;
                    return(0);

                case WM.PAINT:
                    {
                        PAINTSTRUCT ps = default;
                        var hdc        = User32.BeginPaint(_hwnd, ref ps);
                        User32.EndPaint(_hwnd, ref ps);
                        return(0);
                    }

                case WM.MOUSEMOVE:
                    {
                        s_mouse.X = lParam.LowWord;
                        s_mouse.Y = lParam.HiWord;
                        return(0);
                    }

                case WM.LBUTTONDOWN:
                    {
                        // User32.SetCapture(_hwnd);
                        s_mouse.Buttons |= ButtonFlags.Left;
                        return(0);
                    }

                case WM.LBUTTONUP:
                    {
                        s_mouse.Buttons &= ~ButtonFlags.Left;
                        if (s_mouse.Buttons == 0)
                        {
                            // User32.ReleaseCapture();
                        }
                        return(0);
                    }

                case WM.MBUTTONDOWN:
                    {
                        // SetCapture(hWnd);
                        s_mouse.Buttons |= ButtonFlags.Middle;
                        return(0);
                    }

                case WM.MBUTTONUP:
                    {
                        s_mouse.Buttons &= ~ButtonFlags.Middle;
                        if (s_mouse.Buttons == 0)
                        {
                            // ReleaseCapture();
                        }
                        return(0);
                    }

                case WM.RBUTTONDOWN:
                    {
                        // SetCapture(hWnd);
                        s_mouse.Buttons |= ButtonFlags.Right;
                        return(0);
                    }

                case WM.RBUTTONUP:
                    {
                        s_mouse.Buttons &= ~ButtonFlags.Right;
                        if (s_mouse.Buttons == 0)
                        {
                            // ReleaseCapture();
                        }
                        return(0);
                    }

                case WM.MOUSEWHEEL:
                    {
                        s_clearWheel = false;
                        var d        = wParam.HiWord;
                        if (d > 0)
                        {
                            s_mouse.Wheel = 1;
                        }
                        else if (d < 0)
                        {
                            s_mouse.Wheel = -1;
                        }
                        else
                        {
                            s_mouse.Wheel = 0;
                        }
                        return(0);
                    }
                }

                return(User32.DefWindowProcW(_hwnd, uMsg, wParam, lParam));
            });
            var ptr = Marshal.GetFunctionPointerForDelegate(windowProc);

            var windowClass = new WNDCLASSEXW();

            windowClass.cbSize        = Marshal.SizeOf(typeof(WNDCLASSEXW));
            windowClass.style         = CS.HREDRAW | CS.VREDRAW;
            windowClass.lpfnWndProc   = ptr;
            windowClass.cbClsExtra    = 0;
            windowClass.cbWndExtra    = 0;
            windowClass.lpszClassName = WINDOW_CLASS;
            var register = User32.RegisterClassExW(ref windowClass);

            if (register == 0)
            {
                Console.WriteLine("fail to RegisterClassExW");
                return;
            }

            var hwnd = User32.CreateWindowExW(
                0,
                WINDOW_CLASS,
                "SharpImGui",
                WS.OVERLAPPEDWINDOW,
                32, 32,
                640, 480,
コード例 #2
0
        private static IntPtr HandleWindowEvent(IntPtr hWnd, WindowMessage msg, IntPtr wParam, IntPtr lParam)
        {
            switch (msg)
            {
            case WindowMessage.CREATE:

                if (lemonMode)
                {
                    hHardBackgroudBrush = GDI.CreateSolidBrush(GDI.RGB(244, 220, 20));
                    hProgressbarBrush   = GDI.CreateSolidBrush(GDI.RGB(182, 255, 100));

                    //foregroundColor = GDI.RGB(98, 247, 124);
                    foregroundColor = GDI.RGB(86, 223, 13);
                }
                else if (lightMode)
                {
                    hHardBackgroudBrush = GDI.CreateSolidBrush(GDI.RGB(224, 224, 224));
                    hProgressbarBrush   = GDI.CreateSolidBrush(GDI.RGB(120, 248, 99));

                    foregroundColor = GDI.RGB(0, 0, 0);
                }
                else
                {
                    hHardBackgroudBrush = GDI.CreateSolidBrush(GDI.RGB(54, 57, 63));
                    hProgressbarBrush   = GDI.CreateSolidBrush(GDI.RGB(255, 59, 106));

                    foregroundColor = GDI.RGB(220, 221, 222);
                }

                hTextFont = GDI.CreateFont(14, 0, 0, 0,
                                           FontWeight.Medium, 0, 0, 0,
                                           FontLanguageCharSet.Default, FontPrecision.Outline, FontClipPrecision.Default, FontQuality.Cleartype, FontPitch.Variable, "Segoe UI");

                hTitleFont = GDI.CreateFont(26, 0, 0, 0,
                                            FontWeight.Medium, 0, 0, 0,
                                            FontLanguageCharSet.Default, FontPrecision.Outline, FontClipPrecision.Default, FontQuality.Cleartype, FontPitch.Variable, "Consolas");

                hProgressbarFont = GDI.CreateFont(16, 0, 0, 0,
                                                  FontWeight.Medium, 0, 0, 0,
                                                  FontLanguageCharSet.Default, FontPrecision.Outline, FontClipPrecision.Default, FontQuality.Cleartype, FontPitch.Variable, "Segoe UI");

                return(IntPtr.Zero);

            case WindowMessage.DESTROY:
                User32.PostQuitMessage(0);

                GDI.DeleteObject(hBackgroudBrush);
                GDI.DeleteObject(hHardBackgroudBrush);

                GDI.DeleteObject(hProgressbarBrush);

                GDI.DeleteObject(hTextFont);
                GDI.DeleteObject(hTitleFont);
                GDI.DeleteObject(hProgressbarFont);

                IsOpen = false;

                return(IntPtr.Zero);

            case WindowMessage.NCHITTEST:     // Drag'n'Drop everywhere
                IntPtr hit = User32.DefWindowProc(hWnd, (WindowMessage)msg, wParam, lParam);
                if (hit.ToInt32() == 1)
                {
                    hit = new IntPtr(2);
                }
                return(hit);

            case WindowMessage.CLOSE:
                return(IntPtr.Zero);

            case WindowMessage.PAINT:
                PaintStruct ps;
                Rect        rect;

                // Begin paint
                IntPtr hdc = User32.BeginPaint(hWnd, out ps);
                GDI.SetBkColor(hdc, backgroundColor);
                GDI.SetTextColor(hdc, foregroundColor);
                GDI.SelectObject(hdc, hTextFont);

                User32.GetClientRect(hWnd, out rect);

                // Progress bars

                GDI.SetBkMode(hdc, BackgroundMode.TRANSPARENT);
                GDI.SelectObject(hdc, hProgressbarFont);
                DrawProgressBar(hdc, VRCModUpdaterCore.progressTotal, VRCModUpdaterCore.currentStatus, 40, rect.Bottom - 100, rect.Right - 40, rect.Bottom - 70);
                DrawProgressBar(hdc, VRCModUpdaterCore.progressDownload, null, 40, rect.Bottom - 60, rect.Right - 40, rect.Bottom - 30);

                // Text
                GDI.SetBkMode(hdc, BackgroundMode.OPAQUE);
                Rect titleRect = new Rect(ps.rcPaint.Left + 5, ps.rcPaint.Top + 5, ps.rcPaint.Right - 5, ps.rcPaint.Top + 125 - 5);
                GDI.SelectObject(hdc, hTitleFont);
                User32.DrawText(hdc, "VRCModUpdater", -1, ref titleRect, DrawText.SINGLELINE | DrawText.CENTER | DrawText.VCENTER);

                GDI.SelectObject(hdc, hTextFont);
                User32.DrawText(hdc, $"Loader v{VRCModUpdaterPlugin.VERSION}\nCore v{VRCModUpdaterCore.VERSION}", -1, ref titleRect, DrawText.LEFT | DrawText.TOP);
                User32.DrawText(hdc, $"MelonLoader {BuildInfo.Version}\nVRChat {UnityEngine.Application.version}", -1, ref titleRect, DrawText.RIGHT | DrawText.TOP);

                // End paint
                User32.EndPaint(hWnd, ref ps);

                return(IntPtr.Zero);
            }

            return(User32.DefWindowProc(hWnd, msg, wParam, lParam));
        }