Link to home
Start Free TrialLog in
Avatar of short_fat_n_black
short_fat_n_black

asked on

print screen

how do you make a program that automatically prints the screen(copies it to the clipboard) then pastes it into an image box?
Avatar of hes
hes
Flag of United States of America image

If you want the code to do a print screen, capture just the form, just the client area of the form let me know and I will post it.
Avatar of JanusFury
JanusFury

Here's something off the top of my head: (It'll require some API declarations from the API viewer.)

deskWnd = GetDesktopWindow
deskDC = GetDC(deskWnd)
BitBlt Picture1.hDC, 0, 0, Screen.Width \ Screen.TwipsPerPixelX, Screen.Height \ TwipsPerPixelY, deskDC, 0, 0, vbSrcCopy
ReleaseDC deskWnd, deskDC
deskDC = 0
deskWnd = 0

I'll make a full ver of the code when I get home.
<ping>
a ping from wsh2, havn't seen you on lately (until this week) :)
ASKER CERTIFIED SOLUTION
Avatar of glass_cookie
glass_cookie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi short_fat_n_black ,
   
To mimic the printscreen / take a snapshot of desktop:

http://www.mvps.org/vbnet/code/bitmap/printscreen.htm 

Here is another version that Calling the Windows PrintScreen Function Using keybd_event:

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 Const TheScreen = 0
Private Const TheForm = 1

Private Sub Command1_Click()
 'call the Windows keybd_event sub, passing the built-in
 'VB keyboard constant vbKeySnapshot (44) to the sub.

 'The four parameters for keybd_event are:
 'BYTE bVk           'virtual-key code
 'BYTE bScan         'hardware scan code
 'DWORD dwFlags      'flags specifying various function options
 'DWORD dwExtraInfo  'additional data associated with keystroke

 'The bScan parameter value determines what
 'to copy... passing 0 (TheScreen) copies
 'the screen, passing 1 (TheForm) copies the
 'active form.
  keybd_event vbKeySnapshot, TheForm, 0&, 0&
 
 'pause to let Windows update the clipboard
  DoEvents
 
 'retrieve the clipboard bitmap to the control (vbCFBitmap = 2)
  Image1.Picture = Clipboard.GetData(vbCFBitmap)

End Sub


Original Source: http://www.mvps.org/vbnet/code/bitmap/printscreenapi.htm

'Hope will help.