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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to copy the desktop into an image control

Status
Not open for further replies.

hennep

Programmer
Dec 10, 2000
429
I tried to capture the desktop into an TImage control using this code:
Code:
void __fastcall TForm1::FormCreate(TObject *Sender) {
    HANDLE h1, h2;
    long w, h;
    RECT rect;

    GetWindowRect( GetDesktopWindow(), &rect );
    w = rect.right - rect.left;
    h = rect.bottom - rect.top;

    h1 = GetDC( GetDesktopWindow() );
    h2 = GetDC( Image1->Picture->Bitmap->Handle );
    BitBlt( h2, 0, 0, w, h, h1, 0, 0, SRCCOPY );
}
But I definitely don't know what i am doing. Why doesn't it work ?
 
I don't know what are you doing with that code too, but I think you should investigate about Keyboard key that copies the screen into the Clipboard and then copy it to the control.

--- LastCyborg ---
 
hi LastCyborg,

I cannot use the clipboard. The code is part of a screen saver, it would change the contents of the clipboard every time the screensaver was executed.
 
Well, you can save it contents in a temporal identifier, and load the clippboard with the last value after you finish what you are doing.

--- LastCyborg ---
 
What happens with this code you posted?
How is SRCCOPY defined?
Plopping to the clippboard each time would be a bad way to do that.
 
hi Tom,

Did you get this to work?
The first code snippet on the codeproject page results in a handle to the bitmap. But how would you show the bitmap in a TPicture control or the canvas of a form?
 
I wrote "TPicture", but I meant a TImage.
I just saw that there is such a thing as a TPicture but I've never used it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top