Utilisation API GetDC

Résolu
jpmaton Messages postés 67 Date d'inscription mardi 17 mai 2005 Statut Membre Dernière intervention 26 septembre 2023 - 29 mai 2010 à 10:23
jpmaton Messages postés 67 Date d'inscription mardi 17 mai 2005 Statut Membre Dernière intervention 26 septembre 2023 - 29 mai 2010 à 16:21
Bonjour,
Je capte une partie d'écran avec l'API GetDC.
La capture est bien envoyée vers la pictureBox picture1.
Mais si je sauve, le fichier BMP est vide
De même que si j'imprime avec "Printer.PaintPicture Picture1.Image, 0, 0" j'ai une page vide aussi.
Il doit me manquer une étape...
Merci de l'aide et bon WE
Jean-paul

' Boutons : Command1 et Picture1
' Code Form1
Private Sub Command1_Click()
Dim x As Integer, y As Integer, nWidth As Integer, nHeight As Integer
Dim dwRop As Long, hSrcDC As Long, hDestDC As Long

Let nWidth = 500 ' largeur capture
Let nHeight = 300 ' hauteur capture
Let xSrc = 0 ' marge gauche non captée
Let ySrc = 0 ' marge haute non captée
Let x = 0 ' marge G dans picturebox ou form
Let y = 0 ' marge Haute dans pictureBox ou form

Let dwRop = SRCCOPY
Let hDestDC = Picture1.hdc
Let hSrcDC = GetDC(0)
Call BitBlt(hDestDC, x, y, nWidth, nHeight, hSrcDC, xSrc, ySrc, dwRop)
Call ReleaseDC(0, hSrcDC)
SavePicture Picture1.Image, App.Path & "\test.bmp"
End Sub

' Module1
Public Const SRCCOPY = &HCC0020
Public Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Public 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
Public Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hdc As Long) As Long

2 réponses

Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
29 mai 2010 à 15:05
viens de ton AutoRedraw, a mettre a true

Renfield - Admin CodeS-SourceS - MVP Visual Basic & Spécialiste des RegExp
3
jpmaton Messages postés 67 Date d'inscription mardi 17 mai 2005 Statut Membre Dernière intervention 26 septembre 2023 3
29 mai 2010 à 16:21
C'est si simple ainsi
Grand merci

Jean-paul
0
Rejoignez-nous