cs_candyraton
Messages postés
109
Date d'inscription
dimanche 27 juillet 2008
Statut
Membre
Dernière intervention
2 février 2012
3
30 nov. 2008 à 13:28
Bonjour pcpt
multiuse
notaamtsobject
notpersistable
'j'appelle dans une longue procédure:
r = GetWindowRect(hWndActive, RectActive)
Frm_invisible.Pictemp.Top = 0 'RectActive.Top
Frm_invisible.Pictemp.Left = 0 'RectActive.Left
Frm_invisible.Pictemp.Height = RectActive.Bottom - RectActive.Top
Frm_invisible.Pictemp.Width = RectActive.Right - RectActive.Left
Wait 0.5
'je' capture dans pictemp
Set Frm_invisible.Pictemp.Picture = CaptureWindow(hWndActive, False, 0, 0, _
RectActive.Right - RectActive.Left, RectActive.Bottom - RectActive.Top)
(ça marche tres bien dans un module)
'ca passe par une autre class pour "conserver l'intégrité de chaque instances"
Public Function CaptureWindow(ByVal hWndSrc As Long, _
ByVal Client As Boolean, ByVal LeftSrc As Long, _
ByVal TopSrc As Long, ByVal WidthSrc As Long, _
ByVal HeightSrc As Long) As Object ' Picture
Dim interfacedll6 As Object
Dim serveurdll6 As Object
On Error GoTo Error
Set interfacedll6 = CreateObject("madll.ServerInterface")
Set serveurdll6 = interfacedll6.objGetClassInstance("cls_outils")
CaptureWindow = serveurdll6.CaptureWindow(hWndSrc, Client, LeftSrc, TopSrc, WidthSrc, HeightSrc)
Set serveurdll6 = Nothing
Set interfacedll6 = Nothing
Exit Function
Error:
Set serveurdll6 = Nothing
Set interfacedll6 = Nothing
Err.Clear
End Function
dans la dll (ou dans un module (marche)
Public Function CaptureWindow(ByVal hWndSrc As Long, _
ByVal Client As Boolean, ByVal LeftSrc As Long, _
ByVal TopSrc As Long, ByVal WidthSrc As Long, _
ByVal HeightSrc As Long) As Object 'Picture
Dim hDCMemory As Long
Dim hBmp As Long
Dim hBmpPrev As Long
Dim r As Long
Dim hDCSrc As Long
Dim hPal As Long
Dim hPalPrev As Long
Dim RasterCapsScrn As Long
Dim HasPaletteScrn As Long
Dim PaletteSizeScrn As Long
Dim LogPal As LOGPALETTE
'On Error GoTo Err23
' traitement du device context
If Client Then
hDCSrc = GetDC(hWndSrc) ' device context pour la zone client
Else
hDCSrc = GetWindowDC(hWndSrc) ' device context pour la fenetre entiere
End If
' créer un memory device context pour la copie
hDCMemory = CreateCompatibleDC(hDCSrc)
' créer une bitmap et la mettre dans le memory DC
hBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc)
hBmpPrev = SelectObject(hDCMemory, hBmp)
' capturer les propriétés de l'ecran
RasterCapsScrn = GetDeviceCaps(hDCSrc, RASTERCAPS)
HasPaletteScrn = RasterCapsScrn And RC_PALETTE
PaletteSizeScrn = GetDeviceCaps(hDCSrc, SIZEPALETTE)
' si l'ecran a une palette faire une copie et la liberer
If HasPaletteScrn And (PaletteSizeScrn = 256) Then
' faire une copie de la palette
LogPal.palVersion = &H300
LogPal.palNumEntries = 256
r = GetSystemPaletteEntries(hDCSrc, 0, 256, _
LogPal.palPalEntry(0))
hPal = CreatePalette(LogPal)
' liberer la palette
hPalPrev = SelectPalette(hDCMemory, hPal, 0)
r = RealizePalette(hDCMemory)
End If
' copier l'image de l'ecran dans le memory DC
r = BitBlt(hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, _
LeftSrc, TopSrc, vbSrcCopy)
hBmp = SelectObject(hDCMemory, hBmpPrev)
' si l'ecran avait une palette la restaurer
If HasPaletteScrn And (PaletteSizeScrn = 256) Then
hPal = SelectPalette(hDCMemory, hPalPrev, 0)
End If
' liberer le device context
r = DeleteDC(hDCMemory)
r = ReleaseDC(hWndSrc, hDCSrc)
' appeler CreateBitmapPicturepour creer un objet image à partir des handles
' bitmap et palette et retourner l'objet picture
Set CaptureWindow = CreateBitmapPicture(hBmp, hPal)
Exit Function
'Err23:
'err.Clear
End Function
' CreateBitmapPicture
' - Créer un objet bitmap depuis une image bitmap et une palette
' hBmp
' - Handle d'une bitmap
' hPal
' - Handle d'une Palette
' - Peut être null si la bitmap n'utilise pas de palette
' Resultat
' - Un objet picture qui comtient la bitmap
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
Public Function CreateBitmapPicture(ByVal hBmp As Long, _
ByVal hPal As Long) As Object 'Picture
Dim r As Long
Dim Pic As PicBmp
' IPicture a besoin d'une reference a un "Standard OLE Types"
Dim IPic As IPicture
Dim IID_IDispatch As GUID
'On Error GoTo Err24
' Renseigner le ID de l'Interface IDispatch
With IID_IDispatch
.Data1 = &H20400
.Data4(0) = &HC0
.Data4(7) = &H46
End With
' Renseigner Pic
With Pic
.Size = Len(Pic) ' longueur de la structure
.Type = vbPicTypeBitmap ' Type de Picture (bitmap)
.hBmp = hBmp ' Handle du bitmap
.hPal = hPal ' Handle de la palette (peut êtrenull)
End With
' créer un Picture object
r = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)
' retourner un nouveau objet Picture
Set CreateBitmapPicture = IPic
Exit Function
'Err24:
'err.Clear
End Function
nota: toutes les autres fonctions de la dll fonctionnent avec ce systeme d'interface (j'aimerais avoir ton opinion)
les types (Instancing, MTSTransactionMode et Persistable) sont les même pour les 2 class.
J'espére que tu vas pouvoir m'aider sans trop te casser la tete
tout le code est a ta disposition.
a+