GDI Overlay in C# WPF

HexEdit

New member
In diesem Tutorial werde ich euch anhand von C#/WPF

die implementation von GDI Overlay näher bringen.


Hier werde ich ein Window ("OverlayWin") erstellen das über ein anderes Fenster ("Programm/Spiel") legen trotzdem aber Interaktionen

wie Mausklick usw.. zulassen (Hierfür werde ich die Methode Get/SetWindowLong aus "user32.dll" mitteles DLLImport einbinden)



Hier werden die Grundeigenschaften des Fensters festgelegt
Code:
public OverlayWin()
{
    this.ShowInTaskbar = false;
    this.AllowsTransparency = true;
    this.WindowStyle = WindowStyle.None;
    this.Background = Brushes.Green; //nur als Beispiel normal      Transparent
    this.Topmost = true;
    this.Height = 0;
    this.Width = 0;
}
Hindurchklicken durch das Fenster wird implementiert (in die "OnSourceInitialized" wird später noch mehr kommen):
Code:
[DllImport("user32.dll", SetLastError = true)]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("user32.dll")]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
Code:
protected override void OnSourceInitialized(EventArgs e)
{
    base.OnSourceInitialized(e);

    IntPtr winHWnd = new WindowInteropHelper(this).Handle;
    int initialStyle = GetWindowLong(winHWnd, -20);
    SetWindowLong(winHWnd, -20, initialStyle | 0x80000 | 0x20);
}
Possition und größe an das "Ziel Programm" anpassen:
Code:
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
Code:
protected override void OnSourceInitialized(EventArgs e)
{
    .........

    IntPtr targetWindow = FindWindow(null, "z.b. Counter Strike");
    GetWindowRect(targetWindow, out RECT winRect);

    this.Top = winRect.top;
    this.Left = winRect.left;

    this.Height = winRect.bottom - winRect.top;
    this.Width = winRect.right - winRect.left;
}

Ich hoffe es war ein gutes Tutorial und meine Rechtschreibfehler fallen nicht auf xD
vl werde ich demnächst noch ein Tutorial machen wie man das ganze dann zb für ein ESP verwenden kann,
dass heißt ich code eins da ich kein bock hab dann die ganzen BasePointer der EntityLists in zb csgo mit Cheat engine zu suchen.
werde ich ein für irgend ein kleines Spiel den Hack coden.


Kompletter Code:
Code:
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;

namespace GDIOverlay
{
    class Program : Application
    {
        [STAThread]
        static void Main(string[] args)
        {
            new Program().Run();
        }

        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            new OverlayWin().Show();
        }
    }

    class OverlayWin : Window
    {
        public struct RECT
        {
            public int left, top, right, bottom;
        }

        [DllImport("user32.dll", SetLastError = true)]
        public static extern int GetWindowLong(IntPtr hWnd, int nIndex);

        [DllImport("user32.dll")]
        public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);


        [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);


        public OverlayWin()
        {
            this.ShowInTaskbar = false;
            this.AllowsTransparency = true;
            this.WindowStyle = WindowStyle.None;
            this.Background = Brushes.Transparent;
            this.Topmost = true;
            this.Height = 0;
            this.Width = 0;
        }

        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            IntPtr winHWnd = new WindowInteropHelper(this).Handle;
            int initialStyle = GetWindowLong(winHWnd, -20);
            SetWindowLong(winHWnd, -20, initialStyle | 0x80000 | 0x20);

            IntPtr targetWindow = FindWindow(null, "z.b. Counter Strike");
            GetWindowRect(targetWindow, out RECT winRect);

            this.Top = winRect.top;
            this.Left = winRect.left;

            this.Height = winRect.bottom - winRect.top;
            this.Width = winRect.right - winRect.left;
        }
    }
}
 
Zurück
Oben