1、從預設堆中分配記憶體單元
TSS000504
裝置, 軟體 版本:
S60 3rd Edition
建立日期:
描述:
一般來說記憶體單元是從當前線程堆中分配的,但有時無法這樣做,特別當要分配的記憶體單元很大時。
我們可以產生一個新的堆,從它那裡擷取我們需要的記憶體單元,樣本如下:
Code:
//Try to create a heap in a local chunk.
//The minimum length of the heap is 10M and the maximum length is 20M
RHeap *pChunkHeap = UserHeap::ChunkHeap(NULL, 10000*1024, 20000*1024);
if (RHeap)
{
void *mallocBuffer = NULL;
TInt size = 8000*1024; //Try to allocate a 8M memory cell
mallocBuffer = pChunkHeap->Alloc(size);
if (mallocBuffer )
{
//... Use this memory cell ...
}
}
2、顯示多行資訊的詢問對話方塊
TSS000677
裝置, 軟體 版本:
S60 3rd Edition
詳細描述:
下列代碼示範了如何使用一個可以顯示多行資訊的詢問對話方塊:
Code:
_LIT(KTxtApplicationName, "Application Title");
HBufC* sMessage =
StringLoader::LoadLC( R_MESSAGE );
HBufC* sTitle = HBufC::NewLC( KTxtApplicationName().Length() );
sTitle->Des().Append( KTxtApplicationName );
CAknMessageQueryDialog* dialog = new ( ELeave ) CAknMessageQueryDialog();
CleanupStack::PushL( dialog );
dialog->PrepareLC( R_AVKON_MESSAGE_QUERY_DIALOG );
dialog->QueryHeading()->SetTextL( *sTitle );
dialog->SetMessageTextL( *sMessage );
dialog->RunLD();
CleanupStack::Pop(); // dialog
CleanupStack::PopAndDestroy(2); // sTitle, sMessage
要顯示在對話方塊中的資訊是從資源檔載入的,我們在.rss檔案中需要有如下定義:
Code:
#define qtn_message “First Line /nSecond Line”
RESOURCE TBUF r_message
{
buf = qtn_message;
}
3、情景模式
1)如何擷取S60第三版中情景模式的相關資訊
TSS000715
裝置, 軟體 版本:
S60 3rd Edition
S60 3rd Edition, FP1
詳細描述
我們可以通過Profiles Engine API來擷取關於情景模式的細節資訊,如定義的情景模式的順序位置,以及他們的名稱等。
這裡的API可以通過下列獲得
Extensions plug-in package for S60 3rd Edition SDK
http://www.forum.nokia.com/info/sw.n...Pack1.zip.html
解決方案
下列代碼示範了如何找出每個情景模式的名稱:
Code:
#include <mprofileengine.h> // link against ProfileEng.lib
#include <MProfilesNamesArray.h>
MProfileEngine* profileEngine = CreateProfileEngineL();
CleanupReleasePushL( *profileEngine );
MProfilesNamesArray* profileNames =
profileEngine->ProfilesNamesArrayLC();
for( TInt i = 0; i < profileNames->MdcaCount(); ++i )
{
// Name of each profile is returned by
// profileNames->ProfileName(i)->Name();
}
CleanupStack::PopAndDestroy(2); // profileNames, profileEngine
2)如何在S60第三版FP1上設定情景模式
TSS000623
裝置, 軟體 版本:
S60 3rd Edition, FP1
概述
可以用過Profile Engine Wrapper API來設定情景模式
解決方案
下列這段範例程式碼示範了如何設定當前情景模式為靜音。
需要在mmp檔案中添加連結庫ProfileEngine.lib
需要包含的標頭檔有 mproengengine.h, proengfactory.h, profile.hrh
Code:
MProEngEngine* engine = ProEngFactory::NewEngineL();
CleanupReleasePushL(*engine);
engine->SetActiveProfileL(EProfileSilentId);
CleanupStack::PopAndDestroy(1);
4、如何切換程式UI方向為橫屏或豎屏
TSS000676
裝置, 軟體 版本:
S60 3rd Edition
S60 3rd Edition, FP1
詳細描述:
預設情況下,程式是根據手機螢幕的當前方向開始啟動的。如果要強製程序以橫屏或豎屏的模式啟動,那我們在CAknAppUi::ConstructL()方法
中調用BaseConstructL()時就要傳遞相應的flag值:
Code:
void CMyAppUi::ConstructL()
{
BaseConstructL( EAknEnableSkin | EAppOrientationLandscape ); // start in landscape mode
...
}
如果要在程式運行期間改變方向,則需要調用:
Code:
void CAknAppUiBase::SetOrientationL( TAppUiOrientation aOrientation );這裡的參數為EAppUiOrientationLandscape和
EAppUiOrientationPortrait,注意這種情況下的調用就不要再向BaseConstructL()中傳遞相同的參數了。
5、怎麼通過程式鎖定鍵盤
TSS000648
裝置, 軟體 版本:
S60 1st Edition
S60 2nd Edition and FP1, FP2, FP3
S60 3rd Edition and FP1
詳細描述:
我們可以通過RAknKeyLock類來鎖定鍵盤
Code:
#include <aknkeylock.h> // link against avkon.lib
RAknKeyLock keyLock;
if( keyLock.Connect() == KErrNone )
{
keyLock.EnableKeyLock();
keyLock.Close();
}
6、如何準備開始中文程式的開發
TSS000674
裝置, 軟體 版本:
S60 2nd Edition, FP1, FP2, FP3
S60 3rd Edition
詳細描述
在S60第三版中,你可以通過開始菜單選擇語言種類:
通過 '''開始 > 程式 > S60 Developer Tools > 3rd Edition SDK > 1.0 > Languages > Change to Chinese'''
在S60第二版,FP3中,可以在模擬器中選擇語言:
'''Emulator > Tools > References > General Settings > Language'''
在S60第二版,FP1和FP2中,有2個獨立的中文版本SDK可供下載,在
http://www.forum.nokia.com/info/sw.n...16-3.0-mr.html
可以找到。
在Series 80 2nd SDK中,沒有中文版的支援。
7、如何擷取正在運行任務的列表
TSS000649
裝置, 軟體 版本:
S60 1st Edition
S60 2nd Edition and FP1, FP2, FP3
S60 3rd Edition and FP1
Series 80 2nd Edition
詳細描述:
描述
Symbian作業系統的應用程式架構提供了一組API用以獲得當前正在啟動並執行任務的資訊(無論其在前台或後台運行)。
解決方案
我們可以使用TApaTaskList擷取當前正在啟動並執行任務的列表。具體任務是通過正在啟動並執行程式window group來識別的,在構造TApaTaskList時
我們需要將window server的session作為參數傳遞進去。
Code:
#include <apgtask.h> // link against apgrfx.lib
TApaTaskList tasklist(CCoeEnv::Static()->WsSession());
TApaTask taskInForeground = tasklist.FindByPos( 0 );
// Window Group ID of the foreground task
TInt WindowGroupIdentifier = taskInForeground.WgId();
// Thread ID of the foreground task
TThreadId ThreadIdentifier = taskInForeground.ThreadId();
TApaTaskList中第一個任務是在前台啟動並執行那個(相關的window group位置順序是從0開始的)
TApaTask包括很多與task相關的有用資訊,如線程標識(ThreadId())以及window group標識(WgId()).
此外,還有一些有用的函數方法,如EndTask(),用來請求某任務正常關閉,以及KillTask()用來直接中止某任務。
SendToBackground()以及BringToForeground()方法可以用來控製程序在工作清單中的位置。