By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,137 Members | 2,282 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,137 IT Pros & Developers. It's quick & easy.

Any 'Windows Service' Experts? Why can't I capture the screen??

P: n/a
I use this code to capture a screen in a regular VB 2005 windows app.
It works great! I found the code in google. But when I create a windows
service it does not capture the screen. It only captures a blank
graphic. Does anyone know why it will not capture the current screen?
Is something not available when running as a service? Thanks!!!
Sheila

Function CreateScreenshot() As System.Drawing.Bitmap
Dim Rect As System.Drawing.Rectangle =
System.Windows.Forms.Screen.PrimaryScreen.Bounds
Dim gDest As System.Drawing.Graphics
Dim hdcDest As IntPtr
Dim hdcSrc As Integer

CreateScreenshot = New System.Drawing.Bitmap(Rect.Right,
Rect.Bottom)
gDest = gDest.FromImage(CreateScreenshot)

hdcSrc = GetDC(0)
hdcDest = gDest.GetHdc
BitBlt(hdcDest.ToInt32, 0, 0, Rect.Right, Rect.Bottom, hdcSrc,
0, 0, SRCCOPY)
gDest.ReleaseHdc(hdcDest)
ReleaseDC(0, hdcSrc)
End Function

Apr 25 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
gw*****@kc.rr.com wrote:
I use this code to capture a screen in a regular VB 2005 windows app.
It works great! I found the code in google. But when I create a windows
service it does not capture the screen. It only captures a blank
graphic. Does anyone know why it will not capture the current screen?
Is something not available when running as a service? Thanks!!!
Sheila

Function CreateScreenshot() As System.Drawing.Bitmap
Dim Rect As System.Drawing.Rectangle =
System.Windows.Forms.Screen.PrimaryScreen.Bounds
Dim gDest As System.Drawing.Graphics
Dim hdcDest As IntPtr
Dim hdcSrc As Integer

CreateScreenshot = New System.Drawing.Bitmap(Rect.Right,
Rect.Bottom)
gDest = gDest.FromImage(CreateScreenshot)

hdcSrc = GetDC(0)
hdcDest = gDest.GetHdc
BitBlt(hdcDest.ToInt32, 0, 0, Rect.Right, Rect.Bottom, hdcSrc,
0, 0, SRCCOPY)
gDest.ReleaseHdc(hdcDest)
ReleaseDC(0, hdcSrc)
End Function


The windows service runs in it's own session. This is why you can't
make an interactive service and you can't screen capture.

Chris
Apr 25 '06 #2

P: n/a
On 24 Apr 2006 18:43:47 -0700, gw*****@kc.rr.com wrote:
I use this code to capture a screen in a regular VB 2005 windows app.
It works great! I found the code in google. But when I create a windows
service it does not capture the screen. It only captures a blank
graphic. Does anyone know why it will not capture the current screen?
Is something not available when running as a service? Thanks!!!
Sheila

Function CreateScreenshot() As System.Drawing.Bitmap
Dim Rect As System.Drawing.Rectangle =
System.Windows.Forms.Screen.PrimaryScreen.Bound s
Dim gDest As System.Drawing.Graphics
Dim hdcDest As IntPtr
Dim hdcSrc As Integer

CreateScreenshot = New System.Drawing.Bitmap(Rect.Right,
Rect.Bottom)
gDest = gDest.FromImage(CreateScreenshot)

hdcSrc = GetDC(0)
hdcDest = gDest.GetHdc
BitBlt(hdcDest.ToInt32, 0, 0, Rect.Right, Rect.Bottom, hdcSrc,
0, 0, SRCCOPY)
gDest.ReleaseHdc(hdcDest)
ReleaseDC(0, hdcSrc)
End Function

I'm not sure if this is related, but:
With Windows Media Player ver 9 and earlier, you use to be able to
screen capture a running video via the PrintScreen key and the frame
that was playing at the time would show in the resulting capture. With
ver 10 (and possibly from an additional XP upgrade), you no longer can
capture the frame. All you get is a blank media player. Screen capture
of a running video on any other player that I have, here, works as
expected.

I don't recall what MS calls it, but I believe it has something to do
with their attempt to protect media licensing rights.

Gene
Apr 25 '06 #3

P: n/a
GWhite,

A service cannot reach (direct) the screen. (I never tried it, therefore it
was to often written here).

Cor

<gw*****@kc.rr.com> schreef in bericht
news:11*********************@v46g2000cwv.googlegro ups.com...
I use this code to capture a screen in a regular VB 2005 windows app.
It works great! I found the code in google. But when I create a windows
service it does not capture the screen. It only captures a blank
graphic. Does anyone know why it will not capture the current screen?
Is something not available when running as a service? Thanks!!!
Sheila

Function CreateScreenshot() As System.Drawing.Bitmap
Dim Rect As System.Drawing.Rectangle =
System.Windows.Forms.Screen.PrimaryScreen.Bounds
Dim gDest As System.Drawing.Graphics
Dim hdcDest As IntPtr
Dim hdcSrc As Integer

CreateScreenshot = New System.Drawing.Bitmap(Rect.Right,
Rect.Bottom)
gDest = gDest.FromImage(CreateScreenshot)

hdcSrc = GetDC(0)
hdcDest = gDest.GetHdc
BitBlt(hdcDest.ToInt32, 0, 0, Rect.Right, Rect.Bottom, hdcSrc,
0, 0, SRCCOPY)
gDest.ReleaseHdc(hdcDest)
ReleaseDC(0, hdcSrc)
End Function

Apr 25 '06 #4

P: n/a
Try perhaps to check the "allow service to interact with desktop" checkbox.

A service is generally not tied to the desktop. It runs in its own
context...

--
Patrice

<gw*****@kc.rr.com> a écrit dans le message de news:
11*********************@v46g2000cwv.googlegroups.c om...
I use this code to capture a screen in a regular VB 2005 windows app.
It works great! I found the code in google. But when I create a windows
service it does not capture the screen. It only captures a blank
graphic. Does anyone know why it will not capture the current screen?
Is something not available when running as a service? Thanks!!!
Sheila

Function CreateScreenshot() As System.Drawing.Bitmap
Dim Rect As System.Drawing.Rectangle =
System.Windows.Forms.Screen.PrimaryScreen.Bounds
Dim gDest As System.Drawing.Graphics
Dim hdcDest As IntPtr
Dim hdcSrc As Integer

CreateScreenshot = New System.Drawing.Bitmap(Rect.Right,
Rect.Bottom)
gDest = gDest.FromImage(CreateScreenshot)

hdcSrc = GetDC(0)
hdcDest = gDest.GetHdc
BitBlt(hdcDest.ToInt32, 0, 0, Rect.Right, Rect.Bottom, hdcSrc,
0, 0, SRCCOPY)
gDest.ReleaseHdc(hdcDest)
ReleaseDC(0, hdcSrc)
End Function

Apr 25 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.