procedure TForm1.GetActiveWndImg;
var C: TCanvas; b: TBitmap; H: HDC; R: TRect; hand: THandle;
p: TPoint;
J: TJpegImage;
m, n: INTEGER;
name: array[0..255] of char;
begin
B := TBitmap.Create;
C := TCanvas.Create;
GetCurSorPos(P); //取得鼠标所在区域坐标
Hand := WindowFromPoint(P); //取得坐标所在窗体句柄
FillChar(name, SizeOf(name), #0); //
GetWindowText(Hand, name, 255); // 取得窗口标题
if name = '' then CopyMemory(@name, PCHAR(inttostr(hand)), Length(inttostr(hand)) + 1); //用句柄
if hand = 0 then exit;
H := GetWindowDC(Hand); //获取整个窗口(包括边框、滚动条、标题栏、菜单等)的设备场景 返回值 Long
try
GetWindowRect(hand, R); //取得句柄对应窗体的矩形区域
B.Width := R.Right - R.Left;
B.Height := R.Bottom - R.Top;
C.Handle := H; //将描述表赋给画布的句柄,此时画布就代表整个屏幕了
B.Canvas.CopyRect(Rect(0, 0, B.Width, B.Height), C, Rect(0, 0, B.Width, B.Height));
//Image1.Picture.Bitmap.Assign(B);
finally
C.Free;
B.Free;
ReleaseDC(Hand, H); //释放设备上下文环境
end;
end;
以前写的一个类似软件