//得到屏幕的DC
             IntPtr dc1 = g1.GetHdc();这个得到的是你窗体的GC吧

解决方案 »

  1.   

    //得到屏幕的DC
                IntPtr dc1 = g1.GetHdc();屏幕的是IntPtr dc1 = GetDC(0);
    GetDC是windowsAPI,Intptr GetDC(IntPtr hwnd);
      

  2.   

    运行结果 是什么图都没有,为什么呢!!!?????using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    //using DWORD = System.UInt32;
    //using HANDLE = System.IntPtr;
    //using HDC = System.IntPtr;
    namespace SmartDeviceProject3
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        [System.Runtime.InteropServices.DllImportAttribute("coredll.dll")]
            private static extern bool BitBlt(
            IntPtr hdcDest, // 目标 DC的句柄
            int nXDest,
            int nYDest,
            int nWidth,
            int nHeight,
            IntPtr hdcSrc,  // 源DC的句柄
            int nXSrc,
            int nYSrc,
            System.Int32 dwRop  // 光栅的处理数值
            );
            //[System.Runtime.InteropServices.DllImportAttribute("coredll.dll")]
            //public static extern IntPtr FindWindow(String lpClassName, String lpWindowName);
            [System.Runtime.InteropServices.DllImportAttribute("coredll.dll")]
            private static extern IntPtr GetCapture();
            [System.Runtime.InteropServices.DllImportAttribute("coredll.dll")]
            private static extern IntPtr GetDC(IntPtr hWnd);
            private void button1_Click(object sender, EventArgs e)
            {
                //IntPtr hwnd1 = FindWindow(null, "Form1");            this.Capture = true;
                IntPtr hwnd1 = GetCapture();
                this.Capture = false;            IntPtr hDC = GetDC(hwnd1);
                Graphics g1 = Graphics.FromHdc(hDC);            //创建一个以当前屏幕为模板的图象
                //Graphics g1 = Graphics.FromHdc(hwnd2);
                
                //创建以屏幕大小为标准的位图 
                Image bitmap = new Bitmap(800, 600);
                Graphics g2 = Graphics.FromImage(bitmap);
                //得到屏幕的DC
                IntPtr dc1 = g1.GetHdc();
                //得到Bitmap的DC 
                IntPtr dc2 = g2.GetHdc();
                //调用此API函数,实现屏幕捕获
                BitBlt(dc2, 0, 0, 800, 600, dc1, 0, 0, 13369376);            //把当前屏幕拷贝到位图中  
                pictureBox1.Image = bitmap;
                //g1.ReleaseHdc(dc1);            //释放屏幕句柄               g2.ReleaseHdc(dc2);
            }
        }
    }