 This is a continuation of a series of posts with the prefix "15000 FPS", beginning here: part 1 and part 1.5 . It is possible to get 15K FPS to this window, but a reasonable approach here is not to hammer FPS in the Render () cycle, but to redraw it only if necessary, and most of the rest of the work for us will be done by Windows itself. Looking at the screenshot, the first thought of the coder - “ha, yes, we all know how to make non-standard windows!”.
 This is a continuation of a series of posts with the prefix "15000 FPS", beginning here: part 1 and part 1.5 . It is possible to get 15K FPS to this window, but a reasonable approach here is not to hammer FPS in the Render () cycle, but to redraw it only if necessary, and most of the rest of the work for us will be done by Windows itself. Looking at the screenshot, the first thought of the coder - “ha, yes, we all know how to make non-standard windows!”. Since the article is also published in the Design blog, I ask the designers not to kick me for the lack of Pixel Perfect — I made this cutting myself ... Starpere coders like me have time to get acquainted with music and write photoshop in Photoshop , and with a strong need, I myself easel and piano, as far as I can.
 Since the article is also published in the Design blog, I ask the designers not to kick me for the lack of Pixel Perfect — I made this cutting myself ... Starpere coders like me have time to get acquainted with music and write photoshop in Photoshop , and with a strong need, I myself easel and piano, as far as I can.GFX.Clear(WindowFillColor);  internal static Bitmap Shadow_L = Resources.Shadow_L.Clone( new Rectangle(0, 0, Resources.Shadow_L.Width, Resources.Shadow_L.Height), PixelFormat.Format32bppPArgb); //  ..     those. We take a piece of skin from the application's resources, and pump it once, until [the correct term is “pre-optimized for alpha?”] and then use it from the static class, and this greatly increases the FPS. Profit public const Int32 ULW_COLORKEY = 0x00000001; public const Int32 ULW_ALPHA = 0x00000002; public const Int32 ULW_OPAQUE = 0x00000004; public const byte AC_SRC_OVER = 0x00; public const byte AC_SRC_ALPHA = 0x01; public const uint WM_SYSCOMMAND = 0x0112; public const uint DOMOVE = 0xF012; public const uint DOSIZE1 = 0xF001; //... public const uint DOSIZE8 = 0xF008; public const uint SRCCOPY = 0x00CC0020; Some will ask: “Is Win32 really holding up on some kind of numbers?” Roughly speaking, yes. But in the majority it was solved through implicit conversions of enum. At the time of the 486th processor, the concept of “Everything is an object” would have been inadmissible wastefulness! [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)] public static extern IntPtr GetDC(IntPtr hWnd); [DllImport("user32.dll", ExactSpelling = true)] public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC); [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)] public static extern IntPtr CreateCompatibleDC(IntPtr hDC); [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)] public static extern TBool DeleteDC(IntPtr hdc); //  ..  protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; if (!DesignMode) cp.ExStyle |= 0x00080000; return cp; } } Harsh MFC coders will happily recognize the familiar “CreateParams”, but will be surprised at the style constant. private void AssignGFX() { IntPtr screenDc = Win32Helper.GetDC(IntPtr.Zero); IntPtr memDc = Win32Helper.CreateCompatibleDC(screenDc); IntPtr hBitmap = IntPtr.Zero; IntPtr objBitmap = IntPtr.Zero; try { hBitmap = BMP.GetHbitmap(Color.FromArgb(0)); objBitmap = Win32Helper.SelectObject(memDc, hBitmap); TSize size = new TSize(Width, Height); TPoint pointSource = new TPoint(0, 0); TPoint topPos = new TPoint(Left, Top); Win32Helper.UpdateLayeredWindow(Handle, screenDc, ref topPos, ref size, memDc, ref pointSource, 0, ref blend, Win32Helper.ULW_ALPHA); } finally { Win32Helper.ReleaseDC(IntPtr.Zero, screenDc); if (hBitmap != IntPtr.Zero) { Win32Helper.DeleteObject(objBitmap); Win32Helper.DeleteObject(hBitmap); } Win32Helper.DeleteDC(memDc); } } "Take out" the content of our System.Drawing.Bitmap BMP on the window. private void Form1_MouseDown(object sender, MouseEventArgs e) { if (.. /*  */ ...) { Win32Helper.ReleaseCapture(); Win32Helper.PostMessage(Handle, Win32Helper.WM_SYSCOMMAND, Win32Helper.DOSIZE8, 0); } else if (eY < 28) /*   */ { Win32Helper.ReleaseCapture(); Win32Helper.PostMessage(Handle, Win32Helper.WM_SYSCOMMAND, Win32Helper.DOMOVE, 0); } }  interface ISkinnableControl { void RedrawControl(Graphics GFX); } in which each control itself “draws” as he pleases on the GFX from the main window - I drew the buttons from the GraphicsPath, and you can also take some of the PNGs. for (int cnt = Controls.Count - 1; cnt >= 0; cnt--) if (Controls[cnt] is ISkinnableControl && Controls[cnt].Visible) ((ISkinnableControl)Controls[cnt]).RedrawControl(GFX); else Controls[cnt].DrawToBitmap(BMP, new Rectangle(/*W,H*/)); Of course, unfortunately the standard Control.DrawToBitmap () method only gives us a “screenshot”, control, but now the control is visible, although we need a little extra. backend code for dynamic updates of its view. However, the heirs of ISkinnableControl are also concerned.Source: https://habr.com/ru/post/165403/
All Articles