//用BITBLT函数实现位图拷贝(即窗口抓图)
var
HDCScreen : HDC;
iWidth,iHeight : Integer;
tmpRect : TRect; //位图区域procedure CaptureControl;//抓图过程
begin
NoWait := True;
//获得图像的矩形区域和句柄
if FormMain.Pop_VideoWin.Checked = True then
begin
tmpRect := FormMovie.Panel1.ClientRect;
HDCScreen := GetDC(FormMovie.Panel1.Handle);
end
else if FormMain.Pop_FlashWin.Checked = True then
begin
tmpRect := FormFlashPlayer.ShockwaveFlash1.ClientRect;
HDCScreen := GetDC(FormFlashPlayer.Panel2.Handle);
end
else if FormMain.Pop_RealWin.Checked = True then
begin
tmpRect := FormRealPlayer.RealAudio1.ClientRect;
HDCScreen := GetDC(FormRealPlayer.Panel2.Handle);
end
else if FormMain.Pop_FullDisplayWin.Checked = True then
begin
tmpRect := Rect(0,0,Screen.Width,Screen.Height);
HDCScreen := GetDc(GetDesktopWindow);
end
else
begin
NoWait := False;
while not NoWait do
begin
FormMain.Timer_Capture.Enabled := True;
if (Getkeystate(VK_LBUTTON) > 0) or (Getkeystate(VK_RBUTTON) > 0) then
begin
GetCursorPos(P1);
tmpHWND := WindowFromPoint(P1);
GetWindowRect(tmpHWND, tmpRect);
HDCScreen := GetDc(tmpHWND);
FormMain.Timer_Capture.Enabled := False;
NoWait := True;
end;
end;
end;
//建立位图
tmpBitmap :=TBitmap.Create;
iWidth := tmpRect.Right-tmpRect.Left;
iHeight := tmpRect.Bottom-tmpRect.Top;
tmpBitmap.Width := iWidth;
tmpBitmap.Height := iHeight;
iBitmapValide := True;
//复制窗口矩形区域到位图中
Bitblt(tmpBitmap.Canvas.Handle,0,0,iWidth,iHeight,
HDCScreen,tmpRect.Left,tmpRect.Top, SRCCOPY);
//释放句柄
if FormMain.Pop_VideoWin.Checked = True then
begin
ReleaseDC(FormMovie.Panel1.Handle,HDCScreen);
end
else if FormMain.Pop_FlashWin.Checked = True then
begin
ReleaseDC(FormFlashPlayer.Panel2.Handle,HDCScreen);
end
else if FormMain.Pop_RealWin.Checked = True then
begin
ReleaseDC(FormRealPlayer.Panel2.Handle,HDCScreen);
end
else if FormMain.Pop_FullDisplayWin.Checked = True then
begin
ReleaseDC(GetDesktopWindow, HDCScreen);
end
else
begin
ReleaseDC(tmpHWND, HDCScreen);
FormMain.Timer_Capture.Enabled := False;
end;
end;
为什么我只能抓到第一个MEDIAPLAYER文件的电影图,而其他的只能抓到播放器边框的图(即抓到的播放器窗口里是黑屏,就和没播放电影一样)?请大侠们指教
var
HDCScreen : HDC;
iWidth,iHeight : Integer;
tmpRect : TRect; //位图区域procedure CaptureControl;//抓图过程
begin
NoWait := True;
//获得图像的矩形区域和句柄
if FormMain.Pop_VideoWin.Checked = True then
begin
tmpRect := FormMovie.Panel1.ClientRect;
HDCScreen := GetDC(FormMovie.Panel1.Handle);
end
else if FormMain.Pop_FlashWin.Checked = True then
begin
tmpRect := FormFlashPlayer.ShockwaveFlash1.ClientRect;
HDCScreen := GetDC(FormFlashPlayer.Panel2.Handle);
end
else if FormMain.Pop_RealWin.Checked = True then
begin
tmpRect := FormRealPlayer.RealAudio1.ClientRect;
HDCScreen := GetDC(FormRealPlayer.Panel2.Handle);
end
else if FormMain.Pop_FullDisplayWin.Checked = True then
begin
tmpRect := Rect(0,0,Screen.Width,Screen.Height);
HDCScreen := GetDc(GetDesktopWindow);
end
else
begin
NoWait := False;
while not NoWait do
begin
FormMain.Timer_Capture.Enabled := True;
if (Getkeystate(VK_LBUTTON) > 0) or (Getkeystate(VK_RBUTTON) > 0) then
begin
GetCursorPos(P1);
tmpHWND := WindowFromPoint(P1);
GetWindowRect(tmpHWND, tmpRect);
HDCScreen := GetDc(tmpHWND);
FormMain.Timer_Capture.Enabled := False;
NoWait := True;
end;
end;
end;
//建立位图
tmpBitmap :=TBitmap.Create;
iWidth := tmpRect.Right-tmpRect.Left;
iHeight := tmpRect.Bottom-tmpRect.Top;
tmpBitmap.Width := iWidth;
tmpBitmap.Height := iHeight;
iBitmapValide := True;
//复制窗口矩形区域到位图中
Bitblt(tmpBitmap.Canvas.Handle,0,0,iWidth,iHeight,
HDCScreen,tmpRect.Left,tmpRect.Top, SRCCOPY);
//释放句柄
if FormMain.Pop_VideoWin.Checked = True then
begin
ReleaseDC(FormMovie.Panel1.Handle,HDCScreen);
end
else if FormMain.Pop_FlashWin.Checked = True then
begin
ReleaseDC(FormFlashPlayer.Panel2.Handle,HDCScreen);
end
else if FormMain.Pop_RealWin.Checked = True then
begin
ReleaseDC(FormRealPlayer.Panel2.Handle,HDCScreen);
end
else if FormMain.Pop_FullDisplayWin.Checked = True then
begin
ReleaseDC(GetDesktopWindow, HDCScreen);
end
else
begin
ReleaseDC(tmpHWND, HDCScreen);
FormMain.Timer_Capture.Enabled := False;
end;
end;
为什么我只能抓到第一个MEDIAPLAYER文件的电影图,而其他的只能抓到播放器边框的图(即抓到的播放器窗口里是黑屏,就和没播放电影一样)?请大侠们指教
这需要DirectX的Hook技术,比较复杂
具体方法需有偿提供,呵呵~