473,327 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Screen capture?

Under VB6, it was fairly straightforward to get a
screenshot. For instance, the following code:

Public Function ScreenshotBits(hWnd As Long, Optional
compress As Boolean = True) As Byte()
Dim bitmap_info As BITMAPINFO
Dim pixels() As Byte
Dim Size As Long

Dim dc As Long
dc = GetDC(hWnd)

Dim memDC As Long
memDC = CreateCompatibleDC(dc)

Dim r As RECT
GetClientRect hWnd, r

' Prepare the bitmap description.
With bitmap_info.bmiHeader
.biSize = 40
.biWidth = r.Right - r.Left
' Use negative height to scan top-down.
.biHeight = r.Top - r.Bottom
.biPlanes = 1
.biBitCount = 32
.biCompression = BI_RGB
End With

Dim bm As Long
Dim ptr As Long
bm = CreateDIBSection(dc, bitmap_info, DIB_PAL_COLORS,
ptr, 0, 0)

Dim oldbm As Long
oldbm = SelectObject(memDC, bm)

BitBlt memDC, 0, 0, r.Right - r.Left, r.Bottom -
r.Top, dc, 0, 0, SRCCOPY

' Copy the bitmap's data.
Size = (r.Right - r.Left) * (r.Bottom - r.Top) * 4
ReDim pixels(0 To Size - 1)

GetDIBits dc, bm, 0, r.Bottom - r.Top, pixels(0),
bitmap_info, DIB_PAL_COLORS

If compress Then
Dim z As New clsZLib
z.CompressByte pixels
End If

SelectObject memDC, oldbm
DeleteObject memDC
DeleteObject bm
ScreenshotBits = pixels
End Function

How do I duplicate this functionality in VB.NET? That is,
I could import all the API calls and do almost the exact
same code, but the .NET framwork abstracts tons of things
that were previously the realm of API calls. Is there
a .NET way to do this?

~BenDilts( void );
Nov 19 '05 #1
1 3918
Hello,

"Ben Dilts" <be*@agi.com> schrieb:
Under VB6, it was fairly straightforward to get a
screenshot. For instance, the following code:


http://www.mvps.org/dotnet/dotnet/sa...ndowsandforms/
-> "Screenshot"

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Me Mine | last post by:
i, I have trying to code a small console app that will allow a user to select a window and then create a screen capture of the window. I haven't been able to figure out how to do the screen...
1
by: xc | last post by:
Greetings. I encountered a wield problem when grabing screen images. Sometimes in some computers I can capture the screen, but other times not so. In some computer I cannot capture the screen...
3
by: Per | last post by:
Hi all, This may be a newbie question, but I can't find the answer anywhere. I want to make a capture of the screen, or a part of the screen, that contains the main portion of the form. Detecting...
1
by: Jody Gelowitz | last post by:
I have seen some examples of how to capture a color from a point on screen using C#, but haven't come across anything with VB.NET. Is this possible under VB.NET? I know that I will need to use...
2
by: Eddie Dunn | last post by:
I have one here that I cannot find anything on in my searching. I am implementing a screen capture functionality into my Visual Basic ..NET application. The code I am using calls the bitblt...
2
by: py | last post by:
I need to take a screen shot of the computer screen. I am trying to use PIL and I saw there is ImageGrab...however it only works on Windows. Is there a platform-independent ability to work...
4
by: gwhite1 | last post by:
I use this code to capture a screen in a regular VB 2005 windows app. It works great! I found the code in google. But when I create a windows service it does not capture the screen. It only...
2
by: dumbledad | last post by:
Hi All, I'm using ASP.Net web services to provide the logic required for a Flash based prototype. The Flash and the ASP .Net run together on the client machine. One of the functions I'd like to...
4
by: Paolo Pantaleo | last post by:
Hi, I need to capture a screen snapshot in Linux. PIL has a module IageGrab, but in the free version it only works under Windows. Is there any package to capture the screen on Linux? Thnx...
5
Atran
by: Atran | last post by:
Hello Everyone. In this article: You will know to capture the screen in 2 ways: 1)- Capture full screen. 2)- Capture region. Let's Begin: First make a new Windows Application project. And...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.