Witam.
Używam oprogramowania Embarcadero C++Builder.
Ostatnio męczę się nad jedną funkcją, mianowicie nad "Drag and Drop Files into Form".
Przeczesałem już dużo internetu i dalej nie mogę znaleźć odpowiedzi na błędy bądź brak działania:
Plik *.h:
class TForm_Main : public TForm {
__published: // IDE-managed Components
// ...
private:
void virtual __fastcall WMDropFiles(TWMDropFiles &Message);
public:
__fastcall TForm_Main(TComponent* Owner);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_DROPFILES,TWMDropFiles,WMDropFiles);
END_MESSAGE_MAP (TForm);
};
Plik *.cpp:
TForm_Main *Form_Main;
//---------------------------------------------------------------------------
__fastcall TForm_Main::TForm_Main(TComponent* Owner)
: TForm(Owner) {
//
}
//---------------------------------------------------------------------------
void __fastcall TForm_Main::WMDropFiles(TWMDropFiles &Message) {
UINT FileCount = DragQueryFile((HDROP) Message.Drop, 0xFFFFFFFF, NULL, 0);
String FileName;
String FileExtension;
int FileLength;
for(UINT ii=0; ii < FileCount; ii++) {
FileName.SetLength(MAX_PATH);
FileLength = DragQueryFile((HDROP)Message.Drop, ii,
FileName.c_str(), FileName.Length());
FileName.SetLength(FileLength);
ShowMessage( "X" );
}
DragFinish((HDROP) Message.Drop);
}
//###########################################################################
void __fastcall TForm_Main::FormCreate(TObject *Sender) {
DragAcceptFiles(Form_Main-> Handle, true);
}
Nie ważne jak bym zmieniał kod, dostosowując się do wszystkich znalezionych przykładów:
void __fastcall TForm_Main::WMDropFiles(TWMDropFiles &Message) {
UINT FileCount = DragQueryFile((HDROP) Msg.Drop, 0xFFFFFFFF, NULL, 0);
AnsiString FileName;
AnsiString FileExtension;
int FileLength;
for(UINT ii=0; ii < FileCount; ii++)
{
FileName.SetLength(MAX_PATH);
FileLength = DragQueryFile((HDROP)Msg.Drop, ii,
FileName.c_str(), FileName.Length());
FileName.SetLength(FileLength);
ProcessFile(FileLength) // <------ Whatever you want it to be...
} // end for
DragFinish((HDROP) Msg.Drop);
}
lub:
void __fastcall TForm1::WmDropFiles(TWMDropFiles& Message) {
char buff[MAX_PATH];
HDROP hDrop = (HDROP)Message.Drop;
int numFiles =
DragQueryFile(hDrop, -1, NULL, NULL);
for (int i=0;i < numFiles;i++) {
DragQueryFile(hDrop, i, buff, sizeof(buff));
// process the file in 'buff'
}
DragFinish(hDrop);
}
wychodzą błędy z Undefinied Symbor Message / Msg
lub Canno't convert to w_char_t*
Po naprawie tych błędów nic nie działa...