Demonstrates Downloading Data Asynchronously(用ATL异步下载数据的演示)

Demonstrates Downloading Data Asynchronously(用ATL异步下载数据的演示)

程序代码: http://www.cppblog.com/Files/alantop/async.rar

This sample creates a control that downloads data asynchronously from a URL. The control implements the IBindStatusCallback interface. Typically, you asynchronously download large binary objects or properties. This allows the control's user interface to remain unblocked during potentially lengthy network operations. The use of asynchronous downloading also gives the user a chance to abort the download. ATL uses WinInet functions internally to implement asynchronous downloading.

这个例子建立了一个控件从一个URL里异步下载数据。这个控件实现了IBindStatusCallback接口。有代表性的,你异步下载大的数据和道具。这将保持在整个网络长时间的网络操作中,用户的接口保持不被封锁。异步下载可以给用户提供中断的机会。ATL用内建的WinInet函数实现异步下载。

ASYNC creates a subclassed edit control with one property called URL. The URL property is a BSTR that represents a URL that points to data. The ASYNC sample uses the ATL CBindStatusCallback class to implement asynchronous downloading. When the control user sets the URL property, ASYNC creates a CBindStatusCallback object. The CBindStatusCallback::StartAsyncDownload method is then called and passed both the URL and a pointer to a callback function. This function, CAtlAsync::OnData, is called by the CBindStatusCallback object and is passed the binary data from the URL as it is received. CAtlAsync::OnData simply sends the received data to the subclassed edit control, where it is displayed.

ASYNC建立一个子类化的edit控件,其有一个属性关联URL.URL属性用BSTR代表。演示程序用CBindStatusCallback类实现异步下载。当控件用户设置URL属性,ASYNC建立一个CBindStatusCallback属性。然后,CBindStatusCallback::StartAsyncDownload被调用,URL和一个指向回调函数的指针被传递给函数。CAtlAsync::OnDataCBindStatusCallback对象调用,并传递url接收到的二进制数据。CAtlAsync::OnData发送接收到的数据到被显示的子类化控件中。

Running the Sample

Load the AtlAsync.htm file into your web browser. Type a URL into the edit control and press the Go button. This sets the ASYNC control's URL property to the URL you typed and starts the download. As data is downloaded, you will see it displayed in the ASYNC control.

在浏览器中打开atlasync.htm文件。在edit控件键入网址,并选择go.这将设置ASYNC控件的URL属性并开始下载。当数据下载的时候,你可以看到它在async控件中显示。

For an example of how to subclass Windows controls using ATL, see the ATL SubEdit sample.

怎样用 ATL 子类化窗口控件,看 ATL subedit 例子。

 

你可能感兴趣的:(Demonstrates Downloading Data Asynchronously(用ATL异步下载数据的演示))