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

此示例创建了一个从URL异步下载数据的控件。该控件实现IBindStatusCallback接口,用于异步下载大型二进制对象或属性,使用户界面在长时间网络操作期间保持响应,并允许用户中断下载。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

程序代码: 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发送接收到的数据到被显示的子类化控件中。<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?>

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 例子。

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值