想在一个FORM里画一个PICTRUEBOX控件,然后把被PICTRUEBOX遮住的FORM上的图像截出来再贴到PICTRUEBOX上,需要说明的是FORM上是没有贴位图的,我说的被遮住的图像是指FORM及其上的一些控件显示的出来的内容,(不知道我这样说得清楚不,汗!!!)。贴图我想用PICTRUEBOX的Paintpicture应该可以做,但我不知道怎么能获得被遮住部分的截图,在此诚心求教!

解决方案 »

  1.   

    ''使用下面代码中的函数:hDCToPicture,其返回值直接赋给picture的picture属性就行
    Private Type GUID
        Data1 As Long
        Data2 As Integer
        Data3 As Integer
        Data4(7) As Byte
    End Type
    Private Type PicBmp
        SIZE As Long
        Type As Long
        hBmp As Long
        hPal As Long
        Reserved As Long
    End Type'API函数声明
    Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
    Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long
    Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hDC As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
    Private Declare Function StretchBlt Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hhdc As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
    Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
    Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long
    Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Longprivate mhBmp As LongPrivate Function hDCToPicture(ByVal hDCSrc As Long, ByVal LeftSrc As Long, ByVal TopSrc As Long, ByVal WidthSrc As Long, ByVal HeightSrc As Long) As Picture
        '要确保参数LeftSrc、TopSrc、WidthSrc、HeightSrc的单位为像素!!
        
        Dim hDCMemory As Long
        Dim hPal      As Long
        Dim Pic       As PicBmp
        Dim IPic      As IPicture
        Dim IID_IDispatch As GUID
        
        hDCMemory = CreateCompatibleDC(hDCSrc)
        
        If mhBmp <> 0 Then DeleteObject mhBmp    mhBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc)
        DeleteObject SelectObject(hDCMemory, mhBmp)    'Copy the source image to our compatible device context
        StretchBlt hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, LeftSrc, TopSrc,    
           WidthSrc, HeightSrc, vbSrcCopy    With IID_IDispatch
            .Data1 = &H20400
            .Data4(0) = &HC0
            .Data4(7) = &H46
        End With    'Fill picture info
        With Pic
            .SIZE = Len(Pic)         ' Length of structure
            .Type = vbPicTypeBitmap  ' Type of Picture (bitmap)
            .hBmp = mhBmp             ' Handle to bitmap
            .hPal = 0
        End With    'Create the picture
        OleCreatePictureIndirect Pic, IID_IDispatch, 1, IPic    DeleteDC hDCMemory
        
        Set hDCToPicture = IPic
    End Function
      

  2.   

    不能移动窗口,我在里面用了timer
    但是老是把自己的边框给截图了