Window / desktop image capture [ vb.net ]

Discussion in 'Programming' started by navifier, Aug 8, 2011.

  1. #1
    Hi Guys !

    VB.NET question ->

    I would like to make a program that allows me to see the preview of a window inside a form, so far i have managed to make a program to capture an area of fixed size, but there was one problem, the program crashed as soon as my pc run out of virtual memory. So my problem is simple i need to some how fetch hwnd ( handle ) of a window by name and preview ( not save ) on a form. So far i have added a Picture box and a timer that does an action of screen capture and showing that image, but as i said i had memory problems. Here is the code that i have so far ..

    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Timer1.Start()
    end sub
    
     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Dim graph As Graphics = Nothing
            Dim bmp As Bitmap = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
            graph = Graphics.FromImage(bmp)
            graph.CopyFromScreen(50, 59, 59, 59, bmp.Size)
            PictureBox1.BackgroundImage = bmp
        End Sub
    
    Code (markup):
    and here it is how it looks like

    Untitled.jpg
     
    navifier, Aug 8, 2011 IP
  2. navifier

    navifier Member

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    Hi ! I have now tried a different approach with Sendkeys.send() but the memory problem is still here and the app crashes after a while. Something is telling me that the picturebox is the problem. Here is what i have now


    
    
       Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            AppActivate("Untitled - Notepad")
            SendKeys.Send("%{PRTSC}")  ' this is just like alt+printscr
            PictureBox1.Image = CType(Clipboard.GetDataObject.GetData("Bitmap"), Image)
        End Sub
    
    Code (markup):
     
    navifier, Aug 9, 2011 IP
  3. Mind Freak

    Mind Freak Active Member

    Messages:
    13
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    63
    #3
    i would post a similar source soon but in c#
     
    Mind Freak, Aug 9, 2011 IP
  4. navifier

    navifier Member

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #4
    Any language is ok with me, please do show me what you got.
     
    navifier, Aug 9, 2011 IP