Process name: CreateBMPFromWindow
Function: Obtain an image of a window with a handle of Hwnd.
Parameter: Hwnd: Form handle
PicBitNum: number of digits of the image)
Returned value: TBitmap Function CreateBMPFromWindow (Hwnd: THandle; PicBitNum: Byte): TBitmap;
{Create an empty Bitmap}
Function CreateDibBMP (Dc: HDC; width, height: Integer): HBITMAP;
Type
DibRec = record
Bi: BITMAPINFOHEADER;
Ct: array [0 .. 255] of DWORD;
End;
Var
Dib: DibRec;
LpBits: pointer;
Temp: TBitmapInfo;
Begin
Dib. bi. biSize: = sizeof (BITMAPINFOHEADER );
Dib. bi. biWidth: = width;
Dib. bi. biHeight: = height;
Dib. bi. biBitCount: = PicBitNum;
Dib. bi. biPlanes: = 1;
Dib. bi. biCompression: = 0;
Dib. bi. biSizeImage: = 0;
Dib. bi. biClrUsed: = 0;
If PicBitNum = 15 then
Dib. bi. biBitCount: = 16
Else if PicBitNum = 16 then
Begin
Dib. bi. biCompression: = BI_BITFIELDS;
Dib. ct [0]: = $ F800;
Dib. ct [1]: = $07E0;
Dib. ct [2]: = $ 001F;
End;
Move (dib, temp, SizeOf (dib ));
Result: = CreateDIBSection (Dc, temp, DIB_RGB_COLORS, lpBits, 0, 0 );
End;
VaR
RC: trect;
X, Y, CX, Cy: integer;
Hdcscreen, hdcmemory: HDC;
Begin
Getwindowrect (hwnd, RC );
X: = RC. Left;
Y: = RC. Top;
CX: = RC. Right-RC. Left;
Cy: = RC. Bottom-RC. Top;
Hdcscreen: = getdc (0 );
Hdcmemory: = createcompatibledc (0 );
Result: = tbitmap. Create;
Result. Handle: = createdibbmp (hdcscreen, CX, CY );
SelectObject (hdcmemory, result. Handle );
Bitblt (hdcmemory, 0, 0, CX, Cy, hdcscreen, X, Y, srccopy );
Deletedc (hdcmemory );
Releasedc (0, hdcscreen );
End;