再把这个Browser Control API也总结一下吧,只是做个引导,其实要掌握它的用法最好的方法是打开 9.1\S60_3rd\S60Ex\BrCtlSampleApp 这个例子来阅读,它几乎涵盖了这个API的所有使用方法。
而我在UniNews中只使用了它最基本的用法,下面给出代码:
首先,在H文件中声明一个控件成员:
#include <coecntrl.h>
#include <brctlinterface.h>
#include <brctldefs.h>
#include <brctllayoutobserver.h>
#include <brctllinkresolver.h>
class CUniNewsWebContainer : public CCoeControl, MCoeControlObserver,MBrCtlLoadEventObserver ...{
public:
// Constructors and destructor
~CUniNewsWebContainer();
static CUniNewsWebContainer* NewL(const TRect& aRect);
static CUniNewsWebContainer* NewLC(const TRect& aRect);
private:
// New functions
void ConstructL(const TRect& aRect);
CUniNewsWebContainer();
public:
// Functions from base classes
TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
void HandleBrowserLoadEventL(TBrCtlDefs::TBrCtlLoadEvent aLoadEvent,TUint aSize,TUint16 aTransactionId);
void LoadContentL(TInt id);
private:
// Functions from base classes
void SizeChanged();
TInt CountComponentControls() const;
CCoeControl* ComponentControl(TInt aIndex) const;
void Draw(const TRect& aRect) const;
void HandleControlEventL(CCoeControl* aControl, TCoeEvent aEventType);
HBufC8* ReadFileLC(const TDesC& aFileName);
private:
//data
CBrCtlInterface* iBrowser;
TUint iCapabilities;
TInt iCommandBase;
};
主要声明了三个成员,其中CBrCtlInterface是主要的browser控件,其它两个是构造时的所需要的参数。而这个类派生于接口MBrCtlLoadEventObserver,所以实现它的方法void HandleBrowserLoadEventL(TBrCtlDefs::TBrCtlLoadEvent aLoadEvent,TUint aSize,TUint16 aTransactionId);
在实现文件CPP中,我们需要构造它:
void CUniNewsWebContainer::ConstructL(const TRect& aRect) ...{
// Create a window for this application view
CreateWindowL();
SetRect(aRect);
//add your code here ...
iBrowser=CreateBrowserControlL(this
,aRect
,iCapabilities
,iCommandBase
,NULL //softkey observer
,NULL //link resolver
,NULL //special load observer
,NULL //layout observer
,NULL //dialog provider
);