好像vb实现起来比较繁琐?但想知道!谢谢

解决方案 »

  1.   

    MSDN中有现成的实例mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\98VS\2052\kb.chm::/Source/vbwin/q161299.htm
      

  2.   

    和我在老外网站上找到基本一样哦!哈哈但是……我想在鼠标移动到一个object上之后,点击鼠标才抓取。就是在抓取之前还不知道要抓的object到底是什么类型的,如何做?谢谢!
      

  3.   

    只需要知道鼠标下面窗体或控件的hwnd即可。
      

  4.   

    用getdc得到目标dc后
    然后用getbitblt api 就行
      

  5.   

    '----------------------------------------------------------------------------
    '
    'Author:lihonggen0
    'Date:2002-6-19
    '功能:抓屏
    '----------------------------------------------------------------------------
    Private Type POINTAPI
        x As Long
        y 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 GetDC Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) 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 ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As LongPrivate Sub Command1_Click()
        Dim hdc As Long
        Dim sw As Integer
        Dim sh As Integer
        Dim CurPos As POINTAPI
        Dim Cur As Long
        Me.Hide
        DoEvents
        Picture1.AutoRedraw = True
        hdc = GetDC(0)
        GetCursorPos CurPos
        Cur = GetCursor
        Picture1.Width = Screen.Width
        Picture1.Height = Screen.Height
        sw = Screen.Width / Screen.TwipsPerPixelX
        sh = Screen.Height / Screen.TwipsPerPixelY
        BitBlt Picture1.hdc, 0, 0, sw, sh, hdc, 0, 0, vbSrcCopy
        Me.Show
        DrawIcon Picture1.hdc, CurPos.x - 10, CurPos.y - 10, Cur
        ReleaseDC 0, hdc
        Picture1.AutoRedraw = FalseEnd Sub
      

  6.   

    得到单击的句柄,那么你就可以用GetDC(hwnd),然后再bitblt就可以了。
      

  7.   

    获当前活动窗口,模块:
    Option ExplicitType RECT_Type   left As Long
       top As Long
       right As Long
       bottom As LongEnd Type'The following declare statements are case sensitive.Declare Function GetActiveWindow Lib "User32" () As Long
    Declare Function GetDesktopWindow Lib "User32" () As Long
    Declare Sub GetWindowRect Lib "User32" (ByVal Hwnd As Long, _
                                        lpRect As RECT_Type)
    Declare Function GetDC Lib "User32" (ByVal Hwnd As Long) As Long
    Declare Function CreateCompatibleDC Lib "Gdi32" (ByVal hdc As Long) _
                                        As Long
    Declare Function CreateCompatibleBitmap Lib "Gdi32" (ByVal hdc _
                                        As Long, ByVal nWidth As Long, _
                                        ByVal nHeight As Long) As Long
    Declare Function SelectObject Lib "Gdi32" (ByVal hdc As Long, _
                                        ByVal hObject As Long) As Long
    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
    Declare Function OpenClipboard Lib "User32" (ByVal Hwnd As Long) As Long
    Declare Function EmptyClipboard Lib "User32" () As Long
    Declare Function SetClipboardData Lib "User32" (ByVal wFormat As Long, _
                                        ByVal hMem As Long) As Long
    Declare Function CloseClipboard Lib "User32" () As Long
    Declare Function ReleaseDC Lib "User32" (ByVal Hwnd As Long, _
                                        ByVal hdc As Long) As Long
    Declare Function DeleteDC Lib "Gdi32" (ByVal hdc As Long) As LongGlobal Const SRCCOPY = &HCC0020
    Global Const CF_BITMAP = 2
                    
    Function ScreenDump()
       Dim AccessHwnd As Long, DeskHwnd As Long
       Dim hdc As Long
       Dim hdcMem As Long
       Dim rect As RECT_Type
       Dim junk As Long
       Dim fwidth As Long, fheight As Long
       Dim hBitmap As Long  ' DoCmd.Hourglass True   '---------------------------------------------------
       ' Get window handle to Windows and Microsoft Access
       '---------------------------------------------------
       DeskHwnd = GetDesktopWindow()
       AccessHwnd = GetActiveWindow()   '---------------------------------------------------
       ' Get screen coordinates of Microsoft Access
       '---------------------------------------------------
       Call GetWindowRect(AccessHwnd, rect)
       fwidth = rect.right - rect.left
       fheight = rect.bottom - rect.top   '---------------------------------------------------
       ' Get the device context of Desktop and allocate memory
       '---------------------------------------------------
       hdc = GetDC(DeskHwnd)
       hdcMem = CreateCompatibleDC(hdc)
       hBitmap = CreateCompatibleBitmap(hdc, fwidth, fheight)   If hBitmap <> 0 Then
          junk = SelectObject(hdcMem, hBitmap)      '---------------------------------------------
          ' Copy the Desktop bitmap to memory location
          ' based on Microsoft Access coordinates.
          '---------------------------------------------
          junk = BitBlt(hdcMem, 0, 0, fwidth, fheight, hdc, rect.left, _
                        rect.top, SRCCOPY)      '---------------------------------------------
          ' Set up the Clipboard and copy bitmap
          '---------------------------------------------
          junk = OpenClipboard(DeskHwnd)
          junk = EmptyClipboard()
          junk = SetClipboardData(CF_BITMAP, hBitmap)
          junk = CloseClipboard()
       End If   '---------------------------------------------
       ' Clean up handles
       '---------------------------------------------
       junk = DeleteDC(hdcMem)
       junk = ReleaseDC(DeskHwnd, hdc) '  DoCmd.Hourglass FalseEnd Function窗体调用ScreenDump,将抓的图放入Clipboard()
    然后在画图中粘贴一下