Symbian 開發中的一些小知識

來源:互聯網
上載者:User

如何顯示bmp或者jpeg檔案映像

symbian片的顯示用CFbsBitmap,先把其他檔案的圖片轉換為CFbsBitmap在顯示。核心代碼如下:

iImageDecoder = CImageDecoder::FileNewL( iFs, aFileName );

// create the destination bitmap
iBitmap = new (ELeave) CFbsBitmap();
iBitmap->Create( iImageDecoder->FrameInfo().iOverallSizeInPixels,
iImageDecoder->FrameInfo().iFrameDisplayMode );

// start conversion to bitmap
iState = EDecoding;
iImageDecoder->Convert( &iStatus, *iBitmap );

sdk中手機震動的編程介面

S60 2.0引進了震動API,要使用這個API,需要在代碼添加標頭檔vibractrl.h,並在MMP檔案中添加vibractrl.lib,但有一點是使用者佈建裡必須開啟震動。樓主可以先看看vibractrl.h中相關類的說明。

IMPORT_C static CVibraControl* NewL();
IMPORT_C static CVibraControl* NewL(MVibraControlObserver* aCallback);
IMPORT_C static CVibraControl* NewLC(MVibraControlObserver* aCallback);

應該是通過上面三個函構建一個CVibraControl對象,然後調用它StartVibra(TUint16 aDuration),StopVibra(void)來啟動/停止震動。

線程發訊息機制

主線程裡建立一個封裝了副線程的使用中的物件類,順手寫的,141421。

// MyActive.h
class CMyActive : public CActive
{
public:
void DownloadL(const TDesC& aUrl); //

protected:
void DoCancel();
void RunL();
private:
static TInt ThreadFunction(TAny* aArg);

private:
RThread iThread;
};

// MyActive.cpp
void CMyActive : DownloadL(const TDesC& aUrl)
{
// 建立線程
iThread.Logon(iStatus); // 請求副線程退出時通知主線程。
SetActive();
// ...
}

void CMyActive::RunL()
{
if(iStatus.Int()==KErrNone)
{
// 副線程已正常退出
}
}

TInt CMyActive::ThreadFunction(TAny* aArg)
{
// 下載
}

如何擷取翻蓋的狀態

Series 60 C++開發夥伴們現在可以編寫一些應用軟體,用來響應使用者開啟或關閉手 機上蓋、或改變可移動相機的方位。上面兩種使用者動作都有可能出現在諾基亞N90多媒體終端上。這類軟體事件自 Series 60 2nd Edition Feature Pack 2以後就已獲支援。如,當使用者合上其終端時開發人員能令輸出自動轉移到 外屏顯示, 而當使用者開啟終端時,輸出又將自動轉移到內屏(通常內屏較大)。

如欲向某個應用軟體添加這類功能,只需簡單地在CEikAppUi::HandleKeyEventL()中增加一些事件處理控制代碼。相應的事件 (TEventCode)是EEventScreenDeviceChanged、EEventCaseOpened、和 EEventCaseClosed。當相機旋轉時,則 是EEventKeyUp和EEventKeyDown類型的按鍵事件。

以下範例代碼用於檢測當前的相機方位:

#include // link against ecam.lib
CCamera* cam = CCamera::NewL(*this, 0);
TCameraInfo info;
cam->CameraInfo(info);
TCameraOrientation orientation = info.iOrientation;

將TDesC類型 轉換成char *型

const char* cp = reinterpret_cast<const char*>(desc.Ptr()); // or use PtrZ()
char* p = const_cast<char*>(cp);

Remember that the length of the string is desc->Size() (or desc->Length()*2), and the max length of the string is desc->MaxLength()*2(including the '/0' terminator, if any).

具體看:
"Conversion bitween 8 and 16 bits descriptors"
http://forum.newlc.com/index.php/topic,1075.0.html

從檔案中讀取中文亂碼的解決辦法

方法一:

CnvUtfConverter::ConvertFromUnicodeToUtf8(),把UNICODE轉換成UTF-8編碼後再顯示.

方法二:

CCnvCharacterSetConverter* converter=CCnvCharacterSetConverter::NewLC();
// Check if there is conversion between GBK/GB2312 and unicode
if(converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierUtf8,
CEikonEnv::Static()->FsSession())!=CCnvCharacterSetConverter::EAvailable)
User::Leave(KErrNotSupported);
TInt state=CCnvCharacterSetConverter::KStateDefault;
HBufC* aTextBuf = HBufC::NewL( aStuffData.Length() );
TPtr16 ptr = aTextBuf->Des();
if(CCnvCharacterSetConverter::EErrorIllFormedInput == converter->ConvertToUnicode(ptr, aStuffData, state))
User::Leave(KErrArgument); //Leave if error in conversion.
CleanupStack::PopAndDestroy(); //clean for converter

檔案儲存

一些資料儲存到檔案中去,每個變數都儲存在記事本檔案中的一行,每一行記憶個變數的值。

RFile file;
// open the file here ...
TFileText txtfile;
txtfile.Set(file);
// convert your data to a descripter ...

// this operation appends a line delimiter to the descriptor
txtfile.Write(data);

// Of cource TFileText::Read() is the reverse operation which read a whole line.

編輯框的當前IME

當焦點在某個編輯框時,獲得當前編輯框的IME:

TCoeInputCapabilities icap = edwin->InputCapabilities();
CAknEdwinState* edwinState = static_cast(icap.FepAwareTextEditor()->Extension1()->State(KNullUid));
TInt inputMode = edwinState->CurrentInputMode();

實現位元組對齊

The GCC compiler ignores "#pragma pack" statement when compiling for ARM platform, so you should use "__attribute__((packed, aligned))", like this:

#if defined(__WINS__)
#define PACKED
#else
#define PACKED __attribute__((packed, aligned(1)))
#endif

#pragma pack(1)

typedef struct {
char sig[104];
unsigned char verl,key;
int nFile, dFile, crc;
}PACKED avl1;

typedef struct {
char name[22];
int length, crc32;
}PACKED avd1;

#pragma pack(4)

簡單實現一個延時或者計時功能

你需要完成最少三個步驟:
一、建立CPeriodic對象,如

void CPeriodicRunner::StartTimer()
{
const TInt tickInterval=1000000;
iPeriodic=CPeriodic::NewL(0); // neutral priority
iPeriodic->Start(tickInterval,tickInterval,TCallBack(Tick, this));
}

CPeriodic::Start原型為:void Start(TTimeIntervalMicroSeconds32 aDelay,TTimeIntervalMicroSeconds32 anInterval,TCallBack aCallBack);
因此我們需要有一個callback函數,在每次回調時能做點什麼,於是有了第二個步驟

二、Callback函數的完成
TInt CPeriodicRunner::Tick(TAny* aObject)
{
// cast, and call non-static function
((CPeriodicRunner*)aObject)->DoTick();
return 1;
}

如果您不熟悉TCallBack,可以參考SDK,上面這個函數完成了計時的時候相應的迴圈動作(DoTick)

三、計時器的析構
在計時停止或外界終止後,需要停止該計時器,一句話即可:
CPeriodicRunner->Cancel();

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.