Last Updated 2006/02/02
Programming Tips Visual Basic 印刷  索 引 
画面をクリップボードにコピー
2006/02/02

画面全体をクリップボードにコピーする.


画面全体をコピーするには画面のデバイスコンテキストを取得する.

Dim hScreenDC As Long
hScreenDC = CreateDC("DISPLAY", ByVal 0&, ByVal 0&, ByVal 0&, ByVal 0&)


画面の大きさを取得する.
Type Rect
    top    As Long
    left   As Long
    right  As Long
    bottom As Long
End Type

Dim rcWindow As Rect
GetWindowRect GetDesktopWindow(), rcWindow


クリップボードにコピーするには,メモリデバイスコンテキストとビットマップを作成する.

hMemoryDC As Long
hBitmap As Long

hMemoryDC = CreateCompatibleDC(hScreenDC)
hBitmap = CreateCompatibleBitmap(hScreenDC, rcWindow.right - rcWindow.left, _
                                 rcWindow.bottom - rcWindow.top)


ビットマップをデバイスコンテキストに選択して画面イメージを転送する.

If hBitmap Then
    SelectObject hMemoryDC, hBitmap
    BitBlt hMemoryDC,0,0, _
           rcWindow.right - rcWindow.left, _
           rcWindow.bottom - rcWindow.top, _
           hScreenDC, 0, 0, SRCCOPY

    クリップボードに転送
    OpenClipBoard GetDesktopWindow()
    EmptyClipboard
    SetClipboardData CF_BITMAP, hBitmap
    CloseClipboard
End if


デバイスコンテキストの後始末.

DeleteDC hMemoryDC
DeleteDC hScreenDC


参照
ハードコピー
前後のTips
画面をクリップボードにコピー

DSS ProgrammingTipsCGI Ver2.02