473,411 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

URGENT, tricky question (BitBlt experts especially)

I am using the BitBlt operation to capture various controls into jpegs.
It's almost like a screen capture, but of just the control. (This is a
VB.NET application.)

Because of BitBlt limitations I know that the application has to always be
on top.

The problem: I am running this application on a Windows Server 2003 PC. The
server is in another state (North Carolina). I am in Florida. I access the
server over Termincal Server /Remote Desktop. When I disconnect my Remote
Desktop (with the application still running) ALL THE GENERATED IMAGES ARE
BLACK! If I reconnect with Remote Desktop it works PERFECTLY. In other
words it's like using my remote display to draw the jpegs!

1. Any ideas how to overcome this tricky problem?
2. Any alternatives to BitBlt? (I have an ActiveX gauge control (like a
speedometer) and need to capture just the control to a jpeg image.)

Thanks.
Nov 20 '05 #1
7 2411
Hi,

Post your code

Ken
---------------------
"VB Programmer" <gr*********@go-intech.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I am using the BitBlt operation to capture various controls into jpegs.
It's almost like a screen capture, but of just the control. (This is a
VB.NET application.)

Because of BitBlt limitations I know that the application has to always be
on top.

The problem: I am running this application on a Windows Server 2003 PC.
The
server is in another state (North Carolina). I am in Florida. I access
the
server over Termincal Server /Remote Desktop. When I disconnect my Remote
Desktop (with the application still running) ALL THE GENERATED IMAGES ARE
BLACK! If I reconnect with Remote Desktop it works PERFECTLY. In other
words it's like using my remote display to draw the jpegs!

1. Any ideas how to overcome this tricky problem?
2. Any alternatives to BitBlt? (I have an ActiveX gauge control (like a
speedometer) and need to capture just the control to a jpeg image.)

Thanks.

Nov 20 '05 #2
Here's the portion dealing with that...

Public Declare Function BitBlt Lib "gdi32" ( _
ByVal hDestDC As IntPtr, _
ByVal x As Integer, _
ByVal y As Integer, _
ByVal nWidth As Integer, _
ByVal nHeight As Integer, _
ByVal hSrcDC As IntPtr, _
ByVal xSrc As Integer, _
ByVal ySrc As Integer, _
ByVal dwRop As Integer _
) As Integer

Private Sub CaptureGauge(ByVal strFileName As String, ByVal IsKnob As
Boolean)
Try
Dim MyBitmap As Bitmap
Dim MyForm As frmMain

If IsKnob Then
MyBitmap = CaptureControl(MyFrmMain.panKnob)
Else
MyBitmap = CaptureControl(MyFrmMain.panSlider)
End If
MyBitmap.Save(strFileName, Imaging.ImageFormat.Jpeg)

Catch ex As Exception
HandleError(ex, "CaptureGauge")
End Try
End Sub

Public Function CaptureControl(ByVal c As Control) As Bitmap
Dim bmp As Bitmap
Dim gDest, gSource As Graphics
Dim hdcSource, hdcDest As IntPtr
Const SRCCOPY As Integer = &HCC0020
bmp = New Bitmap(c.Width, c.Height)

gSource = c.CreateGraphics
Try
gDest = Graphics.FromImage(bmp)
Try
hdcSource = gSource.GetHdc
Try
hdcDest = gDest.GetHdc
Try
BitBlt( _
hdcDest, 0, 0, _
c.Width, c.Height, _
hdcSource, 0, 0, SRCCOPY _
)
Finally
gDest.ReleaseHdc(hdcDest)
End Try
Finally
gSource.ReleaseHdc(hdcSource)
End Try
Finally
gDest.Dispose()
End Try
Finally
gSource.Dispose()
End Try
Return bmp
End Function

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:eR**************@TK2MSFTNGP11.phx.gbl...
Hi,

Post your code

Ken
---------------------
"VB Programmer" <gr*********@go-intech.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I am using the BitBlt operation to capture various controls into jpegs.
It's almost like a screen capture, but of just the control. (This is a
VB.NET application.)

Because of BitBlt limitations I know that the application has to always be on top.

The problem: I am running this application on a Windows Server 2003 PC.
The
server is in another state (North Carolina). I am in Florida. I access
the
server over Termincal Server /Remote Desktop. When I disconnect my Remote Desktop (with the application still running) ALL THE GENERATED IMAGES ARE BLACK! If I reconnect with Remote Desktop it works PERFECTLY. In other
words it's like using my remote display to draw the jpegs!

1. Any ideas how to overcome this tricky problem?
2. Any alternatives to BitBlt? (I have an ActiveX gauge control (like a speedometer) and need to capture just the control to a jpeg image.)

Thanks.


Nov 20 '05 #3
Hi,

Are you getting an error ?

Declare Function GetLastError Lib "kernel32" Alias "GetLastError" () As
Integer

Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA"
_

(ByVal dwFlags As Integer, ByRef lpSource As Object, ByVal dwMessageId As
Integer, _

ByVal dwLanguageId As Integer, ByVal lpBuffer As String, ByVal nSize As
Integer, _

ByRef Arguments As Integer) As Integer

