//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Viewer.h" #include "common.h" #include "jpeg.hpp" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_VIEWER StringTable[0] #define IDS_COPY StringTable[1] #define IDS_SAVE StringTable[2] //--------------------------------------------------------------------------- TViewer_F *Viewer_F; //--------------------------------------------------------------------------- __fastcall TViewer_F::TViewer_F(TComponent* Owner) : TForm(Owner) { clickx=0; clicky=0; cursor = Cursor; } //--------------------------------------------------------------------------- void __fastcall TViewer_F::ImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { clickx=X; clicky=Y; cursor = Cursor; if(Button==mbLeft) Screen->Cursor=crSizeAll; } //--------------------------------------------------------------------------- void __fastcall TViewer_F::ImageMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { Left+=X-clickx; Top+=Y-clicky; Screen->Cursor=cursor; } //--------------------------------------------------------------------------- void __fastcall TViewer_F::FormCreate(TObject *Sender) { SetFont(); StringTable.Create(BaseDir, Language, "Viewer"); Caption=IDS_VIEWER; pmvToClipBoard->Caption=IDS_COPY; pmvSave->Caption=IDS_SAVE; SavePictureDialog->InitialDir=BaseDir+"\\bmp"; SavePictureDialog->DefaultExt = "bmp"; SavePictureDialog->FileName = "Noname1"; SavePictureDialog->Filter="Bitmaps (*.bmp)|*.bmp|JPEG Image File (*.jpg)|*.jpg"; } //--------------------------------------------------------------------------- void __fastcall TViewer_F::SetFont() { SetSmallFont(Font); } //--------------------------------------------------------------------------- void __fastcall TViewer_F::pmvToClipBoardClick(TObject *Sender) { BITMAPHANDLE bh; HDC dcSrc = NULL, dcDst = NULL; memset(&bh, 0, sizeof(BITMAPHANDLE)); L_CreateBitmap(&bh, TYPE_CONV, Image->Width, Image->Height, 24, ORDER_BGR, NULL, TOP_LEFT); dcDst = L_CreateLeadDC(&bh); dcSrc = Image->Picture->Bitmap->Canvas->Handle; BitBlt(dcDst, 0, 0, Image->Width, Image->Height, dcSrc, 0, 0, SRCCOPY); L_DeleteLeadDC(dcDst); dcDst = NULL; L_CopyToClipboard(Handle, &bh); L_FreeBitmap(&bh); } //--------------------------------------------------------------------------- void __fastcall TViewer_F::pmvSaveClick(TObject *Sender) { if (SavePictureDialog->Execute()) { if(SavePictureDialog->FilterIndex==1){ Image->Picture->Bitmap->SaveToFile(SavePictureDialog->FileName); } else if(SavePictureDialog->FilterIndex==2){ TJPEGImage *jp = new TJPEGImage(); try { jp->Assign(Image->Picture->Bitmap); jp->SaveToFile(SavePictureDialog->FileName); } __finally { delete jp; } } } } //---------------------------------------------------------------------------