|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Visual Basic Bitmap Routines keybd_event: Calling Windows' PrintScreen Function |
||
Posted: | Thursday December 26, 1996 | |
Updated: | Monday December 26, 2011 | |
Applies to: | VB4-32, VB5, VB6 | |
Developed with: | VB4-32, Windows 95 | |
OS restrictions: | None | |
Author: | John Weinhold, VBnet - Randy Birch | |
Related: |
BitBlt: Mimicking the PrintScreen Function BitBlt: Mimicking PrintScreen to Create a 'PrintForm' CreateEnhMetaFile: Saving a PrintScreen as a Windows Enhanced Metafile InflateRect: Highlighting External Windows keybd_event: Calling Windows' PrintScreen Function OleCreatePictureIndirect: Mimicking PrintScreen Using OLE |
|
Prerequisites |
None. |
|
The following code will copy the contents of the desktop
(the screen) into a Picture Box or image control on a form. Unlike the examples listed at the top of this page, this method uses the Windows API to actually PrintScreen to the clipboard first, and then retrieve that bitmap into the image control. |
BAS Module Code |
None. |
|
Form Code |
To the form, add the following code: |
|
Option Explicit '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved. ' Some pages may also contain other copyrights by the author. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Distribution: You can freely use this code in your own ' applications, but you may not reproduce ' or publish this code on any web site, ' online service, or distribute as source ' on any media without express permission. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Declare Sub keybd_event Lib "user32" _ (ByVal bVk As Byte, _ ByVal bScan As Byte, _ ByVal dwFlags As Long, _ ByVal dwExtraInfo As Long) 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 second parameter (bScan) determines what 'to copy... passing 0& copies the screen or 'passing 1& copies the active form. keybd_event vbKeySnapshot, 0&, 0&, 0& 'pause to let Windows update the clipboard DoEvents 'retrieve the clipboard bitmap to the control Image1.Picture = Clipboard.GetData(vbCFBitmap) End Sub |
Comments |
|
|
|
|||||
|
|||||
|
|||||
Copyright ©1996-2011 VBnet and Randy Birch. All Rights Reserved. |