Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,454 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,977 people online right now. Registration is fast and FREE... Join Now!




Screenshot Program

 
Reply to this topicStart new topic

Screenshot Program

NIXZ
10 Aug, 2008 - 12:49 AM
Post #1

D.I.C Head
**

Joined: 26 Jul, 2008
Posts: 87

Hey does anyone knows the source code for a "take a screenshot of my desktop" program ???
I ve searched on the internet and found one that take the screenshot
of the desktop but only the walllpaper not the windows (useless)
Here's the source code:
(theres a lot of variables and methods not declared,not defined)PLZ HELP!!!
CODE

Public Function GetWindowScreenshot(WndHandle As Long, SavePath As String, Optional BringFront As Integer = 1) As Long
'
' Function to create screeenshot of specified window and store at specified path
'
    On Error GoTo ErrorHandler

    Dim hDCSrc As Long
    Dim hDCMemory As Long
    Dim hBmp As Long
    Dim hBmpPrev As Long
    Dim WidthSrc As Long
    Dim HeightSrc As Long
    Dim Pic As PicBmp
    Dim IPic As IPicture
    Dim IID_IDispatch As guid
    Dim rc As RECT
    Dim pictr As PictureBox
    
    
    'Bring window on top of all windows if specified
    If BringFront = 1 Then BringWindowToTop WndHandle
    
    'Get Window Size
    GetWindowRect WndHandle, rc
    WidthSrc = rc.Right - rc.Left
    HeightSrc = rc.Bottom - rc.Top
    
    'Get Window  device context
    hDCSrc = GetWindowDC(WndHandle)
    
    'create a memory device context
    hDCMemory = CreateCompatibleDC(hDCSrc)
    
    'create a bitmap compatible with window hdc
    hBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc)
    
    'copy newly created bitmap into memory device context
    hBmpPrev = SelectObject(hDCMemory, hBmp)
    
    
    'copy window window hdc to memory hdc
    Call BitBlt(hDCMemory, 0, 0, WidthSrc, HeightSrc, _
                hDCSrc, 0, 0, vbSrcCopy)
      
    'Get Bmp from memory Dc
    hBmp = SelectObject(hDCMemory, hBmpPrev)
    
    'release the created objects and free memory
    Call DeleteDC(hDCMemory)
    Call ReleaseDC(WndHandle, hDCSrc)
    
    'fill in OLE IDispatch Interface ID
    With IID_IDispatch
       .data1 = &H20400
       .data4(0) = &HC0
       .data4(7) = &H46
     End With
    
    'fill Pic with necessary parts
    With Pic
       .Size = Len(Pic)         'Length of structure
       .Type = vbPicTypeBitmap  'Type of Picture (bitmap)
       .hBmp = hBmp             'Handle to bitmap
       .hPal = 0&               'Handle to palette (may be null)
     End With
    
    'create OLE Picture object
    Call OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)
    
    'return the new Picture object
    SavePicture IPic, SavePath
    GetWindowScreenshot = 1
    Exit Function
    
ErrorHandler:
    GetWindowScreenshot = 0
End Function



I Have found the program's source code (that takes a screenshot windows included) but i accidentally deleted my external hard drive 120GB full Games and programs (why there's no crying emoticon? icon_down.gif it says Error on Page) to install the operating system... blink.gif crazy.gif

EDIT: I dont know if its Visual Basic or VB.NET (actually i dont know whats the difference...)

EDIT2: CAN YOU PLZ DO THAT IN VBS (Visual Basic Script) ???[u]

This post has been edited by NIXZ: 10 Aug, 2008 - 01:06 AM
User is offlineProfile CardPM
+Quote Post

NIXZ
RE: Screenshot Program
10 Aug, 2008 - 01:46 PM
Post #2

D.I.C Head
**

Joined: 26 Jul, 2008
Posts: 87

Anyone???
User is offlineProfile CardPM
+Quote Post

dineeshd
RE: Screenshot Program
11 Aug, 2008 - 04:04 AM
Post #3

D.I.C Addict
Group Icon

Joined: 30 Jun, 2008
Posts: 578



Thanked: 16 times
Dream Kudos: 575
My Contributions
Refer below article, may be you get some help out of it... rolleyes.gif
ScreenShot of Desktop

User is offlineProfile CardPM
+Quote Post

AdamSpeight2008
RE: Screenshot Program
11 Aug, 2008 - 06:31 AM
Post #4

LINQ D.I.C.
Group Icon

Joined: 29 May, 2008
Posts: 799



Thanked: 51 times
Dream Kudos: 2175
My Contributions
Have you also thought of using sendkeys with the Print Screen button.
The you then have it on the clipboard.
User is offlineProfile CardPM
+Quote Post

cmount
RE: Screenshot Program
13 Aug, 2008 - 10:03 AM
Post #5

New D.I.C Head
*

Joined: 1 Aug, 2008
Posts: 41



Thanked: 1 times
My Contributions
QUOTE(AdamSpeight2008 @ 11 Aug, 2008 - 07:31 AM) *

Have you also thought of using sendkeys with the Print Screen button.
The you then have it on the clipboard.


I think this solution makes a whole lot of sense. I don't know if VB has a way to make a program start up & do something completely hidden, but it might work to have it start up microsoft paint, paste the input from the PrintScreen button, & save it as a jpeg with file name probably based on date & time file was created. Then have it close out of microsoft paint.


User is offlineProfile CardPM
+Quote Post

Zhalix
RE: Screenshot Program
14 Aug, 2008 - 12:43 PM
Post #6

D.I.C Head
**

Joined: 7 May, 2008
Posts: 218



Thanked: 9 times
My Contributions
I think that SendKeys doesn't work for Print Screen. Though the answer to your problem is really quite simple, and if you're still interested in doing this and haven't already found an easy way, this is it.

Before any code, make a picturebox and set it to your current resolution size. Set your scalemode on both the form and the picturebox to pixels. If you plan to use this on different computers, it's better to use code in the Form Load event to ensure the size of the picturebox is the size of the resolution on different computers who may have different resolutions. Turn off it's border, and set it's AutoRedraw property to true.

To set the picturebox to the appropriate size through code, use these calculations:
CODE
picScreenshot.Width = Screen.Width / Screen.TwipsPerPixelX
picScreenshot.Height = Screen.Height / Screen.TwipsPerPixelY


Your two API calls:
CODE
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long


The first one will be used to get the screen's device context, which is the space in memory that holds all the pixels for the screen.

The second one will be used to draw that device context onto a picturebox, which you will then save the picture it contains onto your computer.

CODE
Dim lngScreen As Long
    
lngScreen = GetWindowDC(0)
    
BitBlt picScreenshot.hDC, 0, 0, Screen.Width / Screen.TwipsPerPixelX, Screen.Height / Screen.TwipsPerPixelY, lngScreen, 0, 0, vbSrcCopy

SavePicture picScreenshot.Image, "C:\Screenshot.bmp"


You declare a variable to hold the handle of the device context. You then use BitBlt to draw onto your Picturebox the picture. The calculation 'Screen.Width / Screen.TwipsPerPixelX' is used to determine the resolution of the computer screen and should be left as is, unless you'll only be using it on your own computer. You use the SavePicture function to save the image to your computer as "Screenshot.bmp".

*EDIT*

Now, say you wanted to save it just to your clipboard instead of making a bitmap file. Just use this code instead of the SavePicture function:

CODE
Clipboard.Clear
Clipboard.SetData picScreenshot.Image


This post has been edited by Zhalix: 14 Aug, 2008 - 10:41 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 03:14PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month