I have a wxTextCtrl-derived class that overrides OnDropFiles. However, dragging something over the control does nothin开发者_C百科g. (The cursor changes to the 'not allowed' cursor.) I tried DragAcceptFiles(true) but that only enabled the built-in drop handler. (Which just loads the file into the control.) How can I get my own handler to be invoked?
I also tried SetDropTarget, but that never got invoked either. It worked in a wxFrame, though.
Any ideas?
This is a stripped down version of what I have in one of my projects:
My form code
wxTextCtrl* textctrl = new wxTextCtrl(...);
textctrl->SetDropTarget(new DropFiles(textctrl));
The dropfiles class
class DropFiles: public wxFileDropTarget{
public:
DropFiles(wxTextCtrl *text): m_Text(text){}
bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& arrFilenames);
private:
wxTextCtrl *m_Text;
};
bool DropFiles::OnDropFiles(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), const wxArrayString& arrFilenames){
//Just take the first filename
m_Text->SetValue(arrFilenames.Item(0));
return true;
}
Hope that helps!
You have to handle the EVT_DROP_FILES event. Any other attempt to get notified will fail :(
精彩评论