Results 1 to 16 of 16

Thread: [2005] Capture screen around mouse

  1. #1

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    [2005] Capture screen around mouse

    How do I capture a screenshot of the current screen around the mouse?
    The idea is that I get a little 32x32 image of the area around screen at the mouse location so that the mouse point is in the center?

    Please see attached picture for another example.

    Thanks in advance, knxrb
    Attached Images Attached Images  
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: [2005] Capture screen around mouse

    you'll need to hook the wm_mousemove msg + (or maybe just) the WM_LBUTTONDBLCLK (?) msg, to catch a doubleclick + then capture a 32*32image from the screen using the coordinates in a wndProc. its not a simple job. try googling - hook WM_LBUTTONDBLCLK vb.net. theres some examples there but they're certainly not simple.

    anyway, when you've hooked the msg, you catch it in a wndProc in your form + then grab your image from the screen.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Capture screen around mouse

    Are you saying that you want this to be dynamic, kind of like a screen magnifier, or just an on-demand thing? If it's the latter then you can call the Graphics.CopyFromScreen method and use the Control.MousePosition property to determine the area to copy.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: [2005] Capture screen around mouse

    It's supposed to be a magnifier that gets you a closer look at the area around the mouse.
    It would only call it when the mosue moves around my picturebox.

    Also how would I use CopyFromScreen?
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Capture screen around mouse

    Quote Originally Posted by knxrb
    Also how would I use CopyFromScreen?
    Much like the code example provided in the MSDN documentation for the CopyFromScreen method shows it, I would think.

    If I tell someone what method to use to accomplish a task, it's my expectation that they will at least read the documentation for that method. It generally takes no more than 1 minute to open the MSDN documentation to the index, type in the the method name, click it in the list and then read the information provided. Are my expectations too high?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: [2005] Capture screen around mouse

    I've already done that and I get this:
    http://msdn.microsoft.com/en-us/libr...romscreen.aspx
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Capture screen around mouse

    Quote Originally Posted by knxrb
    I've already done that and I get this:
    http://msdn.microsoft.com/en-us/libr...romscreen.aspx
    Well, that's the first step. Did you click on each of the overload signatures to read about each one? Each one is a link to the topic dedicated to that overload. That's how that interweb thingy works: read, click, read.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: [2005] Capture screen around mouse

    [EDIT]
    I've now got this, but all it gives me is a 1024x768 bitmap with a small 32x32 bitmap of where the mouse was...
    Code:
    Dim bmp As New Bitmap(1024, 768, Imaging.PixelFormat.Format32bppArgb)
            Dim instance As Graphics = Graphics.FromImage(bmp)
            Dim upperLeftSource As Point = New Point(PointToScreen(New Point(e.X - 16, e.Y - 16)).X, PointToScreen(New Point(e.X - 16, e.Y - 16)).Y)
            Dim upperLeftDestination As Point = New Point(PointToScreen(New Point(e.X + 16, e.Y + 16)).X, PointToScreen(New Point(e.X + 16, e.Y + 16)).Y)
            Dim blockRegionSize As Size = New Size(32, 32)
            instance.CopyFromScreen(upperLeftSource, upperLeftDestination, blockRegionSize)
            Mouse.picZoom.Image = bmp
            bmp.Save("1.bmp")
    [EDIT]

    Yep, I've now got this...
    Code:
            Dim instance As Graphics
            Dim upperLeftSource As Point = New Point(PointToScreen(New Point(e.X - 16, e.Y - 16)).X, PointToScreen(New Point(e.X - 16, e.Y - 16)).Y)
            Dim upperLeftDestination As Point = New Point(PointToScreen(New Point(e.X + 16, e.Y + 16)).X, PointToScreen(New Point(e.X + 16, e.Y + 16)).Y)
            Dim blockRegionSize As Size = New Size(32, 32)
            instance.CopyFromScreen(upperLeftSource, upperLeftDestination, blockRegionSize)
    ...but how do I get that into a 32x32 bitmap image?
    Last edited by knxrb; Dec 6th, 2008 at 08:45 AM.
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Capture screen around mouse

    Are you saying that you don't know why your Bitmap is 1024 x 768?
    Code:
    Dim bmp As New Bitmap(1024, 768, Imaging.PixelFormat.Format32bppArgb)
    That's your code.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Capture screen around mouse

    I created a new project. I added a Button and a PictureBox. I added this code:
    Code:
    Private Sub Button1_Click(ByVal sender As Object, _
                              ByVal e As EventArgs) Handles Button1.Click
        Dim bmp As New Bitmap(32, 32)
        Dim sourceLocation As Point = Control.MousePosition
    
        sourceLocation.Offset(-16, -16)
    
        Using g As Graphics = Graphics.FromImage(bmp)
            g.CopyFromScreen(sourceLocation, Point.Empty, bmp.Size)
        End Using
    
        Me.PictureBox1.Image = bmp
    End Sub
    I ran the project and clicked the Button.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: [2005] Capture screen around mouse

    No, I know why it's 1024x768, I want to know how I get the 32x32 bitmap that's displayed to be a 32x32 bitmap instead of it being a 1024x768 bitmap with a 32x32 bitmap where the cursor was.
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Capture screen around mouse

    Quote Originally Posted by knxrb
    No, I know why it's 1024x768, I want to know how I get the 32x32 bitmap that's displayed to be a 32x32 bitmap instead of it being a 1024x768 bitmap with a 32x32 bitmap where the cursor was.
    That doesn't make sense. If you know why it's a 1024 x 768 Bitmap then you how to change the code to make it a 32 x 32 Bitmap. YOU are specifying the size of the Bitmap when you invoke the constructor. If you specify 1024 and 768 as the dimensions then of course it will be 1024 x 768. If you want it to be 32 x 32 then logic would dictate that those should be the dimensions you specify when you create it.

    There also seems to be some confusion here as to what's a Bitmap and what isn't. There is no 1024 x 768 Bitmap with a 32 x 32 Bitmap inside it. There is only one Bitmap object and that's the one you create by invoking the Bitmap class constructor. That Bitmap will be whatever size you tell the constructor to make it. When you call CopyFromScreen you are NOT creating another Bitmap. You are simply copying some pixels from the screen onto the Bitmap you created. You specify the upper left corner of the area on screen, the upper left corner of the area on the canvas and the size of the area. The corner of the source area is 16 to the left and 16 above the cursor position:
    Code:
    sourceLocation.Offset(-16, -16)
    The upper left corner of the target area is the upper left corner of the canvas itself, i.e. (0, 0):
    Code:
    g.CopyFromScreen(sourceLocation, Point.Empty, bmp.Size)
    The size of the area is the size of the canvas:
    Code:
    g.CopyFromScreen(sourceLocation, Point.Empty, bmp.Size)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  13. #13

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: [2005] Capture screen around mouse

    This is what i mean when I have a 1024x768 bitmap with a 32x32 picture at the mouse location:
    Attached Files Attached Files
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

  14. #14
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Capture screen around mouse

    I don't understand what you're trying to say. I've already shown you how to create a 32x32 Bitmap and copy a 32x32 area of the screen centred on the mouse cursor to that Bitmap. Are you saying that that isn't what you want? If so then you're going to have to try again to explain what you DO want because I have no idea. If what I've described IS what you want then I don't understand what the problem is.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  15. #15

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: [2005] Capture screen around mouse

    Sorry, no problem now, somehow I missed post #10:
    http://www.vbforums.com/showpost.php...8&postcount=10
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

  16. #16
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Capture screen around mouse

    Quote Originally Posted by knxrb
    somehow I missed post #10
    What? You missed my best work in this thread? Alls is well what endses well.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width