Private Const FORMAT_MESSAGE_FROM_SYSTEM As Short = &H1000S

Private Const LANG_NEUTRAL As Short = &H0S

Dim intReturn As Integer

intReturn = BitBlt( _

hdcDest, 0, 0, w, h, hdcSrc, 0, 0, SRCCOPY)

If intReturn = 0 Then

Dim Buffer As String = Space(255)

FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError, _

LANG_NEUTRAL, Buffer, 255, 0)

MessageBox.Show(Buffer)

End If

Ken

---------------------------

"VB Programmer" <gr*********@go-intech.com> wrote in message
news:OH**************@tk2msftngp13.phx.gbl...
Here's the portion dealing with that...

Public Declare Function BitBlt Lib "gdi32" ( _
ByVal hDestDC As IntPtr, _
ByVal x As Integer, _
ByVal y As Integer, _
ByVal nWidth As Integer, _
ByVal nHeight As Integer, _
ByVal hSrcDC As IntPtr, _
ByVal xSrc As Integer, _
ByVal ySrc As Integer, _
ByVal dwRop As Integer _
) As Integer

Private Sub CaptureGauge(ByVal strFileName As String, ByVal IsKnob As
Boolean)
Try
Dim MyBitmap As Bitmap
Dim MyForm As frmMain

If IsKnob Then
MyBitmap = CaptureControl(MyFrmMain.panKnob)
Else
MyBitmap = CaptureControl(MyFrmMain.panSlider)
End If
MyBitmap.Save(strFileName, Imaging.ImageFormat.Jpeg)

Catch ex As Exception
HandleError(ex, "CaptureGauge")
End Try
End Sub

Public Function CaptureControl(ByVal c As Control) As Bitmap
Dim bmp As Bitmap
Dim gDest, gSource As Graphics
Dim hdcSource, hdcDest As IntPtr
Const SRCCOPY As Integer = &HCC0020
bmp = New Bitmap(c.Width, c.Height)

gSource = c.CreateGraphics
Try
gDest = Graphics.FromImage(bmp)
Try
hdcSource = gSource.GetHdc
Try
hdcDest = gDest.GetHdc
Try
BitBlt( _
hdcDest, 0, 0, _
c.Width, c.Height, _
hdcSource, 0, 0, SRCCOPY _
)
Finally
gDest.ReleaseHdc(hdcDest)
End Try
Finally
gSource.ReleaseHdc(hdcSource)
End Try
Finally
gDest.Dispose()
End Try
Finally
gSource.Dispose()
End Try
Return bmp
End Function

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:eR**************@TK2MSFTNGP11.phx.gbl...
Hi,

Post your code

Ken
---------------------
"VB Programmer" <gr*********@go-intech.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
>I am using the BitBlt operation to capture various controls into jpegs.
> It's almost like a screen capture, but of just the control. (This is a
> VB.NET application.)
>
> Because of BitBlt limitations I know that the application has to always be > on top.
>
> The problem: I am running this application on a Windows Server 2003 PC.
> The
> server is in another state (North Carolina). I am in Florida. I
> access
> the
> server over Termincal Server /Remote Desktop. When I disconnect my Remote > Desktop (with the application still running) ALL THE GENERATED IMAGES ARE > BLACK! If I reconnect with Remote Desktop it works PERFECTLY. In
> other
> words it's like using my remote display to draw the jpegs!
>
> 1. Any ideas how to overcome this tricky problem?
> 2. Any alternatives to BitBlt? (I have an ActiveX gauge control (like a > speedometer) and need to capture just the control to a jpeg image.)
>
> Thanks.
>
>



Nov 20 '05 #4
On 2004-02-07, Ken Tucker [MVP] <vb***@bellsouth.net> wrote:
Hi,

Are you getting an error ?

Declare Function GetLastError Lib "kernel32" Alias "GetLastError" () As
Integer

Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA"
_

(ByVal dwFlags As Integer, ByRef lpSource As Object, ByVal dwMessageId As
Integer, _

ByVal dwLanguageId As Integer, ByVal lpBuffer As String, ByVal nSize As
Integer, _

ByRef Arguments As Integer) As Integer

Private Const FORMAT_MESSAGE_FROM_SYSTEM As Short = &H1000S

Private Const LANG_NEUTRAL As Short = &H0S

Dim intReturn As Integer

intReturn = BitBlt( _

hdcDest, 0, 0, w, h, hdcSrc, 0, 0, SRCCOPY)

If intReturn = 0 Then

Dim Buffer As String = Space(255)

FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError, _

LANG_NEUTRAL, Buffer, 255, 0)

MessageBox.Show(Buffer)

End If

Ken

---------------------------

"VB Programmer" <gr*********@go-intech.com> wrote in message
news:OH**************@tk2msftngp13.phx.gbl...


Ken,

Using GetLastError in VB.NET is not a good idea - for the same reasons
as in VB.CLASSIC. The runtime makes API calls and the value you get
from GetLastError may not be correct...

To get API error returns you should use Marshal.GetLastWin32Error().
And the calls to format message are not needed either. Just create an
instance of System.ComponentModel.Win32Exception and then look at the
..Message property...

