VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Capturing the Screen

by TK (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (1 Votes)

Capture a screen in a window, this one actually works...

Inputs
'Inputs: None
Assumes
You need to create a form, add 2 menu items, item1 and item2, then add 2 picture boxs one named piccover and one named picfinal, make them the same size, and lay them right on top of each other... the size of them is the size of the screen captured... so if you want a 1024x768 screen captured be sure to size the picture boxes as big as you can.. The two menu items you can call whatever you like.. Capture screen for the first, and Clear window for the second if you like...
API Declarations
'Make these one line, this window isn't big enough
Private Declare Function GetDC% Lib "USER32" (ByVal HWnd%)
Private Declare Function ReleaseDC% Lib "USER32" (ByVal HWnd%, ByVal HDC%)
Private Declare Function GetDesktopWindow% Lib "USER32" ()
Private Declare Function BitBlt% Lib "GDI32" (ByVal DestDC%, ByVal X%, ByVal Y%, ByVal W%, ByVal H%, ByVal SrcHDC%, ByVal SrcX%, ByVal SrcY%, ByVal Rop&)
Private Declare Function DeleteDC Lib "GDI32" (ByVal HDC As Long) As Long
Const SRCCOPY = &HCC0020

Rate Capturing the Screen

Private Sub GrabScreen()
'I wont format this because this box doesn't allow tabbing, my apologies...  
PicFinal.Cls
DeleteDC (HwndSrc%)
HwndSrc% = GetDesktopWindow()
HSrcDC% = GetDC(HwndSrc%)
'BitBlt requires coordinates in pixels.
HDestDC% = PicFinal.HDC
DWRop& = SRCCOPY
Suc% = BitBlt(HDestDC%, 0, 0, 1024, 768, HSrcDC%, 0, 0, DWRop&)
Dmy% = ReleaseDC(HwndSrc%, HSrcDC%)
PicCover.Picture = PicFinal.Image
DeleteDC (HwndSrc%)
  
End Sub
Private Sub Item2_Click()
Capture.Hide
Capture.Visible = False
GrabScreen
Capture.Visible = True
End Sub
Private Sub Item3_Click()
Cls
PicFinal.Cls
PicCover.Cls
PicFinal.Refresh
PicCover.Refresh
DeleteDC (HwndSrc%)
End Sub

Download this snippet    Add to My Saved Code

Capturing the Screen Comments

No comments have been posted about Capturing the Screen. Why not be the first to post a comment about Capturing the Screen.

Post your comment

Subject:
Message:
0/1000 characters