Solved

Capture Active window in vb.net

Posted on 2007-03-31
4
575 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
  • 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now