2009-02-26 21 views
-5

これは、私は、スクリーンショットを取るために使用していたコードです:ツールチップとカーソルでスクリーンショットを撮る見える

[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; 
} 

それはスクリーンショットをキャプチャんが、私は目に見えるツールチップでスクリーンショットを撮りたいです。ツールチップとカーソルを表示してスクリーンショットを撮るために追加する必要があるものは何ですか?

+0

重複:http://stackoverflow.com/questions/584963/tool-tipscreen-shot and http://stackoverflow.com/questions/589151/taking-screenshots – Jared

+1

同じ人が2つの異なるアカウントを使用しているように思えます。 – Cerebrus

+1

驚くべきこと... 2人の人が同じコードで同じコードを使って同じ問題を考えています...同じ偶然です。-1同じ質問を2回、別のユーザーアカウントでも聞いています。 – Naveen

答えて

3

Vistaには、http://blog.falafel.com/2008/08/12/CaptureScreenShotsWithToolTipsAndPopupsUsingVistaSnippingTool.aspxに記載されているように簡単にスニッフィングツールがあります。

のSilverlightを介してアプリケーションもあります:http://blogs.msdn.com/swick/archive/2007/12/18/snipping-pictures-with-silverlight.aspx

ソースコードをつむツールのために利用可能である場合、私は知りません。ビデオを撮ってから、ビデオの一部のスナップショットを撮ることができますas shown here

+0

私は 'WinSnap'ユーティリティを使用します。これは一般的にはうまくいきます。特に、丸いウィンドウコーナーを扱い、指定されたウィンドウセットをスナップすることができます。しかし、WinSnapは**無料ではありません**。 [無料の古いバージョン](http://www.ntwind.com/software/winsnap/download-free-version.html)がありますが、現代のWindows上でどれくらいうまく動作しているか分かりません。 –

関連する問題