Chụp ảnh màn hình bằng VB6

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 1

Chp nh mn hnh bng VB6

Hi: Em mun vit chng trnh theo di hot ng ca desktop bng cch chp mn hnh ri lu li. Ch trnh dng hm SendKeys nhn phm Print Screen nhng khng c.

tr li: Trong VB6, hm SendKeys cho php gi i mt phm ging nh khi ta nhn phm t bn phm, nhng hm ny khng nhn phm PrtSc (Print Screen). Bn phi dng hm API nhn phm PrtSc hoc Alt+PrtSc. Bn hy to mi mt project kiu Standard EXE. Trn form mc nh v mt PictureBox control c tn Picture1, mt Timer contr tn Timer1 vi thuc tnh Interval l 1000, ri g vo on m 1. Bn lu : nh c ghi ln a lun lun l nh chp c l nhn phm lin trc . on m 1 Option Explicit Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal _ bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long) Private Declare Function GetVersionExA Lib "kernel32" _ (lpVersionInformation As OSVERSIONINFO) As Integer Private Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 End Type Private Const KEYEVENTF_KEYUP = &H2 Private Const VK_SNAPSHOT = &H2C Private Const VK_MENU = &H12 Dim blnAboveVer4 As Boolean Private Sub Form_Load() Dim osinfo As OSVERSIONINFO Dim retvalue As Integer osinfo.dwOSVersionInfoSize = 148 osinfo.szCSDVersion = Space$(128) retvalue = GetVersionExA(osinfo) If osinfo.dwMajorVersion > 4 Then blnAboveVer4 = True Picture1.Visible = False End Sub Private Sub Timer1_Timer() Chp bng phm PrtSc If blnAboveVer4 Then keybd_event VK_SNAPSHOT, 0, 0, 0 Else keybd_event VK_SNAPSHOT, 1, 0, 0 End If Picture1.Picture = Clipboard.GetData(vbCFBitmap) DoEvents cho Picture1 nhn ht nh t clipboard If Picture1.Picture <> 0 Then SavePicture Picture1.Picture, "D:\Hinh.JPG" Lu nh ln a End If End Sub

You might also like