//--------------------------------------------------------------------------- #include #include #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } TBitmap *bmp; float p,r,r0,r1,dpi,rate,rate_res,res_w,res_h; TRect rect,p_rect; int change; int size_h,size_w,pixel; int X,Y; //--------------------------------------------------------------------------- void disp() { int w,h,off_w,off_h,H; Form1->Image1->Picture = NULL; if(change ==0) { r=(float) Form1->Panel2->Height/(float)bmp->Height; r1= (float) Form1->Panel2->Width/(float)bmp->Width; if(r>r1) { rate=r1; } else { rate=r; } p=20; Form1->ScrollBar1->Position=20; } else { p=Form1->ScrollBar1->Position; } h=bmp->Height*rate; w=bmp->Width*rate; if(p<0) { r=1/p*-1; } else { r=p/20; } if(r==0) r=1; off_w=(Form1->Image1->Width-w*r)/2; off_h=(Form1->Image1->Height-h*r)/2; rect.Top =off_h; rect.Left=off_w; Form1->Label1->Caption=FloatToStrF(r,ffFixed,15,2); r0=(float) res_h/(float)bmp->Height; r1= (float) res_w/(float)bmp->Width; if(r0>r1) { rate_res=r1; } else { rate_res=r0; } Form1->Label1->Caption = FloatToStrF((bmp->Width*rate_res*r/pixel),ffFixed,15,0); rect.Bottom =h*r+off_h; rect.Right=w*r+off_w; Form1->Image1->Canvas->StretchDraw(rect,bmp); } void Init() { float w; int dpi_x,dpi_y; int horzsize,vertsize,i; String s; Form1->Panel1->Caption=""; change=0; Form1->Image1->Picture = NULL; Form1->PrintDialog1->Execute(); TPrinter *printer=Printer(); HDC dc=printer->Handle; dpi_x=GetDeviceCaps(dc,LOGPIXELSX); // dpi_y=GetDeviceCaps(dc,LOGPIXELSY); horzsize=GetDeviceCaps(dc,HORZSIZE); vertsize=GetDeviceCaps(dc,VERTSIZE); Form1->Memo1->Clear(); s="LOGPIXELSX "+IntToStr(dpi_x); Form1->Memo1->Lines->Add(s); // s="LOGPIXELSY "+IntToStr(dpi_y); // Memo1->Lines->Add(s); size_w=GetDeviceCaps(dc,HORZSIZE); s="HORZSIZE "+IntToStr(size_w); Form1->Memo1->Lines->Add(s); size_h=GetDeviceCaps(dc,VERTSIZE); s="VERTSIZE "+IntToStr(size_h); Form1->Memo1->Lines->Add(s); res_w=GetDeviceCaps(dc,HORZRES); s="HORZRES "+FloatToStr(res_w); Form1->Memo1->Lines->Add(s); res_h=GetDeviceCaps(dc,VERTRES); s="VERTRES "+FloatToStr(res_h); Form1->Memo1->Lines->Add(s); pixel =res_w/size_w; rate=300/res_w; w=300*(res_h/res_w); Form1->Panel1->Top=15; Form1->Panel2->Top=15; Form1->Panel1->Left=10; Form1->Panel2->Left=Form1->Panel1->Width+20; Form1->Panel1->Height= (int) w; Form1->Panel1->Width=300; Form1->Image1->Align=alClient; Form1->Width=300+Form1->Panel1->Width; Form1->Height=500; Form1->Panel2->Left=Form1->Panel1->Width+20; disp(); } void loard_clipbord() { int flg; String ws,hs; delete bmp; bmp = new Graphics::TBitmap(); if(Clipboard()->HasFormat(CF_PICTURE) ) { bmp->Assign(Clipboard()); Form1->Image1->Picture->Assign(bmp); Screen->Cursor=crHourGlass; Form1->Image1->Stretch = false; Form1->Image1->Visible=false; Form1->Image1->Stretch = false; Form1->Image1->Visible=true; hs=" H"+IntToStr(Form1->Image1->Picture->Bitmap->Height); ws=" x W"+IntToStr(Form1->Image1->Picture->Bitmap->Width); Form1->Caption = "ClipBoard"+hs+" "+ws; Screen->Cursor=crDefault; X=Form1->Image1->Picture->Bitmap->Width; Y=Form1->Image1->Picture->Bitmap->Height; } else { ShowMessage("ClipBoradにデータがありません"); Form1->Close(); } } void __fastcall TForm1::Button3Click(TObject *Sender) { Close(); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { Init(); // ݒ } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { int x,y,h,w,off_w,off_h; Screen->Cursor=crHourGlass; off_w=(res_w-bmp->Width*rate_res*r)/2; off_h=(res_h-bmp->Height*rate_res*r)/2; p_rect.Top=off_h; p_rect.left=off_w; p_rect.Right=bmp->Width*rate_res*r+off_w; p_rect.Bottom=bmp->Height*rate_res*r+off_h; Printer()->BeginDoc(); Printer()->Canvas->StretchDraw(p_rect,bmp); h=(p_rect.Bottom-p_rect.Top)/30; w=(p_rect.Right-p_rect.left)/30; Printer()->EndDoc(); Screen->Cursor=crDefault; } //--------------------------------------------------------------------------- void __fastcall TForm1::FormActivate(TObject *Sender) { Form1->Panel2->Caption=""; loard_clipbord(); Init(); // ݒ } //--------------------------------------------------------------------------- void __fastcall TForm1::ScrollBar1Change(TObject *Sender) { change=255; disp(); } //---------------------------------------------------------------------------