basic drag and drop implement using SetWindowLongPtr
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

151 lines
3.7 KiB

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "aviimage.h"
#include "AVIWrite.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
aviimage* work;
int iw,ih;
int start,fend;
void playbackavi(aviimage*,int,int);
void dispaframe(aviimage*, int);
//---------------------------------------------------------------------------
void __fastcall TForm1::WMDROPFILES(TWMDropFiles Msg)
{
int i;
char buf[MAX_PATH];
TRect f;
//int iw,ih;
//ドラッグされたファイルの個数
int cnt=::DragQueryFile((HDROP)Msg.Drop,0xFFFFFFFF,NULL,0);
for(int i=0;i<cnt;i++){
::DragQueryFile((HDROP)Msg.Drop, i,buf,sizeof(buf));
// bufにファイル名が入っている
Memo1->Lines->Add(AnsiString(buf));
if( ExtractFileExt(buf) == ".avi" ){
work = new aviimage(buf);
//f = AVIImage1->Frame;
f = work->getframerect();
iw = f.Width();
ih = f.Height();
start = work->getfirst();
fend = work->getlast();
Memo1->Lines->Add("Avi file: "+AnsiString(iw)+"x"+AnsiString(ih));
Memo1->Lines->Add("start: " + IntToStr(start) + "to " + IntToStr(fend));
TrackBar1->Min = start;
TrackBar1->Max = fend;
dispaframe(work,start);
//playbackavi(work,start,fend);
//playbackavi(work,start,end);
//delete work;
}
else if( ExtractFileExt(buf) == ".roi" ){
Memo1->Lines->Add("Roi file");
}
else if( ExtractFileExt(buf) == ".bmp" ){
Image1->Picture->LoadFromFile(buf);
}
}
}
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
DragAcceptFiles(Handle,True);
Memo1->Lines->Clear();
}
//---------------------------------------------------------------------------
void dispaframe(aviimage* avi,int framenum)
{
//TWICImage* twic = new TWICImage();
TImage* targeti;
TMemoryStream* temp = new TMemoryStream();
TBitmap* first = new TBitmap();
targeti = Form1->Image1;
targeti->Picture->Bitmap->PixelFormat=pf24bit; // should be 8bit
targeti->Width = iw;
targeti->Picture->Bitmap->Width = iw;
targeti->Height=ih;
targeti->Picture->Bitmap->Height = ih;
first->Width = iw;
first->Height = ih;
Form1->Label1->Caption = IntToStr(framenum);
avi->saveaframe(framenum,temp);
temp->Position = 0;
first->LoadFromStream(temp);
//targeti->Picture->Bitmap->LoadFromStream(temp);
Form1->Label2->Caption = IntToStr(first->Width);
Form1->Label3->Caption = IntToStr(first->Height);
Form1->Image1->Picture->Bitmap->Assign(first);
targeti->Refresh();
}
void playbackavi(aviimage* avi,int start, int end)
{
TWICImage* twic = new TWICImage();
TImage* targeti;
TMemoryStream* temp = new TMemoryStream();
targeti = Form1->Image1;
targeti->Picture->Bitmap->PixelFormat=pf24bit; // should be 8bit
targeti->Width = iw;
targeti->Picture->Bitmap->Width = iw;
targeti->Height=ih;
targeti->Picture->Bitmap->Height = ih;
for( int i = start ; i < end ; i++ ){
Form1->Label1->Caption = IntToStr(i);
dispaframe(avi,i);
//Application->ProcessMessages();
//targeti->Refresh();
//Form1->Invalidate();
}
}
void __fastcall TForm1::TrackBar1Change(TObject *Sender)
{
Label1->Caption = IntToStr(TrackBar1->Position);
Edit1->Text = IntToStr(TrackBar1->Position);
dispaframe(work,TrackBar1->Position);
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1Exit(TObject *Sender)
{
Label1->Caption = Edit1->Text;
TrackBar1->Position = StrToInt(Edit1->Text);
if( StrToInt(Edit1->Text) < fend )
dispaframe(work,StrToInt(Edit1->Text));
}
//---------------------------------------------------------------------------