C# 在工具提示和光标可见的情况下拍摄屏幕截图

C# 在工具提示和光标可见的情况下拍摄屏幕截图,c#,cursor,tooltip,screenshot,C#,Cursor,Tooltip,Screenshot,这是我用来截图的代码: [DllImport("gdi32.dll",EntryPoint="DeleteDC")] public static extern IntPtr DeleteDC(IntPtr hDc); [DllImport("gdi32.dll",EntryPoint="DeleteObject")] public static extern IntPtr DeleteObject(IntPtr hDc); [DllImport("gdi32.dll",EntryPoint=

这是我用来截图的代码:

[DllImport("gdi32.dll",EntryPoint="DeleteDC")]
public static extern IntPtr DeleteDC(IntPtr hDc);

[DllImport("gdi32.dll",EntryPoint="DeleteObject")]
public static extern IntPtr DeleteObject(IntPtr hDc);

[DllImport("gdi32.dll",EntryPoint="BitBlt")]
public static extern bool BitBlt(IntPtr hdcDest,int xDest,
    int yDest,int wDest,int hDest,IntPtr hdcSource,
    int xSrc,int ySrc,int RasterOp);

[DllImport ("gdi32.dll",EntryPoint="CreateCompatibleBitmap")]
public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc,
    int nWidth, int nHeight);

[DllImport ("gdi32.dll",EntryPoint="CreateCompatibleDC")]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);

[DllImport ("gdi32.dll",EntryPoint="SelectObject")]
public static extern IntPtr SelectObject(IntPtr hdc,IntPtr bmp);

[DllImport("user32.dll", EntryPoint="GetDesktopWindow")]
public static extern IntPtr GetDesktopWindow();

[DllImport("user32.dll",EntryPoint="GetDC")]
public static extern IntPtr GetDC(IntPtr ptr);

[DllImport("user32.dll",EntryPoint="GetSystemMetrics")]
public static extern int GetSystemMetrics(int abc);

[DllImport("user32.dll",EntryPoint="GetWindowDC")]
public static extern IntPtr GetWindowDC(Int32 ptr);

[DllImport("user32.dll",EntryPoint="ReleaseDC")]
public static extern IntPtr ReleaseDC(IntPtr hWnd,IntPtr hDc);

public static Bitmap GetDesktopImage()
{
    //In size variable we shall keep the size of the screen.
    SIZE size;          

    //Variable to keep the handle to bitmap.
    IntPtr hBitmap;

    //Here we get the handle to the desktop device context.
    IntPtr  hDC = GetDC(GetDesktopWindow());

    //Here we make a compatible device context in memory for screen
    //device context.
    IntPtr hMemDC = CreateCompatibleDC(hDC);

    //We pass SM_CXSCREEN constant to GetSystemMetrics to get the
    //X coordinates of the screen.
    size.cx = GetSystemMetrics(SM_CXSCREEN);

    //We pass SM_CYSCREEN constant to GetSystemMetrics to get the
    //Y coordinates of the screen.
    size.cy = GetSystemMetrics(SM_CYSCREEN);

    //We create a compatible bitmap of the screen size and using
    //the screen device context.
    hBitmap = CreateCompatibleBitmap
        (hDC, size.cx, size.cy);

    //As hBitmap is IntPtr, we cannot check it against null.
    //For this purpose, IntPtr.Zero is used.
    if (hBitmap!=IntPtr.Zero)
    {
        //Here we select the compatible bitmap in the memeory device
        //context and keep the refrence to the old bitmap.
        IntPtr hOld = (IntPtr)SelectObject
            (hMemDC, hBitmap);
        //We copy the Bitmap to the memory device context.
        BitBlt(hMemDC, 0, 0,size.cx,size.cy, hDC,0, 0,SRCCOPY);
        //We select the old bitmap back to the memory device context.
        SelectObject(hMemDC, hOld);
        //We delete the memory device context.
        DeleteDC(hMemDC);
        //We release the screen device context.
        ReleaseDC(GetDesktopWindow(), hDC);
        //Image is created by Image bitmap handle and stored in
        //local variable.

        Bitmap bmp = System.Drawing.Image.FromHbitmap(hBitmap); 
        //Release the memory to avoid memory leaks.
        DeleteObject(hBitmap);
        //This statement runs the garbage collector manually.
        GC.Collect();
        //Return the bitmap 
        return bmp;
    }
    //If hBitmap is null, retun null.
    return null;
}

它确实捕获了一个屏幕截图,但我想在截图中显示工具提示。要在工具提示和光标可见的情况下拍摄屏幕截图,我需要添加哪些内容?

Vista有一个剪贴工具,可以轻松地进行剪贴,如中所示

Silverlight还提供了一个应用程序:


我不知道剪贴工具的源代码是否可用。您可以尝试拍摄一段视频,然后对视频的一部分进行快照。

复制,似乎是同一个人使用两个不同的帐户询问!太神奇了…两个人在同一个代码上用同一个代码思考同一个问题…真是巧合-1问同一个问题两次,也问不同的用户帐户。@Naveen你应该投票,不管问题的内容如何,而不是基于用户的恶果。这就是标志的作用。我使用
WinSnap
实用程序,它通常工作得很好,特别是它处理圆角窗口,并且可以捕捉指定的一组窗口。但WinSnap不是免费的。有,但我不知道它在现代窗户上的效果如何。