|
-
Jun 21st, 2007, 03:26 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Wierd Screen Caputre...
I've made a screen shot program... but there's a strange problem with it...
There's an option to capture the focused window.
When the event fires it calls this function. The function captures the correct amount of space (The Windows Height and the Windows Length).
But for some reason that i can't figure out, it doesn't get the Top and the Left correctly, when the function is called, these are both 0 & i end up capturing the top left of the screen with the focused window's size (Height and Width). I'm pretty sure it's my code, as i didn't create this code, rather got it off this forum site about 12 months ago and frankensteined it together.
Don't mind the commented stuff, it was just me trying to resolve the error.
Code:
Public xpos As Long
Public ypos As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
'##############^^^ CAPTURE SCREEN ^^^################
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowRect Lib "user32" _
(ByVal hWnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Sub Screen_Shot_Event(Picture_ As PictureBox, Optional Active_Window As Boolean = False, Optional Draw_Cursor As Boolean = False)
Dim wScreen As Long
Dim hScreen As Long
Dim hdcScreen As Long
Dim w As Long
Dim h As Long
Dim TmpPic As PictureBox
Set TmpPic = Picture_
TmpPic.AutoRedraw = False
TmpPic.Width = 15000
TmpPic.Height = 15000
Dim lWnd As Long
Dim R
lWnd = GetForegroundWindow()
Picture_.Cls
wScreen = Screen.Width \ Screen.TwipsPerPixelX
hScreen = Screen.Height \ Screen.TwipsPerPixelY
Picture_.ScaleMode = vbPixels
w = Screen.Width / Screen.TwipsPerPixelX
h = Screen.Height / Screen.TwipsPerPixelY
hdcScreen = GetDC(0)
If Draw_Cursor = True Then DrawCursor hdcScreen
If Active_Window = False Then
Picture_.Width = (Screen.Width)
Picture_.Height = (Screen.Height)
'Picture_.AutoRedraw = False
R = StretchBlt(TmpPic.hdc, 0, 0, w, h, hdcScreen, 0, 0, wScreen, hScreen, vbSrcCopy)
'Picture_.AutoRedraw = True
Else
If Active_Window = True Then
Dim rct As RECT
GetWindowRect lWnd, rct
'Picture_.AutoRedraw = False
R = StretchBlt(TmpPic.hdc, rct.Left * -1, rct.Top * -1, rct.Right, rct.Bottom, hdcScreen, 0, 0, rct.Right, rct.Bottom, vbSrcCopy)
Picture_.Width = (rct.Right * Screen.TwipsPerPixelX) - (rct.Left * Screen.TwipsPerPixelX) + 70
Picture_.Height = (rct.Bottom * Screen.TwipsPerPixelY) - (rct.Top * Screen.TwipsPerPixelY) + 70
'Picture_.AutoRedraw = True
End If
End If
Debug.Print ""
Debug.Print lWnd, hdcScreen, rct.Top
Set Picture_.Picture = hDCToPicture(hdcScreen, 0, 0, Screen.Width / Screen.TwipsPerPixelX, Screen.Height / Screen.TwipsPerPixelY)
End Sub
Last edited by Slyke; Jun 21st, 2007 at 03:30 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|