static void Render() { while (running) { BeginScene(); ClearScene(); RawRectangleF rectF; if (TargetWindow == IntPtr.Zero) { rectF = new RawRectangleF(50, 50, OverlayRect.Right, OverlayRect.Bottom); } else { GetWindowRect(TargetWindow, out RECT TargetRect); //rectF = new RawRectangleF(50, 50, OverlayRect.Right, OverlayRect.Bottom); rectF = new RawRectangleF(50 + TargetRect.Left, 50 + TargetRect.Top, OverlayRect.Right, OverlayRect.Bottom); WindowSetAbove(); SetWindowLongPtr(OverlayWindow, (int)GWL_STYLE, new IntPtr((long)nv_edit)); SetWindowLongPtr(OverlayWindow, (int)GWL_EXSTYLE, new IntPtr((long)nv_ex_edit)); } target.DrawText("Hello my name is Zhengyu Wu", format, rectF, brushes["red"]); EndScene(); Thread.Sleep(1000 / 144); } Console.WriteLine("End of render thread"); }
protected void DrawText(WindowRenderTarget device, Color color, float x, float y, float width, float height, string text, TextFormat textFormat) { using (SolidColorBrush brush = new SolidColorBrush(device, color)) { RectangleF rect = new RectangleF(x, y, width, height); device.DrawText(text, textFormat, rect, brush); } }