如何抓到“当前活动窗体”(一定要包括标题栏) (200分)

G

gxcooo

Unregistered / Unconfirmed
GUEST, unregistred user!
我能抓到窗体内的图象,就是抓不到[red]标题栏和菜单[/red],但snagit能办到,何解?
ActiveWnd := GetForegroundWindow;

if ActiveWnd <> NULL then
begin
Form1.Image1.Picture.Bitmap := nil;
//Windows.GetWindowRect(ActiveWnd, Rect);//这个也不行
Windows.GetClientRect(ActiveWnd, Rect);//只能得到窗体内的图象,得不到标题栏
ScreenPic.Width := Rect.Right - Rect.Left;
ScreenPic.Height := Rect.Bottom - Rect.Top;
Image1.Width := Rect.Right - Rect.Left;
Image1.Height := Rect.Bottom - Rect.Top;
BitBlt(ScreenPic.Canvas.handle, 0, 0, ScreenPic.Width, ScreenPic.Height, GetDc(ActiveWnd), 0, 0, SRCCOPY);

Form1.Image1.Picture.Bitmap := ScreenPic;
end;
Form1.WindowState := wsNormal; //复原窗口状态
Form1.show; //显示窗口
 
var
dc: HDC;
h: THandle;
Rct: TRect;
begin
h := getforegroundwindow;
getwindowrect(h, rct);
offsetrect(rct, -rct.left, -rct.top);
dc := getwindowdc(h);
with image1.picture.bitmap do
begin
width := rct.right;
height := rct.bottom;
bitblt(canvas.handle, 0, 0, width, height, dc, 0, 0, SRCCOPY);
end;
releasedc(h, dc);
end;
 
我只知道Alt+Print Screen键能抓。可以模拟按键.
 
我有一个源程序,它可以实现多种抓图方式,如同HprSnap,要吗?
toli1226@163.com
 
procedure ScreenShotActiveWindow(Bild: TBitMap);
var
c: TCanvas;
r, t: TRect;
h: THandle;
begin
c := TCanvas.Create;
c.Handle := GetWindowDC(GetDesktopWindow);
h := GetForeGroundWindow;
if h <> 0 then
GetWindowRect(h, t);
try
r := Rect(0, 0, t.Right - t.Left, t.Bottom - t.Top);
Bild.Width := t.Right - t.Left;
Bild.Height := t.Bottom - t.Top;
Bild.Canvas.CopyRect(r, c, t);
finally
ReleaseDC(0, c.Handle);
c.Free;
end;
end;
 
我要的是可以抓到 [red]标题栏和菜单[/red] 的 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
接受答案了.
 
顶部