I've made a small tutorial on how to make a ScreenCap Application
You need:
- A button
![[Image: screenshot.34.png]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_tm7eYGCoQDN-hBuPnrt75n5K1rjfUvU6AtoS51QI-yVlT36QEGUhs8UAVF2YV4ZlFyhVOyehyoDxSbq3TOnW7qdLrp99mWGdGBDfgeqDvdeeOjER86=s0-d)
Start a new project and add this under "Public Class Form1"
Now add this sub anywhere to your project, just make sure it's not in another sub.
And if you want Button1 to capture the screen and save it to C:/picture.jpg you would do this
![[Image: screenshot.37.png]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_t72Ko2TaH3u2KxVU_mB2MchU0NPH7xsI1q9gtVzUokfp1OUZ3EXW5ME12FM6-ZHxFILT1nk1aYtQWYSJfW-ibIoQKOv7_oq0I5mEVk4TSGxx8Bza7M=s0-d)
Download source
You need:
- A button
Start a new project and add this under "Public Class Form1"
Code:
Inherits System.Windows.Forms.Form
Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As String) As Integer
Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
Private Declare Function GetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps" (ByVal hdc As Integer, ByVal nIndex As Integer) As Integer
Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer, ByVal hObject As Integer) As Integer
Private Declare Function BitBlt Lib "GDI32" (ByVal srchDC As Integer, ByVal srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH As Integer, ByVal desthDC As Integer, ByVal destX As Integer, ByVal destY As Integer, ByVal op As Integer) As Integer
Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As Integer) As Integer
Const SRCCOPY As Integer = &HCC0020
Private oBackground As Bitmap
Private FW, FH As IntegerNow add this sub anywhere to your project, just make sure it's not in another sub.
Code:
Protected Sub CaptureScreen()
Dim hSDC, hMDC As Integer
Dim hBMP, hBMPOld As Integer
Dim r As Integer
hSDC = CreateDC("DISPLAY", "", "", "")
hMDC = CreateCompatibleDC(hSDC)
FW = GetDeviceCaps(hSDC, 8)
FH = GetDeviceCaps(hSDC, 10)
hBMP = CreateCompatibleBitmap(hSDC, FW, FH)
hBMPOld = SelectObject(hMDC, hBMP)
r = BitBlt(hMDC, 0, 0, FW, FH, hSDC, 0, 0, 13369376)
hBMP = SelectObject(hMDC, hBMPOld)
r = DeleteDC(hSDC)
r = DeleteDC(hMDC)
oBackground = Image.FromHbitmap(New IntPtr(hBMP))
DeleteObject(hBMP)
End SubAnd if you want Button1 to capture the screen and save it to C:/picture.jpg you would do this
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CaptureScreen()
oBackground.save("C:/picture.jpg")
End SubDownload source


12:22 AM
Unknown
Posted in: 
0 comments:
Post a Comment