Soyez le premier à donner votre avis sur cette source.
Vue 19 596 fois - Téléchargée 1 207 fois
'Device Context = "contexte de dispositif" selon le traducteur de google.fr 'Pour plus d'informations : 'http://msdn.microsoft.com/library/en-us/gdi/devcons_0g6r.asp?frame=true 'CLASSE VB.NET 2003 - 1.1 (et 2002? 1.0) Public Class ScreenShoter Private Declare Function BitBlt Lib "GDI32" (ByVal hDestDC As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As IntPtr, ByVal SrcX As Integer, ByVal SrcY As Integer, ByVal Rop As Integer) As Integer Private Declare Function GetForegroundWindow Lib "user32" () As IntPtr Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hWnd As IntPtr, ByRef lpRect As Rectangle) As Integer Private Declare Function GetDesktopWindow Lib "user32" () As IntPtr 'Capture tout l'écran Public Shared Function ShotScreen() As Bitmap Try Dim DesktopRect As Rectangle = Screen.GetBounds(New Point(0, 0)) 'obtient la taille du bureau sous forme de rectangle dans DesktopRect Return ShotScreenPart(DesktopRect.Width, DesktopRect.Height) 'appele la fonction ShotScreenPart avec les dimensions du bureau. Catch ex As Exception MsgBox(ex.ToString) Return emptybitmap() End Try End Function 'Capture la fenetre active Public Shared Function ShotActiveWin() As Bitmap Dim WinRect As Rectangle Try If (GetWindowRect(GetForegroundWindow, WinRect) > 0) Then 'obtient la taille et la position de la fenetre active sous forme de rectangle (WinRect) Return ShotScreenPart(WinRect.Size.Width - WinRect.Left, WinRect.Size.Height - WinRect.Top, WinRect.Left, WinRect.Top) 'appele la fonction ShotLoc avec les dimensions et la position de la fenetre. Else Return ShotScreen() End If Catch ex As Exception MsgBox(ex.ToString) Return emptybitmap() End Try End Function Public Shared Function ShotScreenPart(ByVal nwidth As Integer, ByVal nheight As Integer, Optional ByVal x As Integer = 0, Optional ByVal y As Integer = 0) As Bitmap Dim resultBmp As Bitmap = New Bitmap(nwidth, nheight) 'crée l'objet bitmap cible Dim SrcGraph As Graphics = Graphics.FromHwnd(GetDesktopWindow) 'crée l'objet "graphics" SelGraph a partir du handdle du bureau Dim BmpGraph As Graphics = Graphics.FromImage(resultBmp) 'crée un objet graphics à partir du bitmap Dim bmpDC As IntPtr = BmpGraph.GetHdc() 'obtient le device context du bitmap Dim hDC As IntPtr = SrcGraph.GetHdc() 'obtient le device context du bureau BitBlt(bmpDC, 0, 0, nwidth, nheight, hDC, x, y, &HCC0020) '"bit-block transfer" : copie chaque bits affichés dans le device context hDC dans le device context du bitmap SrcGraph.ReleaseHdc(hDC) 'relache le device context du bureau BmpGraph.ReleaseHdc(bmpDC) 'relache le device context du bitmap SrcGraph.Dispose() BmpGraph.Dispose() 'libere toutes les ressources crées par l'objet (useless?) Return resultBmp End Function Public Shared Function emptybitmap() As Bitmap Dim resultBmp As Bitmap = New Bitmap(1, 1) 'crée l'objet bitmap cible Return resultBmp End Function Public Shared Function TagShoot(ByVal curshot As Bitmap, ByVal tag As String, ByVal x As Single, ByVal y As Single, ByVal txtcolor As Color) As Bitmap Dim graph As Graphics = Graphics.FromImage(curshot) Dim drawFont As New Font("Arial", 16) Dim drawBrush As New SolidBrush(txtcolor) graph.DrawString(tag, drawFont, drawBrush, x, y) graph.Flush() Return curshot End Function End Class CLASSE VB.NET 2005 - 2.0 Public Class ScreenShoter2 Private Declare Function GetForegroundWindow Lib "user32" () As IntPtr Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hWnd As IntPtr, ByRef lpRect As Rectangle) As Integer 'Capture tout l'écran Public Shared Function ShotScreen() As Bitmap Try Dim DesktopRect As Rectangle = Screen.GetBounds(New Point(0, 0)) 'obtient la taille du bureau sous forme de rectangle dans DesktopRect Return ShotScreenPart(DesktopRect.Width, DesktopRect.Height) 'appele la fonction ShotScreenPart avec les dimensions du bureau. Catch ex As Exception Return emptybitmap() MsgBox(ex.ToString) End Try End Function 'Capture la fenetre active Public Shared Function ShotActiveWin() As Bitmap Dim WinRect As Rectangle Try If (GetWindowRect(GetForegroundWindow, WinRect) > 0) Then 'obtient la taille et la position de la fenetre active sous forme de rectangle (WinRect) Return ShotScreenPart(WinRect.Size.Width - WinRect.Left, WinRect.Size.Height - WinRect.Top, WinRect.Left, WinRect.Top) 'appele la fonction ShotLoc avec les dimensions et la position de la fenetre. Else Return ShotScreen() End If Catch ex As Exception MsgBox(ex.ToString) Return emptybitmap() End Try End Function Public Shared Function ShotScreenPart(ByVal nwidth As Integer, ByVal nheight As Integer, Optional ByVal x As Integer = 0, Optional ByVal y As Integer = 0) As Bitmap Dim resultBmp As Bitmap = New Bitmap(nwidth, nheight) Dim BmpGraph As Graphics = Graphics.FromImage(resultBmp) Dim screensize As Size = New Size(nwidth, nheight) BmpGraph.CopyFromScreen(x, y, 0, 0, screensize) BmpGraph.Dispose() Return resultBmp End Function Public Shared Function emptybitmap() As Bitmap Dim resultBmp As Bitmap = New Bitmap(1, 1) Return resultBmp End Function Public Shared Function TagShoot(ByVal curshot As Bitmap, ByVal tag As String, ByVal x As Single, ByVal y As Single, ByVal txtcolor As Color) As Bitmap Dim graph As Graphics = Graphics.FromImage(curshot) Dim drawFont As New Font("Arial", 16) Dim drawBrush As New SolidBrush(txtcolor) graph.DrawString(tag, drawFont, drawBrush, x, y) graph.Flush() Return curshot End Function End Class
23 mars 2005 à 16:47
Désolé de te dire ça mais aucun intérêt, autant rester sous vb6.
Lorsque tu développes en .NET, l'intérêt est d'utiliser le framework .net
23 mars 2005 à 17:39
Bitmap.FromHbitmap(New IntPtr(bmplng))
qui est bien un appel propre au framework.net (lis tout le code avant de critiquer).
Utiliser l'objet bitmap du framework permet d'acceder à la fonction FromHbitmap, mais aussi de convertir l'image en le format desiré!
On peut peut etre le modifier pour faire la meme chose en vb6, mais la n'etait pas mon but.
De plus, meme si le code marchait en vb6, pourquoi coder une classe en vb6 pour un projet en .net??
Non vraiment, ta critique est à revoir. See u
23 mars 2005 à 18:03
15 mai 2008 à 18:01
HVB, je te soutiens dans tes argumentations, d'ailleurs, ceux de OneHacker sont relativement court.
Il est vrai que faire 1000 screenshots en 1 seconde, ca ne doit pas être évident, mais les enregistrer dans 1000 fichiers différents sur le disque, ca doit être encore plus tendu ! A part peut-être sur le dernier Cray ? (lol)
Ceci dit, si ce que dit OneHacker est vrai, alors je suis également certain qu'il arrivera à faire un moteur de recherche mieux que Google... (Larry P. et Sergey B., cravachez dur, OneHacker arrive !!!)
30 sept. 2008 à 01:24
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.