我在 http://www.codeproject.com/cs/media/IECapture.asp 看到一个例子
但该例只能在xp下使用,在2000下,其中的printWindow函数就会出错。大家看看有什么办法可以解决这个问题??
急啊谁能解决的话,我会另开帖加分的,帮帮我吧

解决方案 »

  1.   

    模拟printscreen
    然后取出剪贴板的数据
      

  2.   


    class GDI32
    {
    [DllImport("GDI32.dll")]
    public static extern bool BitBlt(int hdcDest,int nXDest,int nYDest,
    int nWidth,int nHeight,int hdcSrc,
    int nXSrc,int nYSrc,int dwRop);
    [DllImport("GDI32.dll")]
    public static extern int CreateCompatibleBitmap(int hdc,int nWidth, 
    int nHeight);
    [DllImport("GDI32.dll")]
    public static extern int CreateCompatibleDC(int hdc);
    [DllImport("GDI32.dll")]
    public static extern bool DeleteDC(int hdc);
    [DllImport("GDI32.dll")]
    public static extern bool DeleteObject(int hObject);
    [DllImport("GDI32.dll")]
    public static extern int GetDeviceCaps(int hdc,int nIndex);
    [DllImport("GDI32.dll")]
    public static extern int SelectObject(int hdc,int hgdiobj);
    } class User32
    {
    [DllImport("User32.dll")]
    public static extern int GetDesktopWindow();
    [DllImport("User32.dll")]
    public static extern int GetWindowDC(int hWnd);
    [DllImport("User32.dll")]
    public static extern int ReleaseDC(int hWnd,int hDC);
    [DllImport("User32.dll")]
    public static extern int GetDC(int hwnd);
    }
    public void CaptureScreen(string fileName, ImageFormat imageFormat)
    {
    int intHdc = User32.GetDC(0);
    int w= Screen.PrimaryScreen.Bounds.Width;
    int h= Screen.PrimaryScreen.Bounds.Height;
    int hdcSrc = User32.GetWindowDC(User32.GetDesktopWindow()), 
    hdcDest = GDI32.CreateCompatibleDC(intHdc),
    hBitmap = GDI32.CreateCompatibleBitmap(intHdc,
    w,h);
    GDI32.SelectObject(hdcDest,hBitmap);
    GDI32.BitBlt(hdcDest,0,0,GDI32.GetDeviceCaps(intHdc,8),
    GDI32.GetDeviceCaps(intHdc,10),
    intHdc,0,0,0x00CC0020);
    SaveImageAs(hBitmap,fileName,imageFormat);
    Cleanup(hBitmap,intHdc,hdcDest);
    }//end CaptureScreen
    private void Cleanup(int hBitmap, int hdcSrc, int hdcDest)
    {
    User32.ReleaseDC(User32.GetDesktopWindow(),hdcSrc);
    GDI32.DeleteDC(hdcDest);
    GDI32.DeleteObject(hBitmap);
    }//end Cleanup    private void SaveImageAs(int hBitmap, string fileName, ImageFormat imageFormat)
    {
    Bitmap image = 
    new Bitmap(Image.FromHbitmap(new IntPtr(hBitmap)),
    Image.FromHbitmap(new IntPtr(hBitmap)).Width,
    Image.FromHbitmap(new IntPtr(hBitmap)).Height);
    image.Save(fileName,imageFormat);
    }//end SaveImageAs