I have a printscreen method which is running in a timer_tick event handler to continously capture another application window. The problem is that for some reason, after some (very brief) periode of time, the application window being printscreened stops being painted properly it seems. Notice that this other application window is not part of my VB.NET 05 app. It seems that region inside the app window arent painted propperly, possibly delayed for a long time, and that in order for the regions to get repainted you have to minimuize and maximize to force it to repaint. My printscreen method uses
the classic PrintWindow API call:
I even tried to send a WM_PAINT message to the window without success, however I'm not sure I did this properly:
Why is this happening and how can I fix it?
Any and all suggestions are greatley appreciated
the classic PrintWindow API call:
VB.NET:
Public Declare Function PrintWindow Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal hdcBlt As IntPtr, _
ByVal nFlags As UInt32) As Boolean
Public Function printScreen(ByVal windowHandle As Integer) As Bitmap
Dim lpRect As RECT
Call GetWindowRect(windowHandle, lpRect)
Dim wBitmap As New Bitmap(lpRect.Right - lpRect.Left, lpRect.Bottom - lpRect.Top)
Dim g As Graphics = Graphics.FromImage(wBitmap)
Dim hdc As IntPtr = g.GetHdc
PrintWindow(windowHandle, hdc, Nothing)
g.ReleaseHdc(hdc)
g.Flush()
g.Dispose()
Return wBitmap
End Function
I even tried to send a WM_PAINT message to the window without success, however I'm not sure I did this properly:
VB.NET:
Private Declare Function UpdateWindow Lib "user32.dll" Alias "UpdateWindow" (ByVal hwnd As Int32) As Boolean
Public Sub refresh(ByVal handle As Integer)
UpdateWindow(handle)
End Sub
Why is this happening and how can I fix it?
Any and all suggestions are greatley appreciated
Last edited by a moderator: