바탕화면의 이미지를 복사한 후, 그 위에 마우스 정보를 얻어 마우스 이미지를 그리는 방식이다.

초기 화면은 다음과 같다.


다음 이미지는 스샷하기 버튼을 눌러 마우스 커서를 포함한 스크린샷을 한 이미지다


다음은 소스이다.
' 마우스 커서를 포함한 스크린샷
Option Explicit

Private Type POINTAPI
    x As Long
    y As Long
End Type

Private Type ICONINFO
    fIcon As Long
    xHotspot As Long
    yHotspot As Long
    hbmMask As Long
    hbmColor As Long
End Type

Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
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 Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetIconInfo Lib "user32" (ByVal hIcon As Long, piconinfo As ICONINFO) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Const SRCCOPY = &HCC0020


Private Sub Command1_Click()
    Dim hdc As Long ' 바탕화면 DC 핸들
    Dim MPos As POINTAPI ' 마우스 좌표
    Dim hCursor As Long ' 마우스 커서 핸들
    Dim CursorInfo As ICONINFO ' 커서 정보
   
    With Me
        .AutoRedraw = True
        .ScaleMode = vbPixels
        hdc = GetDC(GetDesktopWindow())
        Call BitBlt(.hdc, 0, 0, .ScaleWidth, .ScaleHeight, hdc, 0, 0, SRCCOPY) ' 바탕화면 이미지를 DC에 복사한다.
        Call GetCursorPos(MPos)
        hCursor = GetCursor()
        Call GetIconInfo(hCursor, CursorInfo)
        DrawIcon .hdc, MPos.x - CursorInfo.xHotspot, MPos.y - CursorInfo.yHotspot, hCursor ' 마우스 커서를 DC에 그린다.
        .Refresh
        ReleaseDC GetDesktopWindow(), hdc
    End With
End Sub

+ Recent posts