Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: VCL Screen snapshot getting black or white bitmap


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Feb 20, 2017 7:42 PM Last Post By: Brett Wilton
Brett Wilton

Posts: 45
Registered: 10/1/11
VCL Screen snapshot getting black or white bitmap  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 19, 2017 8:08 PM
I'm using RadStudio Pro 10.1.2 and have been trying to get an automatic snap shot of my application.

This is working on Window 10 but not on a server running Win Server 2008 R2 Standard Service pack 1.

The Code (C++ function in this case) :-
TRect SrcR;
SrcR.Left = PageControl->Pages[0]->Left + WView::Get()->SnapLeft;
SrcR.Top = PageControl->Pages[0]->Top + WView::Get()->SnapTop;
SrcR.Right = width;
SrcR.Bottom = height;

TImage* Dest = new TImage(this);
Dest->Width = DestR.Width();
Dest->Height = DestR.Height();
Dest->Canvas->CopyRect(DestR, PageControl->Canvas, SrcR);

Works until I quit RDP, from that point on it gets a white image and some text I overlay on it.

I have tried many tests in setting foreground, restore, repaint etc but no luck under win2008.

I have tried the PrintWindow function but this gets a black image when exited RDP and my overlay text.

// reference
// http://stackoverflow.com/questions/27024554/capture-screenshot-from-selected-minimized-window
function WindowSnap(hWindow: HWND; bmp: TBitmap): boolean;
var
user32DLLHandle: THandle;
printWindowAPI: function(sourceHandle: HWND; destinationHandle: HDC; nFlags: UINT): BOOL; stdcall;
R: TRect;
wp: WINDOWPLACEMENT;
ai: ANIMATIONINFO;
restoreAnimation: Boolean;
ExStyle: LONG_PTR;
begin
Result := False;
ExStyle := 0;
user32DLLHandle := GetModuleHandle(user32) ;
if user32DLLHandle <> 0 then
begin
@printWindowAPI := GetProcAddress(user32DLLHandle, 'PrintWindow') ;
if @printWindowAPI <> nil then
begin
if not IsWindow(hWindow) then Exit;

ZeroMemory(@wp, SizeOf(wp));
wp.length := SizeOf(wp);
GetWindowPlacement(hWindow, @wp);

I also tried the BitBlit Remey suggested on that stackoverflow post but again no luck.

Anyone have an idea how to get a screen shot to work when RDP exits on a Win2008 R2 Server ?

Any help appreciated.

Edited by: Brett Wilton on Feb 19, 2017 9:01 PM

Edited by: Brett Wilton on Feb 19, 2017 9:02 PM
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: VCL Screen snapshot getting black or white bitmap [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 20, 2017 10:27 AM   in response to: Brett Wilton in response to: Brett Wilton
Brett Wilton wrote:

I'm using RadStudio Pro 10.1.2 and have been trying to get an
automatic snap shot of my application.

This is working on Window 10 but not on a server running Win Server
2008 R2 Standard Service pack 1.

what do you expect? If you are not connected to the server in a RDP
session there simply is no desktop for your application to render
itself to! You should not use an application with a UI on such a
server, such machines are intended to run services and other non-UI
processes.


Anyone have an idea how to get a screen shot to work when RDP exits
on a Win2008 R2 Server ?

Have you tried the PrintTo method, passing it a bitmap.Canvas?


--
Peter Below
TeamB

Brett Wilton

Posts: 45
Registered: 10/1/11
Re: VCL Screen snapshot getting black or white bitmap [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 20, 2017 12:49 PM   in response to: Peter Below in response to: Peter Below
Peter Below wrote:
what do you expect? If you are not connected to the server in a RDP
session there simply is no desktop for your application to render
itself to! You should not use an application with a UI on such a
server, such machines are intended to run services and other non-UI
processes.

What did I expect? Hmmmh, well my experience with MS Windows for 27 years has proven with Windows to expect the unexpected and nothing will be simple.

Our software is required to genereate images every minute and runs correctly under Win10 and surprise OSX Wine. I haven't tested on other Win OS's till this one but I expected, well hoped, it may work in the same vain but so far this is not the case. I do understand the difference in OS intended purpose.

The user is not logged off when stopping the RDP session so I had hoped it would continue operating like any normal application.

In fact this is the case apart from the images produced are either white or black.

Well my additional text overlay also displays correct giving time of image generation.

Not sure if there is a mechanism to draw into a bitmap rather than the PageControl, that would be nice.

Have you tried the PrintTo method, passing it a bitmap.Canvas?

I'll give it a try

Edited by: Brett Wilton on Feb 20, 2017 12:50 PM

Edited by: Brett Wilton on Feb 20, 2017 12:50 PM
Brett Wilton

Posts: 45
Registered: 10/1/11
Re: VCL Screen snapshot getting black or white bitmap  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 20, 2017 7:42 PM   in response to: Brett Wilton in response to: Brett Wilton
Ok it took a while to workout a solution.

It comes down to the exit machanism from the RDP session. Redirecting to console using tscon command is the solution.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02