×
Namespaces

Variants
Actions

使用CDocumentHandler打开一个文件

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

文章
hoolee 在 28 Aug 2008 创建
最后由 hamishwillee 在 15 Dec 2011 编辑

CS001052


  • 开发伙伴平台:

S60 3rd Edition, FP1


  • 详细描述

下列代码片段演示了如何使用Document Handler API(CDocumentHandler)打开一个文件。这里演示了两种方法:

1、在一个单独应用程序中打开这个文件;

2、在当前正在运行的程序中用内嵌方式打开这个文件


Contents

MMP文件

需要下列链接库和能力:

CAPABILITY  SwEvent  // TApaTask::SwitchOpenFile() (Standalone version only)LIBRARY  apgrfx.lib    // 
 
TApaTaskList, TApaTask (Standalone version only)
LIBRARY apmime.lib // TDataType
LIBRARY commonui.lib // CDocumentHandler


头文件(单独版本)

#include <DocumentHandler.h>class CMyAppUi : public CAknAppUi
{
// ...
 
private: // Private functions
void LaunchFileL(const TDesC& aFilename);
void RefreshDocumentFileL(const TUid& aUid, const TDesC& aFileName);
 
private: // Data
CDocumentHandler* iDocHandler;
}


源文件(单独版本)

如果要在单独的handler中启动程序,可以使用CDocumentHandler::OpenFileL()方法。此外,下列代码演示了如果这个文件

已经在handler中打开,那将如何更新这个文件

#include <DocumentHandler.h>void CMyAppUi::ConstructL()
{
// Create the document handler
iDocHandler = CDocumentHandler::NewL(CEikonEnv::Static()->Process());
 
// ...
}void CMyAppUi::LaunchFileL(const TDesC& aFilename)
{
TDataType emptyDataType = TDataType();
// Open a file in a standalone handler application
iDocHandler->OpenFileL(aFilename, emptyDataType);
 
TUid handlerUid;
TInt err = KErrNone;
err = iDocHandler->HandlerAppUid(handlerUid);
if (!err)
{
RefreshDocumentFileL(handlerUid, aFilename);
}
}
 
/**
* Refreshes the file opened in a standalone handler. Does nothing if the file
* has not been already opened.
*/
void CMyAppUi::RefreshDocumentFileL(const TUid& aUid, const TDesC& aFileName)
{
TApaTaskList taskList(iCoeEnv->WsSession());
TApaTask task = taskList.FindApp(aUid);
 
// If the standalone handler is already running, then update the file
if (task.Exists())
{
User::LeaveIfError(task.SwitchOpenFile(aFileName));
}
}


头文件(内嵌版本)

#include <aknserverapp.h>  // MAknServerAppExitObserver
#include <DocumentHandler.h>class CMyAppUi : public CAknAppUi, public MAknServerAppExitObserver
{
// ...
 
private: // Functions from base classes
/**
* From MAknServerAppExitObserver.
* Handles the exit of a connected server application.
*/
void HandleServerAppExit(TInt aReason);
 
private: // Private functions
void LaunchFileEmbeddedL(const TDesC& aFilename);
 
private: // Data
CDocumentHandler* iDocHandler;
};


源文件(内嵌版本)

要以内嵌方式启动文件的话,我们需要使用CDocumentHandler::OpenFileEmbeddedL()方法

#include <aknserverapp.h>  // MAknServerAppExitObserver
#include <DocumentHandler.h>void CMyAppUi::ConstructL()
{
// Create the document handler
iDocHandler = CDocumentHandler::NewL(CEikonEnv::Static()->Process());
 
// ...
}void CMyAppUi::LaunchFileEmbeddedL(const TDesC& aFilename)
{
//Set the exit observer so HandleServerAppExit will be called
iDocHandler->SetExitObserver(this);
 
TDataType emptyDataType = TDataType();
//Open a file embedded
iDocHandler->OpenFileEmbeddedL(aFilename, emptyDataType);
}
 
void CMyAppUi::HandleServerAppExit(TInt aReason)
{
//Handle closing the handler application
MAknServerAppExitObserver::HandleServerAppExit(aReason);
}
This page was last modified on 15 December 2011, at 09:01.
89 page views in the last 30 days.
×