• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

Visual Basic Screen Capture

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
verasen
Asked:
verasen
2 Solutions
 
jayeshshahCommented:
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
 
Richie_SimonettiIT OperationsCommented:
If window is minimized, i think the only way is retore it, do the stuff and set it back to minimize state.
0
 
Richie_SimonettiIT OperationsCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Richie_SimonettiIT OperationsCommented:
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
 
verasenAuthor Commented:
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
 
SethiCommented:
This code example from Microsoft works excellently:
http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B161299
0
 
Richie_SimonettiIT OperationsCommented:
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
 
webJoseCommented:
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
 
CleanupPingCommented:
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
 
DanRollinsCommented:
Moderator, my recommended disposition is:

    Split points between: Richie_Simonetti and webJose

DanRollins -- EE database cleanup volunteer
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now