' BitBlt code...
If intRetun = 0 Then
Dim ex As New Win32Exception(Marshal.GetLastWin32Error())
MessageBox.Show(ex.Message)
End If

--
Tom Shelton [MVP]
Powered By Gentoo Linux 1.4
Of all men's miseries, the bitterest is this:
to know so much and have control over nothing.
-- Herodotus
Nov 20 '05 #5
"Ken Tucker [MVP]" <vb***@bellsouth.net> schrieb

Are you getting an error ?


Untested: I think we could reproduce the problem by pressing Win+L and
having the app make a snapshot meanwhile...
--
Armin

Nov 20 '05 #6
Hi,

Much better method.

Ken
------------------
"Tom Shelton" <to*@mtogden.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
On 2004-02-07, Ken Tucker [MVP] <vb***@bellsouth.net> wrote:
Hi,

Are you getting an error ?

Declare Function GetLastError Lib "kernel32" Alias "GetLastError" () As
Integer

Private Declare Function FormatMessage Lib "kernel32" Alias
"FormatMessageA"
_

(ByVal dwFlags As Integer, ByRef lpSource As Object, ByVal dwMessageId As
Integer, _

ByVal dwLanguageId As Integer, ByVal lpBuffer As String, ByVal nSize As
Integer, _

ByRef Arguments As Integer) As Integer

Private Const FORMAT_MESSAGE_FROM_SYSTEM As Short = &H1000S

Private Const LANG_NEUTRAL As Short = &H0S

Dim intReturn As Integer

intReturn = BitBlt( _

hdcDest, 0, 0, w, h, hdcSrc, 0, 0, SRCCOPY)

If intReturn = 0 Then

Dim Buffer As String = Space(255)

FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError, _

LANG_NEUTRAL, Buffer, 255, 0)

MessageBox.Show(Buffer)

End If

Ken

---------------------------

"VB Programmer" <gr*********@go-intech.com> wrote in message
news:OH**************@tk2msftngp13.phx.gbl...


Ken,

Using GetLastError in VB.NET is not a good idea - for the same reasons
as in VB.CLASSIC. The runtime makes API calls and the value you get
from GetLastError may not be correct...

To get API error returns you should use Marshal.GetLastWin32Error().
And the calls to format message are not needed either. Just create an
instance of System.ComponentModel.Win32Exception and then look at the
.Message property...

' BitBlt code...
If intRetun = 0 Then
Dim ex As New Win32Exception(Marshal.GetLastWin32Error())
MessageBox.Show(ex.Message)
End If

--
Tom Shelton [MVP]
Powered By Gentoo Linux 1.4
Of all men's miseries, the bitterest is this:
to know so much and have control over nothing.
-- Herodotus

Nov 20 '05 #7
Thanks everyone I will try it today.

"Armin Zingler" <az*******@freenet.de> wrote in message
news:us**************@TK2MSFTNGP12.phx.gbl...
"Ken Tucker [MVP]" <vb***@bellsouth.net> schrieb

Are you getting an error ?


Untested: I think we could reproduce the problem by pressing Win+L and
having the app make a snapshot meanwhile...
--
Armin

Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Vibhajha | last post by:
Hi friends, My sister is in great problem , she has this exam of C++ and she is stuck up with some questions, if friends like this group provides some help to her, she will be very grateful....
2
by: DraguVaso | last post by:
Hi, In the override of the Paint-method of a DataGridTextBoxColumn I want to show an image with BitBlt, to see what I can gain there on performance. The problem is: It doesn't show me the image...
5
by: JackS | last post by:
I am trying to use GDI32 bitblt to write a bitmap to a control's window, but all I get is an empty rectangle of some rop-dependent color. In short, I use the following logic in a paint event handler:...
2
by: mmacrobert | last post by:
We have an MFC application mixed with a few .NET controls. I would like to be able to render the content of a .NET control to an MFC device context - specifically a printing device context. We...
11
by: Daemach | last post by:
OK, it's time to try the experts :) I've been doing most of my development work in Firefox because of Firebug. Then, when my projects are fully debugged, sleek and refined I load them in IE and...
6
by: Martijn Mulder | last post by:
/* BitBlt.cs C# code using P/Invoke I have good reasons to use P/Invoke to get access to the Win32 API function BitBlt(). But I have trouble understanding the workings of it. Below is a...
5
by: =?Utf-8?B?UmljYXJkbyBGdXJ0YWRv?= | last post by:
I'm trying to copy a part of an image (a rectangle) width the bitblt api function, bu i receive an error when i try to do it. The error is the following, that i will try to translate because its in...
1
by: =?Utf-8?B?Y3JhbmtlX2JveQ==?= | last post by:
Hi Folks, I'm not sure where this post belongs since I'm using managed vc.net, but the issue is around GDI BitBlt. Here is a summary of the problem: - I am trying to copy a bitmap of my main...
0
by: crankeboy | last post by:
Hi Folks, My setup: Visual Studio Express 2008, VC++, .NET, BitBlt Here is a summary of the problem: - I am trying to copy a bitmap of my main form into a picture box. - To do this, I bitblt...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.