Solved

Capture Active window in vb.net

Posted on 2007-03-31
4
601 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 86

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 86

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 86

Expert Comment

by:Mike Tomlinson
ID: 18830192
=)
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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