336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
void __fastcall ScrollBoxPaintTo(TScrollBox *ScrollBox,HDC DC,int X,int Y,int Wid,int Hei) { int I, EdgeFlags, BorderFlags, SaveIndex; TRect R; ScrollBox->ControlState=ScrollBox->ControlState<< csPaintCopy; MoveWindowOrg(DC, X, Y); IntersectClipRect(DC, 0, 0, Wid, Hei); BorderFlags = 0; EdgeFlags = 0; if( GetWindowLong(ScrollBox->Handle, GWL_EXSTYLE) & WS_EX_CLIENTEDGE != 0 ) { EdgeFlags = EDGE_SUNKEN; BorderFlags = BF_RECT | BF_ADJUST; } else if( GetWindowLong(ScrollBox->Handle, GWL_STYLE) & WS_BORDER != 0 ) { EdgeFlags = BDR_OUTER; BorderFlags = BF_RECT | BF_ADJUST | BF_MONO; } if( BorderFlags !=0) { R=Rect( 0, 0, Wid, Hei); DrawEdge(DC, &R, EdgeFlags, BorderFlags); MoveWindowOrg(DC, R.Left, R.Top); IntersectClipRect(DC, 0, 0, R.Right - R.Left, R.Bottom - R.Top); } //일반 캡쳐의 경우 ... //scroll전체 캡쳐를 위해 빼버림 // ScrollBox->Perform(WM_ERASEBKGND, (int)DC, 0); // ScrollBox->Perform(WM_PAINT, (int)DC, 0); for ( int i=0;i< ScrollBox->ControlCount;i++) { if(ScrollBox->Controls[i]->Visible) { if(ScrollBox->Controls[i]->InheritsFrom(__classid(TWinControl))) { ((TWinControl *)ScrollBox->Controls[i])->PaintTo(DC,ScrollBox->Controls[i]->Left+ScrollBox->HorzScrollBar->Position ,ScrollBox->Controls[i]->Top+ScrollBox->VertScrollBar->Position); } else if(ScrollBox->Controls[i]->InheritsFrom(__classid(TGraphicControl))) { MoveWindowOrg(DC, ScrollBox->Controls[i]->Left+ScrollBox->HorzScrollBar->Position, ScrollBox->Controls[i]->Top+ScrollBox->VertScrollBar->Position); ((TGraphicControl *)ScrollBox->Controls[i])->Perform(WM_PAINT,(int)DC,0);// PaintTo(DC,ScrollBox->Controls[i]->Left+ScrollBox->HorzScrollBar->Position ,ScrollBox->Controls[i]->Top+ScrollBox->VertScrollBar->Position); MoveWindowOrg(DC, -ScrollBox->Controls[i]->Left-ScrollBox->HorzScrollBar->Position, -ScrollBox->Controls[i]->Top-ScrollBox->VertScrollBar->Position);//MoveWindowOrg(DC, R.Left, R.Top); } } } ScrollBox->ControlState=ScrollBox->ControlState>>csPaintCopy;// Exclude(FControlState, csPaintCopy); } Graphics::TBitmap * __fastcall GetScrollBoxImage(TScrollBox *ScrollBox) { if(ScrollBox==NULL)return NULL; Graphics::TBitmap *bmp=NULL; TRect rc=Rect(0,0,ScrollBox->HorzScrollBar->Range,ScrollBox->VertScrollBar->Range); bmp=new Graphics::TBitmap; bmp->Width=ScrollBox->HorzScrollBar->Range; //ScrollBox->ClientWidth; bmp->Height=ScrollBox->VertScrollBar->Range; //ScrollBox->ClientHeight; bmp->Canvas->Brush = ScrollBox->Brush; bmp->Canvas->FillRect(rc);//ScrollBox->ClientRect); bmp->Canvas->Lock(); try { int Ofs=0; if(GetWindowLong(ScrollBox->Handle, GWL_STYLE) & WS_BORDER ) Ofs = -1; // Don't draw form border else Ofs = 0; // There is no border ScrollBoxPaintTo(ScrollBox,bmp->Canvas->Handle,Ofs, Ofs, rc.right,rc.bottom); // ScrollBox->PaintTo(bmp->Canvas->Handle, Ofs, Ofs); } __finally { bmp->Canvas->Unlock(); } return bmp; } void __fastcall TForm3::Button5Click(TObject *Sender) { Graphics::TBitmap *bmp; bmp=GetScrollBoxImage(ScrollBox1); // bmp->SaveToFile("C:\\TestScrollBoxImage.bmp"); Image1->Picture->Bitmap->Assign(bmp); Image1->AutoSize=true; delete bmp; } //--------------------------------------------------------------------------- |
추가 08-11-25
procedure Tform1.PaintControl( aControl: TWinControl; aCanvas: TCanvas; offsetx, offsety: Integer ); begin SaveDC( aCanvas.handle ); try SetWindowOrgEx( aCanvas.handle, - (acontrol.left + offsetx), - (acontrol.top + offsety), nil ); acontrol.perform( WM_PRINT, acanvas.handle, PRF_CHILDREN or PRF_CLIENT or PRF_NONCLIENT or PRF_ERASEBKGND ); finally RestoreDC( aCanvas.handle, - 1 ); end; end; procedure Tform1.Button1Click(Sender: TObject); var bmp: TBitmap; i: integer; begin bmp := TBitmap.Create; try bmp.width := scrollbox1.HorzScrollBar.Range; bmp.height := scrollbox1.VertScrollBar.Range; bmp.canvas.lock; SetMapMode( bmp.canvas.handle, MM_ISOTROPIC ); SetWindowExtEx( bmp.canvas.handle, 400, 400, nil ); SetViewportExtEx( bmp.canvas.handle, 400, 400, nil ); try SetWindowOrgEx( bmp.canvas.handle, - scrollbox1.HorzScrollBar.Position, - scrollbox1.VertScrollBar.POsition, nil ); bmp.Canvas.Brush := scrollbox1.Brush; bmp.Canvas.FillRect(Rect(0,0,bmp.width,bmp.height)); scrollbox1.perform( WM_PAINT, bmp.canvas.handle, 1 ); SetWindowOrgEx( bmp.canvas.handle, 0, 0, nil ); for i := 0 to scrollbox1.controlcount - 1 do if scrollbox1.Controls[i] is TWincontrol then Paintcontrol(TWincontrol(scrollbox1.Controls[i]), bmp.canvas, scrollbox1.horzscrollBar.Position, scrollbox1.vertScrollBar.Position ); finally bmp.canvas.unlock; end; bmp.SaveToFile('c:\test.bmp'); finally bmp.free; end; end; |
추가 08-12-02
위 델파이 버젼 코드를 다시 좀 수정 했습니다.
다른사람코드를 거의 그대로 복사해 넣다보니 쓸데없는 부분이 좀 있네요
다음은 수정한 코드입니다.
function GetScrollBoxImage(ScrollBox:TScrollBox):TBitmap; var bmp: TBitmap; i: integer; wCtrl:TWinControl; function iMax(iVal1,iVal2:Integer):Integer; begin if iVal1>iVal2 then Result:=iVal1 else Result:=iVal2; end; begin Result:=nil; bmp := TBitmap.Create; // bitmap을 Scroll-Range 크기만하게 만들어준다. // Scroll-Range가 ScrollBox의 원래크기보다 작은경우가 잇으므로 Max값으로 한다. bmp.width := iMax(ScrollBox.HorzScrollBar.Range,ScrollBox.Width); bmp.height :=iMax(ScrollBox.VertScrollBar.Range,ScrollBox.Height); bmp.canvas.lock; //ScrollBox의 Brush를 이용해서 배경을 그려준다. bmp.Canvas.Brush := ScrollBox.Brush; bmp.Canvas.FillRect(Rect(0,0,bmp.width,bmp.height)); //ScrollBox의 이미지 즉 ScrollBox와 그위에 올려진 GraphicControl의 그린다. //그릴때 현재 ScrollBar의 위치만큼 DC의 Offset을 설정하고 그린다. SetWindowOrgEx( bmp.canvas.handle, - ScrollBox.HorzScrollBar.Position, - ScrollBox.VertScrollBar.POsition, nil ); ScrollBox.perform( WM_PAINT, bmp.canvas.handle, 0 ); //ScrollBox위에 모든 Window-Control을 그려준다. for i := 0 to ScrollBox.controlcount - 1 do begin if ScrollBox.Controls[i] is TWincontrol then begin wCtrl:=TWinControl(ScrollBox.Controls[i]); SaveDC( bmp.Canvas.Handle ); SetWindowOrgEx( bmp.Canvas.Handle, - (wCtrl.Left + ScrollBox.horzscrollBar.Position), - (wCtrl.Top + ScrollBox.vertScrollBar.Position), nil ); wCtrl.Perform(WM_PAINT,bmp.Canvas.Handle,0); RestoreDC(bmp.Canvas.Handle,-1 ); end; end; bmp.canvas.Unlock; Result:=Bmp; end; //사용예 procedure TForm1.Button2Click(Sender: TObject); var bmp:TBitmap; begin bmp:=GetScrollBoxImage(ScrollBox1); Image2.Picture.Bitmap.Assign(bmp); Image2.AutoSize:=true; bmp.free; end; |
[출처]
http://cafe.naver.com/bcbmaster.cafe?iframe_url=/ArticleRead.nhn%3Farticleid=759