hvb
Messages postés
939
Date d'inscription
vendredi 25 octobre 2002
Statut
Membre
Dernière intervention
27 janvier 2009
3
16 mars 2007 à 12:08
et il reste 2 avertissements dans la classe, que j'ai modifié pour y paliere (je l'avais fait en vb2005 mais pas en vb2003) :
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 ExceptionMsgBox(ex.ToString)
Return
New Bitmap(1, 1)
End
Try
End
Function
'Capture la fenetre active
Public
Shared
Function ShotActiveWin()
As Bitmap
Dim WinRect
As Rectangle
Try
If GetWindowRect(GetForegroundWindow, WinRect)
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
New Bitmap(1, 1)
End
If
Catch ex
As ExceptionMsgBox(ex.ToString)
Return
New Bitmap(1, 1)
End
Try
End
Function
'Capture une partie de l'ecran, defini par les deux variable width et height (dimensions du rectangle), et des valeur optionels X et Y (base du rectangle)
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 bureauBitBlt(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 bureauBmpGraph.ReleaseHdc(bmpDC)
'relache le device context du bitmapSrcGraph.Dispose()
BmpGraph.Dispose()
'libere toutes les ressources crées par l'objet (useless?)
Return resultBmp
End
FunctionEnd
Class
Hvb aka Batto
bato.ltd at gmail.com