Solved

Capture Active window in vb.net

Posted on 2007-03-31
4
590 Views
Last Modified: 2013-11-07
Does anyone have or has seen an example of how to find the current active window on a desktop, find its cordinates and then screen shot it in to a bmp?
0
Comment
Question by:pamsauto
[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
  • 3
4 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18829580
There are two basic ways to go about it:

(1) Use the GetForegroundWindow() API to get a handle to the active window.  Use the GetWindowRect() API to get the screen coordinates.  Use the BitBlt() API to copy it to an image (more APIs involved there).

(2) Press Alt-PrtScr and copy the resulting Image from the ClipBoard.

Do you have a preference in method?...
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 18829603
Method (2) is simply...

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Clipboard.Clear()
        SendKeys.SendWait("%{PRTSC}")
        Dim data As IDataObject = Clipboard.GetDataObject()
        If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
            Dim bmp As Bitmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Bitmap)

            ' do something with "bmp"...
            PictureBox1.Image = bmp
        End If
    End Sub
0
 

Author Comment

by:pamsauto
ID: 18829831
I need method #1.  With the API calls you gave me I found what I needed.  They were solutions you made for users already!    

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_21504191.html


As always Idle Mind - Thanks for your help.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18830192
=)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

763 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