Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7795827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:10:55+00:00 2026-06-01T23:10:55+00:00

I am needing code that will run in visual basic to capture the screen

  • 0

I am needing code that will run in visual basic to capture the screen and convert it to a RBG array of pixel values – needs to be quite fast.

Any help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:10:57+00:00Added an answer on June 1, 2026 at 11:10 pm

    This code will capture a screenshot from a window or the entire desktop (virtual screen) and draw it to a custom picturebox.

    Private Type RECT
      Left As Long
      Top As Long
      Right As Long
      Bottom As Long
    End Type
    
    Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
    Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    
    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
    Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
    
    Private Const SM_XVIRTUALSCREEN = 76
    Private Const SM_YVIRTUALSCREEN = 77
    Private Const SM_CYVIRTUALSCREEN = 79
    Private Const SM_CXVIRTUALSCREEN = 78
    
    Private Sub GetScreenshot(Optional ByVal hWnd As Long = 0)
    Dim hDC As Long
    
    Dim WindowRect As RECT
    Dim Left As Long
    Dim Top As Long
    Dim Width As Long
    Dim Height As Long
    
      If hWnd = 0 Then
        'Get the DC of the desktop
        hDC = GetWindowDC(GetDesktopWindow)
    
        'Get the virtual screen coordinates (this handles multiple monitors too :)
        Left = GetSystemMetrics(SM_XVIRTUALSCREEN)
        Top = GetSystemMetrics(SM_YVIRTUALSCREEN)
        Width = GetSystemMetrics(SM_CXVIRTUALSCREEN)
        Height = GetSystemMetrics(SM_CYVIRTUALSCREEN)
    
      Else
        'Get the DC of the window we want to capture
        hDC = GetWindowDC(hWnd)
    
        'Get the window coordinates
        GetWindowRect hWnd, WindowRect
        Left = 0
        Top = 0
        Width = WindowRect.Right - WindowRect.Left
        Height = WindowRect.Bottom - WindowRect.Top
    
      End If
    
      'BitBlt into our own DC
      BitBlt picScreen.hDC, 0, 0, Width, Height, hDC, Left, Top, vbSrcCopy
    
      'Delete our reference to the windows's DC
      ReleaseDC hWnd, hDC
    End Function
    

    Note the use of GetSystemMetrics() when capturing the desktop. This allows it to get the full virtual screen screen dimensions when multiple monitors are in use instead of just the primary monitor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am needing to write portable code that will run on a shared server
I am needing the code that will allow my users to input centered text
I am needing to create a foreach statement that will run through and create
In HTML is there such a line of code that will do the same
We are developing a custom textual DSL, that will ultimately get integrated into Visual
Hey all. Here is the scenario. I have the below code, and I'm needing
I often find myself needing reference to an object that is several objects away,
I'm needing to create a zip file containing documents that exist on the server.
I'm in lean startup mode, working on a simple phone app that will be
I'm working on a solution in Visual Studio 2010 Ultimate that contains two C#

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.