Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To Use Secondary TForm As Screenshot Capture Area?

Status
Not open for further replies.

webowner47

Programmer
Nov 26, 2018
16
DZ
Hello,
I'm using the code below to capture desktop screen, but the problem is that the screenshot is taken from the MainForm, and i want to take it from the Secondary TForm instead:


Code:
TBitmap* __fastcall TCaptureContainer::CaptureImage()
{
    HDC hdcDesk;
	try
	{
		this->bitbmp->Width  = Screen->Width;
		this->bitbmp->Height = Screen->Height;
		hdcDesk     = GetDC(GetDesktopWindow());
		if ( BitBlt(this->bitbmp->Canvas->Handle, 0, 0, Screen->Width, Screen->Height, hdcDesk, 0, 0, SRCCOPY) ) {
			this->CaptureViewer->Picture->Bitmap = this->bitbmp;
		}
	}
	__finally
	{
		ReleaseDC(GetDesktopWindow(), hdcDesk);
	}
	return this->bitbmp;
}

this is the dynamic TForm with TImage and TTimer:

Code:
__fastcall TCaptureContainer::TCaptureContainer()
{
    // Capture Container
	this->CaptureContainer = new TForm(NULL, 0);
	this->CaptureContainer->Parent = NULL;
    this->CaptureContainer->DoubleBuffered = true;
	this->CaptureContainer->BorderStyle = bsSizeable;
	this->CaptureContainer->Position    = poScreenCenter;
	this->CaptureContainer->Width       = 389;
	this->CaptureContainer->Height      = 226;
	this->CaptureContainer->Color       = clBlack;
    this->CaptureContainer->OnClose     = this->CaptureContainerClose;
	this->CaptureContainer->Show();
	// Capture Viewer
	this->CaptureViewer = new TImage(this->CaptureContainer);
	this->CaptureViewer->Parent = this->CaptureContainer;
	this->CaptureViewer->Align  = alClient;
	this->CaptureViewer->Center = true;
	this->CaptureViewer->Show();
	// Capture Streamer
	this->CaptureStreamer = new TTimer(this->CaptureContainer);
	this->CaptureStreamer->Interval = 1;
    this->CaptureStreamer->Enabled  = true;
	this->CaptureStreamer->OnTimer  = this->CaptureStreamerOnTimer;
	// Bitmap
    this->bitbmp = new TBitmap();
}




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top