To  qiuji(忆秋季) :我们要鼠标的形状,可能你理解反了。

解决方案 »

  1.   

    你取的hDC是当前窗口的,因为鼠标不属于当前窗口,所以图象里不包括鼠标。用整个屏幕的hDC试试。
      

  2.   

    你用系统的pringscreen按键来截取的时候也是没有的啊
    至于什么原因,我也不清楚
      

  3.   

    weifenluo(weifenluo),谢谢你,怎么用整个屏幕的hDC? code怎么写?
      

  4.   

    从楼主的代码上看,
      IntPtr hDCDesktop = Win32.GetDC(hWndDesktop);
    应该就是指的是屏幕 DC 了。创建屏幕 DC 的实际代码应该如下:
    [DllImport("GDI32.DLL")]
    private static extern IntPtr CreateDC(
       string driverName,
       string deviceName,
       string output,
       IntPtr lpInitData);{
         ...
         IntPtr hDCDesktop = CreateDC("DISPLAY", null, null, IntPtr.Zero);
         ...
    }试试看吧,不过我没试 :-Q
      

  5.   

    调用API函数DrawIconEx(),来画鼠标。
    [DllImport("user32.dll", EntryPoint="DrawIconEx")]
    private static extern int DrawIconEx (
    int hdc,
    int xLeft,
    int yTop,
    int hIcon,
    int cxWidth,
    int cyWidth,
    int istepIfAniCur,
    int hbrFlickerFreeDraw,
    int diFlags
    );
      

  6.   

    To qiuji(忆秋季):
      请问: 
           难道像 ACDSee 这类看图软件里的“包含鼠标指针的屏幕截图”功能
           是按照类似于你的方法实现的吗?
      

  7.   

    AhBian(阿扁):
    你的方法我试过了,还是一样.qiuji(忆秋季) :
    你那个DrawIconEx是怎么用的?可以举个例子吗? 还有如果由于文件运行而导致的mouse形状改变,怎么办呢?
      

  8.   

    我现在用的机器上没有安装VS.NET,所以不能给你一个准确的例子。
    你可以参考一下下面的例子:
    (这是使用delphi实现的,在C#中原理类似)
    use the API DrawIconEx( ) to draw an Cursor to a bitmap:begin
    hCursor := GetCursor; 
    CopyBmp := TBitmap.Create;
    CopyBmp.Width := 32;
    CopyBmp.Height := 32;
    DrawIconEx(CopyBmp.Canvas.Handle,0,0, hCursor, 0,0, 0, 0, DI_DEFAULTSIZE or DI_NORMAL);
    Canvas.Draw(20,20,CopyBmp);
    CopyBmp.SavetoFile('C:\SomeBmp.bmp');
    CopyBmp.Free;
    end;
      

  9.   

    这边还有一个方法,也是获得鼠标后然后再画到图片上的。
    (....you can obtain a handle to the current cursor and then use the DrawIcon() API to draw it into the screen capture at the appropriate coordinates. )http://support.microsoft.com/default.aspx?scid=kb;en-us;230495
      

  10.   

    qiuji(忆秋季),我用以下来运行你的例子:}
    Bitmap b=new Bitmap(800,600);
    graphics = Graphics.FromImage(b);
    graphics.DrawImage(b,new Rectangle(10,10,b.Width,b.Height));DrawIconEx(b.GetHicon(),0,0, GetCurrentCursorHandle(), 0,0, 0, 0, DI_DEFAULTSIZE);
    }HCURSOR GetCurrentCursorHandle()
    {
    ......
    }但是就提示HCURSOR缺少using指令,HCURSOR是一个类吗?
      

  11.   

    可以不用GetCurrentCursorHandle(),
    你调用API函数:GetCursor()或者GetCursorInfo()
      

  12.   

    qiuji(忆秋季) ,我根据你的提示写成以下:}
    Bitmap b=new Bitmap(800,600);
    graphics = Graphics.FromImage(b);
    graphics.DrawImage(b,new Rectangle(10,10,b.Width,b.Height));Win32.DrawIconEx((int)b.GetHicon(),0,0, Win32.GetCursor(), 10,10, 0, 0, 0);
    }{
    [DllImport("user32.dll")]
    public static extern int GetCursor();}compile是通过了,但还是没有mouse出现,是不是因为DrawIconEx里面的参数设置错误?
      

  13.   

    是重新劃的
    Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
    Private Declare Function GetCursor Lib "user32" () As Long
    Private Sub Form_Paint()
          DrawIcon Me.hdc, 0, 0, GetCursor
    End Sub
      

  14.   

    GetCursorPos()得到当时鼠标的坐标,
        再GetCursor()得到鼠标的HCURSOR。
        最后把鼠标的位图拷贝到 先前抓到的位图。
      

  15.   

    GetCursorPos()得到当时鼠标的坐标,
        再GetCursor()得到鼠标的HCURSOR。
        最后把鼠标的位图拷贝到 先前抓到的位图。 
    拷位图时, 可以用得到的HCURSOR作为参数传到位图拷贝函数里。
      

  16.   

    我试了一个晚上,只想出一个不完美的方法。1 打开系统目录下的Cursors目录,如:C:\WINNT\Cursors,用ACDSEE等
    看图软件打开rainbow.ani,然后保存为gif格式,再用Photoshop处理一
    下生成一张鼠标指针的gif图片。注意,背景应该是透明的。2 把这个gif文件拷贝到程序运行的目录。3 执行代码如下(API声明略)://创建显示器的DC
    IntPtr dc1 = CreateDC ( "DISPLAY" , null , null , ( IntPtr ) null ) ;
    //由一个指定设备的句柄创建一个新的Graphics对象
    Graphics g1 = Graphics.FromHdc ( dc1 ) ;//根据屏幕大小创建一个与之相同大小的Bitmap对象
    bmp = new Bitmap ( Screen.PrimaryScreen.Bounds.Width , 
    Screen.PrimaryScreen.Bounds.Height , g1 ) ;
    Graphics g2 = Graphics.FromImage ( bmp ) ;//获得屏幕的句柄
    IntPtr dc3 = g1.GetHdc ( ) ;
    //获得位图的句柄
    IntPtr dc2 = g2.GetHdc ( ) ;//把当前屏幕捕获到位图对象中
    BitBlt ( dc2 , 0 , 0 , Screen.PrimaryScreen.Bounds.Width ,
    Screen.PrimaryScreen.Bounds.Height , dc3 , 0 , 0 , 13369376 ) ;//释放屏幕句柄
    g1.ReleaseHdc ( dc3 ) ;
    //释放位图句柄
    g2.ReleaseHdc ( dc2 ) ;Bitmap cursor = new Bitmap(Application.StartupPath+"\\cursor.gif");
    g2.DrawImage(cursor, MousePosition.X, MousePosition.Y, cursor.Width, cursor.Height);
    bmp.Save("C:\\capture.jpg");picBox1.Image = bmp;
    如果要画出系统当前的鼠标指针,则会碰到指针位置与实际位置不符的问题。
    什么原因呢?你打开C:\WINNT\Cursors,用ACDSEE浏览该目录下的指针文件,
    我想你就会明白其中的原因了。以下是我画系统当前鼠标指针的代码:Rectangle rect = new Rectangle(
    Cursor.Position.X, Cursor.Position.Y,
    Cursor.Size.Width, Cursor.Size.Height);Cursor.Draw(g2,rect);Bitmap bmp2 = new Bitmap(Cursor.Size.Width, Cursor.Size.Height);
    Graphics g3 = Graphics.FromImage(bmp2);
    Rectangle rect2 = new Rectangle(new Point(0,0), 
    new Size(Cursor.Size.Width, Cursor.Size.Height));
    Cursor.Draw(g3,rect2);bmp2.Save("C:\\img.gif",ImageFormat.Gif);
    我还是不明白为什么系统自己不会搞错呢?我猜一定有一种完美解决该问题
    的方法,希望熟悉Window编程的高手解答!