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 OpenCvSharp;

using System.Diagnostics;


namespace WindowsFormsApp1

{

    public partial class Form1 : Form

    {

        [System.Runtime.InteropServices.DllImport("User32", EntryPoint = "FindWindow")]

        private static extern IntPtr FindWindow(string IpClassName, string IpWindowName);


        [System.Runtime.InteropServices.DllImport("user32.dll")]

        internal static extern bool PrintWindow(IntPtr hWnd, IntPtr hdcBlt, int nFlags);



        //프로그램창 대상

        string AppPlayerName = "notepad";


        public Form1()

        {

            InitializeComponent();

        }


        private void button1_Click(object sender, EventArgs e)

        {

            IntPtr findwindow = FindWindow(null, AppPlayerName);

            if(findwindow != IntPtr.Zero)

            {

              

                Debug.WriteLine("창 확인");


            

                Graphics Graphicsdata = Graphics.FromHwnd(findwindow);


           

                Rectangle rect = Rectangle.Round(Graphicsdata.VisibleClipBounds);


                

                Bitmap bmp = new Bitmap(rect.Width, rect.Height);


          

                using (Graphics g = Graphics.FromImage(bmp))

                {

             

                    IntPtr hdc = g.GetHdc();

                    PrintWindow(findwindow, hdc, 0x0);

                    g.ReleaseHdc(hdc);

                }


           

                pictureBox1.Image = bmp;

            }

            else

            {

                Debug.WriteLine("확인불가");

            }

        }

    }

}




이렇게 짰는데 윈도우 타이틀명을 잘못쓴건지 자꾸 확인불가라고만 나옵니다 ㅠㅠㅠㅠ