本文介绍了如何在位图上绘制整个表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 TBitmap
对象上绘制包括标题栏和框架在内的整个表单。
I want to paint the whole form including its caption bar and frame on a TBitmap
object.
GetFormImage
很酷,但是有两个问题:
GetFormImage
is cool, but it has two problems:
- 它也不会绘制窗口框。
- 隐藏表单时不起作用。
有解决这些问题的想法吗?
Do you have any idea to workaround these problems?
推荐答案
访问非客户区的关键是函数,其他所有操作均像往常一样:
The key to accessing non-client area is GetWindowDC
function, everything else is blitting as usual:
procedure TForm5.FormClick(Sender: TObject);
var
Bitmap: TBitmap;
DC: HDC;
FileName: string;
begin
Bitmap := TBitmap.Create;
try
Assert(HandleAllocated);
DC := GetWindowDC(Handle);
Win32Check(DC <> 0);
Bitmap.SetSize(Width, Height);
Win32Check(BitBlt(Bitmap.Canvas.Handle, 0, 0, Width, Height, DC, 0, 0, SRCCOPY));
FileName := Name + '.' + GraphicExtension(TBitmap);
Bitmap.SaveToFile(FileName);
ShellExecute(HWND_DESKTOP, nil, PChar(FileName), nil, nil, SW_NORMAL);
finally
ReleaseDC(Handle, DC);
Bitmap.Free;
end;
end;
对于第二种隐藏(未绘制!)窗口-请参阅RRUZ的评论。
For the second case of hidden (not painted!) window - see a comment from RRUZ.
这篇关于如何在位图上绘制整个表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!