Hi I am currently trying to create Screenshot taker, which saves the screen as for example bitmap and then saves it. The problem is that it only saves desktop while I want it to save whole screen (For example while in WoW with full screen it only saves desktop, I want it to save WoW screen). I have tried using APIs GetForegroundWindow etc but no success yet. Need some solution without use of SendKeys(alt+printscreen).
Here's simple solution which only saves desktop (CopyFromScreen):
Code:
Dim ScreenSize As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim screenGrab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(screenGrab)
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), ScreenSize)
screenGrab.Save("C:\asd.jpg")
Here's using GetForegroundWindow (still only desktop):
Code:
Private Declare Function GetForegroundWindow Lib "user32.dll" () As IntPtr
Public Structure RECT
Public Left As Integer
Public Top As Integer
Public Right As Integer
Public Bottom As Integer
End Structure
Dim rct As RECT
GetWindowRect(GetForegroundWindow(), rct)
Using bmpScreenshot As Bitmap = New Bitmap(rct.Right - rct.Left, rct.Bottom - rct.Top, PixelFormat.Format24bppRgb)
Using gfxScreenshot As Graphics = Graphics.FromImage(bmpScreenshot)
gfxScreenshot.CopyFromScreen(rct.Left, rct.Top, 0, 0, New Size(rct.Right - rct.Left, rct.Bottom - rct.Top), CopyPixelOperation.SourceCopy)
End Using
PictureBox1.Image = New Bitmap(bmpScreenshot)
bmpScreenshot.Save("C:\asd.jpg", ImageFormat.Jpeg)
End Using
Thanks.