?
Solved

Visual Basic Screen Capture

Posted on 2003-02-25
11
Medium Priority
?
269 Views
Last Modified: 2013-11-25
I need to capture whatever is visible on a window. I know it's possible to capture any window on the screen, but what I need is to capture a window that is minimized. So the contents of the window are not directly visible, but I would like to capture what the window would look like if it were not minimized. Any ideas?
0
Comment
Question by:verasen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 5

Expert Comment

by:jayeshshah
ID: 8019042
download the file capture.zip from the following link and check if it suits your requirements.
http://www.vbcode.com/images/bigzip.gif


K'Regards

Jayesh
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8019574
If window is minimized, i think the only way is retore it, do the stuff and set it back to minimize state.
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 400 total points
ID: 8019639
This is a little example:

Option Explicit
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 GetForegroundWindow Lib "user32" () As Long
Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Form_Click()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim Ret As Long

        'Get the handle of the foreground window
        Ret = GetForegroundWindow()
        'Get the foreground window's device context
        Ret = GetDC(Ret)
        'draw an ellipse
        BitBlt Picture1.hdc, 0, 0, 300, 300, Ret, 0, 0, vbSrcCopy
        DoEvents
 
End Sub


0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8019693
You need two more api to find the target window and setting its state:

'complete one (i think)

Option Explicit
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 GetForegroundWindow Lib "user32" () As Long
Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const SW_RESTORE = 9
Private Const SW_MINIMIZE = 6
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Private Sub Form_Click()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim Ret As Long, hw As Long

        'Get the handle of the foreground window
        hw = FindWindow(vbNullString, "your_target_caption_goes_here") 'GetForegroundWindow()
        'Get the foreground window's device context
        ShowWindow hw, SW_RESTORE
        Ret = GetDC(hw)
       
        BitBlt Picture1.hdc, 0, 0, 300, 300, Ret, 0, 0, vbSrcCopy
        ShowWindow hw, SW_MINIMIZE

 
End Sub


take in mind that you could need to test if window is really minimized or not.
0
 

Author Comment

by:verasen
ID: 8020979
Thanks for your reply, but what you're doing is restoring it and minimizing it again. The problem is I need to sample this thing at 20 frames a second, so restoring and minimizing 20 times a second seems like it'll turn into a horror show :)


0
 
LVL 18

Expert Comment

by:Sethi
ID: 8022097
This code example from Microsoft works excellently:
http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B161299
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8025066
jayeshshah:
your link is broken.

verasen:
If window is not in screen, you will capture nothing.
Besides, your question was regarding one window that is minimized. You never told about "..20 frames a second..."
0
 
LVL 7

Assisted Solution

by:webJose
webJose earned 400 total points
ID: 8031645
What Richie says is correct.  The only way to get a screenshot of a window is if the window is visible.  Otherwise is impossible.  Why?  Because Windows does not know every possible content of every possible window.  If Windows determines a specified window needs repainting, it will post a WM_PAINT message so the window repaints itself.  It would be a monumental waste of RAM if Windows stored a bitmap representation of the complete contents of every window.

There is no way to achieve what you are asking for, in my opinion.  From the top of my head, maybe dll injection will achieve the goal by hooking into the BeginPaint and EndPaint GDI API functions, but again, it takes an assembly guy to pull out something like that.
0
 

Expert Comment

by:CleanupPing
ID: 8901127
verasen:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8972835
Moderator, my recommended disposition is:

    Split points between: Richie_Simonetti and webJose

DanRollins -- EE database cleanup volunteer
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question