Article View: borland.public.cppbuilder.nativeapi
Article #14910How to get image to buffer
From: Sky
Date: Sat, 26 Jul 2003 14:47
Date: Sat, 26 Jul 2003 14:47
48 lines
2220 bytes
2220 bytes
Hi all, I can use a thread retrieving desktop picture ceaselessly
and draw it on my form, but now i want send my desktop to another
computer on the network, so i want get the image buffer of desktop,
but i don't know how to do it, any hint will be great appreciated.
// My original code, it work ok
void __fastcall TMyGetScreen::Execute()
{
// MyCanvas = MainForm->PaintBox1->Canvas;
HDC hdc = GetDC(0); // Get desktop DC
using namespace std;
SetStretchBltMode(MyCanvas->Handle, HALFTONE);
while (!Terminated)
{
MyCanvas->Lock();
StretchBlt(MyCanvas->Handle, 0, 0, 320, 240, hdc, 0, 0, 1024, 768,
SRCCOPY);
Sleep(50);
MyCanvas->Unlock();
}
ReleaseDC(0, hdc);
}
// new code, it doesn't work, I cann't retrieve the buffer
void __fastcall TMyGetScreen::Execute()
{
HDC hdc = GetDC(0); // Get desktop DC
HBITMAP hbmp = CreateCompatibleBitmap(hdc, 1024, 768);
byte *buffer = new byte[1024*768*3];
BITMAPINFO bi;
ZeroMemory(&bi, sizeof(BITMAPINFO));
while (!Terminated)
{
GetDIBits(hdc, hbmp, 0, 768-1, buffer, &bi, DIB_RGB_COLORS);
// send buffer here
SendBuf(buffer, 1024, 768);
}
ReleaseDC(0, hdc);
DeleteObject(hbmp);
delete [] buffer;
}
Technical Details
Message-ID:
<3f229484@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,a4e18d70a3290c59,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-07-26 07:51:09 PST Reply-To: "Sky" <huangc913@msn.com> From: "Sky" <huangc913@msn.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: How to get image to buffer Date: Sat, 26 Jul 2003 22:47:33 +0800 Lines: 50 Organization: CK X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 220.113.162.152 Message-ID: <3f229484@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1059230852 220.113.162.152 (26 Jul 2003 07:47:32 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail