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. 7 2435
Hi,
Post your code
Ken
---------------------
"VB Programmer" <gr*********@ go-intech.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.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.
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(By Val strFileName As String, ByVal IsKnob As
Boolean)
Try
Dim MyBitmap As Bitmap
Dim MyForm As frmMain
If IsKnob Then
MyBitmap = CaptureControl( MyFrmMain.panKn ob)
Else
MyBitmap = CaptureControl( MyFrmMain.panSl ider)
End If
MyBitmap.Save(s trFileName, Imaging.ImageFo rmat.Jpeg)
Catch ex As Exception
HandleError(ex, "CaptureGau ge")
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.CreateGraphic s
Try
gDest = Graphics.FromIm age(bmp)
Try
hdcSource = gSource.GetHdc
Try
hdcDest = gDest.GetHdc
Try
BitBlt( _
hdcDest, 0, 0, _
c.Width, c.Height, _
hdcSource, 0, 0, SRCCOPY _
)
Finally
gDest.ReleaseHd c(hdcDest)
End Try
Finally
gSource.Release Hdc(hdcSource)
End Try
Finally
gDest.Dispose()
End Try
Finally
gSource.Dispose ()
End Try
Return bmp
End Function
"Ken Tucker [MVP]" <vb***@bellsout h.net> wrote in message
news:eR******** ******@TK2MSFTN GP11.phx.gbl... Hi,
Post your code
Ken --------------------- "VB Programmer" <gr*********@ go-intech.com> wrote in message news:%2******** ********@TK2MSF TNGP10.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.
Hi,
Are you getting an error ?
Declare Function GetLastError Lib "kernel32" Alias "GetLastErr or" () 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(F ORMAT_MESSAGE_F ROM_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******** ******@tk2msftn gp13.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(By Val strFileName As String, ByVal IsKnob As Boolean) Try Dim MyBitmap As Bitmap Dim MyForm As frmMain
If IsKnob Then MyBitmap = CaptureControl( MyFrmMain.panKn ob) Else MyBitmap = CaptureControl( MyFrmMain.panSl ider) End If MyBitmap.Save(s trFileName, Imaging.ImageFo rmat.Jpeg)
Catch ex As Exception HandleError(ex, "CaptureGau ge") 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.CreateGraphic s Try gDest = Graphics.FromIm age(bmp) Try hdcSource = gSource.GetHdc Try hdcDest = gDest.GetHdc Try BitBlt( _ hdcDest, 0, 0, _ c.Width, c.Height, _ hdcSource, 0, 0, SRCCOPY _ ) Finally gDest.ReleaseHd c(hdcDest) End Try Finally gSource.Release Hdc(hdcSource) End Try Finally gDest.Dispose() End Try Finally gSource.Dispose () End Try Return bmp End Function
"Ken Tucker [MVP]" <vb***@bellsout h.net> wrote in message news:eR******** ******@TK2MSFTN GP11.phx.gbl... Hi,
Post your code
Ken --------------------- "VB Programmer" <gr*********@ go-intech.com> wrote in message news:%2******** ********@TK2MSF TNGP10.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. > >
On 2004-02-07, Ken Tucker [MVP] <vb***@bellsout h.net> wrote: Hi,
Are you getting an error ?
Declare Function GetLastError Lib "kernel32" Alias "GetLastErr or" () 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(F ORMAT_MESSAGE_F ROM_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******** ******@tk2msftn gp13.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.GetLast Win32Error().
And the calls to format message are not needed either. Just create an
instance of System.Componen tModel.Win32Exc eption and then look at the
..Message property...
' BitBlt code...
If intRetun = 0 Then
Dim ex As New Win32Exception( Marshal.GetLast Win32Error())
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
"Ken Tucker [MVP]" <vb***@bellsout h.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
Hi,
Much better method.
Ken
------------------
"Tom Shelton" <to*@mtogden.co m> wrote in message
news:%2******** *******@TK2MSFT NGP11.phx.gbl.. . On 2004-02-07, Ken Tucker [MVP] <vb***@bellsout h.net> wrote: Hi,
Are you getting an error ?
Declare Function GetLastError Lib "kernel32" Alias "GetLastErr or" () 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(F ORMAT_MESSAGE_F ROM_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******** ******@tk2msftn gp13.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.GetLast Win32Error(). And the calls to format message are not needed either. Just create an instance of System.Componen tModel.Win32Exc eption and then look at the .Message property...
' BitBlt code... If intRetun = 0 Then Dim ex As New Win32Exception( Marshal.GetLast Win32Error()) 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
Thanks everyone I will try it today.
"Armin Zingler" <az*******@free net.de> wrote in message
news:us******** ******@TK2MSFTN GP12.phx.gbl... "Ken Tucker [MVP]" <vb***@bellsout h.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
These are some questions:-
7. design and implement a class binsearch for a binary search tree.it
includes search,remove and add options.make suitable assumption.
8.explai how pointers to functions can be declared in c++.under what
conditions can...
|
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 in the DataGrid-Cell's, but a
black background...
Does anybody has any idea what I am doing wrong?
Thanks a lot in advance,
|
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:
dstGr = args.graphics;
srcGr = Graphics.FromImage( bitmap );
dstHdc = dstGr.GetHdc();
srcHdc = srcGr.GetHdc();
BitBlt( dstHdc, x, y, width, height, srcHdc, 0, 0, rop );
What am I doing wrong? A complete demo program follows.
|
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 wrote the MFC app and the .NET control, so we can add hook functions
into either module if necessary.
The .NET control is hosted in the MFC app using the CWinFormsControl
template.
|
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 I am humbled without fail. This last project was/is especially painful ;)
Please visit this site: IdeaMill: tableFilter
This demo is a couple of months out of date, unfortunately, but it does demonstrate the specific problem I need your help...
| |
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 small, compilable and runnable program that shows the
|
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 another language:
"A call for the function PInvoke “GestCeph! GestCeph.Geral:: BitBlt”
unbalanced the stack. It is probable that the managed signature PInvoke does
not correspond to the signature of destination not managed. It verifies if...
|
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 form into a picture box.
- To do this, I bitblt using the device contexts of the form and a bitmap
object.
- After blitting, the bitmap image is always blank. I don't understand what
|
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 using the device contexts of the form and a bitmap object.
- After blitting, the bitmap image is always blank. I don't understand what I'm doing wrong here.
Here is my relevant code:
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |