13,825
社区成员
发帖
与我相关
我的任务
分享
void __fastcall TfrmGenerator::tmrTimer(TObject *Sender)
{
HDC hdc1,hdc2;
TRect rect;
//sgTable是一个TStringGrid控件
rect = sgTable->ClientRect;
//修正位置
rect.right -= 10;
rect.bottom -= 10;
TImage *img;
//定义
img = new TImage(NULL);
img->Picture = NULL;
//改变bmp大小
img->Picture->Bitmap->Width = rect.right - rect.left;
img->Picture->Bitmap->Height = rect.bottom - rect.top;
//要截取的目标
hdc1 = GetDC(GetActiveWindow());
hdc2 = img->Canvas->Handle;
//删掉线
sgTable->GridLineWidth = 0;
//截取
BitBlt(hdc2,0,0,rect.Width(),rect.Height(),hdc1,sgTable->Left + 10,sgTable->Top + 10,SRCCOPY);
//重新添加StringGrid的线
sgTable->GridLineWidth = 1;
//重新实现图片的画线
if(Color != NULL){
RedrawTable(img,rect,sgTable->ColCount - 1,ScreenHeight / RowHeight ,sgTable->ColWidths[1] + 1,sgTable->RowHeights[1] + 1);
}
img->Picture->SaveToFile(FileName);
//清空指针
delete img;
Close();
}
hdc1 = Form2->img1->Canvas->Handle ; //GetDC(GetActiveWindow());
不能用GetActiveWindow这个了。我是用的图片测试的,你就直接用数据表所在窗体的句柄就可以了