C# 在线游戏中未捕获打印窗口

C# 在线游戏中未捕获打印窗口,c#,dllimport,user32,C#,Dllimport,User32,我正在尝试创建一个简单的自动访问程序。 使用该代码捕获只保存灰色图片。 我该怎么办? 其他不是游戏的程序通常会被捕获。 是因为安全计划吗? 我试着在游戏中输入一个键盘,但根本不起作用 SendKeys.SendWait(“W”) SendKeys.Send(“W”) 输入模拟器 发送输入 }游戏不使用GDI显示内容。 您的程序正在创建一个GDI对象(图形)并从中复制内容。但游戏和3d编辑器用于DirectX、OpenGL或任何其他直接访问视频的方式。它们绕过GDI级别 在旧时代它被称为戏剧模

我正在尝试创建一个简单的自动访问程序。 使用该代码捕获只保存灰色图片。 我该怎么办? 其他不是游戏的程序通常会被捕获。 是因为安全计划吗? 我试着在游戏中输入一个键盘,但根本不起作用

  • SendKeys.SendWait(“W”)
  • SendKeys.Send(“W”)
  • 输入模拟器
  • 发送输入

}游戏不使用GDI显示内容。 您的程序正在创建一个GDI对象(图形)并从中复制内容。但游戏和3d编辑器用于DirectX、OpenGL或任何其他直接访问视频的方式。它们绕过GDI级别

在旧时代它被称为戏剧模式

当游戏使用directx时,请使用本文:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Drawing.Imaging;

namespace WindowsFormsApp2
{

public partial class Form1 : Form
{
        [System.Runtime.InteropServices.DllImport("User32", EntryPoint = "FindWindow")]
    private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    String AppPlayerName = "LOST ARK (64-bit) v.1.0.1.3";

    [DllImport("user32.dll", SetLastError = true)]

    [return: MarshalAs(UnmanagedType.Bool)]

    static extern bool PrintWindow(IntPtr hwnd, IntPtr hDC, uint nFlags);



    [DllImport("user32.dll", SetLastError = true)]

    static extern int GetWindowRgn(IntPtr hWnd, IntPtr hRgn);



    [DllImport("gdi32.dll")]

    static extern IntPtr CreateRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);


    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        IntPtr findwindow = FindWindow(null, AppPlayerName);
        if (findwindow != IntPtr.Zero)
        {
            Debug.WriteLine("Found.");
            Debug.WriteLine(findwindow.ToString());
            PrintWindow(findwindow);
        }
        else
        {
            Debug.WriteLine("Not Found");
        }
    }

    public static void PrintWindow(IntPtr hwnd)

    {

        Rectangle rc = Rectangle.Empty;

        Graphics gfxWin = Graphics.FromHwnd(hwnd);

        rc = Rectangle.Round(gfxWin.VisibleClipBounds);

        Bitmap bmp = new Bitmap(rc.Width, rc.Height, PixelFormat.Format32bppArgb);

        Graphics gfxBmp = Graphics.FromImage(bmp);

        IntPtr hdcBitmap = gfxBmp.GetHdc();

        bool succeeded = PrintWindow(hwnd, hdcBitmap, 1);

        gfxBmp.ReleaseHdc(hdcBitmap);

        if (!succeeded)

        {

            gfxBmp.FillRectangle(

                new SolidBrush(Color.Gray),

                new Rectangle(Point.Empty, bmp.Size));

        }

        IntPtr hRgn = CreateRectRgn(0, 0, 0, 0);

        GetWindowRgn(hwnd, hRgn);

        Region region = Region.FromHrgn(hRgn);

        if (!region.IsEmpty(gfxBmp))

        {

            gfxBmp.ExcludeClip(region);

            gfxBmp.Clear(Color.Transparent);

        }

        gfxBmp.Dispose();

        bmp.Save(Application.StartupPath + "1.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }
}