Preface: I'm extrapolating from documentation I've found, and am not concerned if I'm wrong. Please make sure the following explanation makes sense, ie try it, before voting-up my answer or accepting it :)
After Googling OnDropFiles
, I discovered that it's inherited from the CWnd
class: (MSDN page)
According to that MSDN article:
Parameters
hDropInfo
A pointer to an internal data structure that describes the dropped files. This handle is used by the DragFinish
, DragQueryFile
, and DragQueryPoint
Windows functions to retrieve information about the dropped files.
Quoting later:
"The framework calls this member function when the user releases the left mouse button over a window that has registered itself as the recipient of dropped files.
"Typically, a derived class will be designed to support dropped files and it will register itself during window construction.
This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was received. If you call the base-class implementation of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function."
That appears to indicate that until the function has been registered, it won't work 'as expected'.
Therefore, I believe that what's happening is that the first time you drop something onto the CHTMLView, it registers itself, and only then 'works as expected'.
If my understanding is correct, then a new question is raised, which is how can you force the registration of the View. From the related links on the MSDN Technote, it looks like you can force DragAcceptFiles
(see here) to run, which would otherwise be triggered when the drop event finished.