Implementation of webbrowser control dragging

Source: Internet
Author: User

As a popular plug-in, webbrowser has always been notorious for its ease of use and difficulty in writing.

 

Its massive interfaces are busyProgramHappy employee.

 

A few days ago, we needed to drag and drop files in webbrowser. Some problems were solved and we hope to share them with you.

 

I'm a cainiao. Thank you.

 

Environment: Pure SDK (MFC is not used, because it is too convenient, so it seems bloated, but some problems are complicated, so use the SDK mode to explain)

 

We all know that webbrowser has a famous interface called idochostuihandler.

 

For more information about this interface, see the following link:

 

Http://www.vckbase.com/document/viewdoc? Id = 1486

 

The only drawback is that it is based on MFC, but this interface is easy to convert to SDK mode, which is very simple.

 

There is a function in idochostuihandler, getdroptarget (idroptarget * pdroptarget, idroptarget ** ppdroptarget)

It is said that the function is reloaded and then returned. You can replace the default drag and drop operation (the default drag and drop operation is to download the dragged object)

In the interface aboveArticleThe author seems to have easily implemented this function using the mfc html module.

However, someone soon reflected the problem:

Http://topic.csdn.net/u/20071130/10/c8fb0fe8-776a-42d3-b340-a5fce0568cda.html

The questioner solved the problem almost until the end, but it was a little worse. Unfortunately, the problem had been closed and he could not answer his question.

 

In fact, for the implementation of drag and drop, the principle is still the com class. In MFC, a class is provided, coledroptarget. This class is inherited by many classes, such as cview.

This class is used to "IMPLEMENT" drag and drop. I put quotation marks because they are not actually used.

The implementation files of this class are in X:/program files/Microsoft Visual Studio 9.0/VC/atlmfc/src/mfc/oledrop2.cpp.

The following is a tutorial on using him)

Http://www.vckbase.com/document/viewdoc? Id = 258

(The reason why I hate MFC is that it is a simple thing that he uses very tedious technologies to make it simple .)

 

According to the thought of the student, there are actually two implementations.

Method 1:

Use registerdragdrop (...) to tell the system to define a window as a drag window.

Function prototype:

The hwnd parameter is the handle of the drag and drop window.

The pdroptarget parameter is a pointer to the idroptarget to process drag and drop operations.

Note that pdroptarget must be implemented by the user.

    1. Winoleapi registerdragdrop (
    2. HwndHwnd,// Handle to a window that can accept drops
    3. Idroptarget * pdroptarget
    4. // Pointer to object that is to be target of drop
    5. );

You also need to simply return s_ OK IN THE getdroptarget in your own implementation of idochostuihandler to tell webbrowser about custom drag.
    1. Hresult 
    2. Yourdochostuihandler: getdroptarget (idroptarget * pdroptarget, idroptarget ** ppdroptarget)
    3. {
    4. // Use User-Defined drag and drop
    5. ReturnS_ OK;
    6. }

Note that the registerdragdrop parameter hwnd is the handle for the drag and drop window. It must be the window itself, not the child window, not the parent window.

Many people should know that the m_hwnd given in the mfc html does not actually accept the window of the drag-and-drop window, but its Framework Window.

Use sky ++ to view the composition of the webbrowser window.

You will find that m_hwnd is the window at the outermost layer, and the actual window is a famous window with a class name such as Internet assumer_server, which is exactly the window

Is the window that should be dragged.

Although the previous employee used registerdragdrop, he still could not accept the drag operation. The problem was that he did not register the Internet assumer_server window as the drag operation. Instead, he registered his grandfathers window, of course, this cannot be achieved.

Of course, the problem is covered up in MFC, but sometimes this problem occurs when you do not "follow God's will" to use MFC.

 

 

Method 2.

This method is a standard method and is very simple:

 

    1. Hresult 
    2. Yourdochostuihandler: getdroptarget (idroptarget * pdroptarget, idroptarget ** ppdroptarget)
    3. {
    4. // Use User-Defined drag and drop
    5. * Ppdroptarget = & yourdroptarget;
    6. ReturnS_ OK;
    7. }

In this method, we tell webbrowser that we use yourdroptarget to replace the default droptarget.

 

 

 

 

You are welcome to make a picture and ask questions.

Thank you.

 

From the hard sea of MFC, back to the original, back to the embrace of pure SDK ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.