S60简单控件的问题
按照书上的例子,一个简单的只包含一个Label的程序,但是Label始终不显示,请问这是为什么?代码如下:
appui.h:
#ifndef __STOPWATCHHXAPPUI_h__
#define __STOPWATCHHXAPPUI_h__
#include <aknappui.h>
class CStopWatchHXAppView;
class CStopWatchHXAppUi: public CAknAppUi
{
public:
void ConstructL();
CStopWatchHXAppUi();
virtual ~CStopWatchHXAppUi();
private:
void HandleCommandL(TInt aCommand);
void HandleStatusPaneSizeChange();
CArrayFix<TCoeHelpContext>* HelpContextL() const;
private:
CStopWatchHXAppView* iAppView;
};
#endif // __STOPWATCHHXAPPUI_h__
appui.cpp:
// INCLUDE FILES
_LIT( KFileName, "C:\\private\\E9AECC2D\\StopWatchHX.txt" );
_LIT( KText, "Hello World!");
void CStopWatchHXAppUi::ConstructL()
{
// Initialise app UI with standard value.
BaseConstructL(CAknAppUi::EAknEnableSkin);
// Create view object
iAppView = CStopWatchHXAppView::NewL(ClientRect());
// Create a file to write the text to
TInt err = CCoeEnv::Static()->FsSession().MkDirAll(KFileName);
if ((KErrNone != err) && (KErrAlreadyExists != err)) {
return;
}
RFile file;
err = file.Replace(CCoeEnv::Static()->FsSession(), KFileName, EFileWrite);
CleanupClosePushL(file);
if (KErrNone != err) {
CleanupStack::PopAndDestroy(1); // file
return;
}
RFileWriteStream outputFileStream(file);
CleanupClosePushL(outputFileStream);
outputFileStream << KText;
CleanupStack::PopAndDestroy(2); // outputFileStream, file
}
CStopWatchHXAppUi::CStopWatchHXAppUi()
{
// No implementation required
}
CStopWatchHXAppUi::~CStopWatchHXAppUi()
{
if (iAppView) {
delete iAppView;
iAppView = NULL;
}
}
void CStopWatchHXAppUi::HandleCommandL(TInt aCommand)
{
switch (aCommand) {
case EEikCmdExit:
case EAknSoftkeyExit:
Exit();
break;
case ECommand1:
{
// Load a string from the resource file and display it
HBufC* textResource = StringLoader::LoadLC(R_COMMAND1_TEXT);
CAknInformationNote* informationNote;
informationNote = new (ELeave) CAknInformationNote;
// Show the information Note with
// textResource loaded with StringLoader.
informationNote->ExecuteLD(*textResource);
// Pop HBuf from CleanUpStack and Destroy it.
CleanupStack::PopAndDestroy(textResource);
}
break;
case ECommand2:
{
RFile rFile;
//Open file where the stream text is
User::LeaveIfError(rFile.Open(CCoeEnv::Static()->FsSession(), KFileName, EFileStreamText));//EFileShareReadersOnly));// EFileStreamText));
CleanupClosePushL(rFile);
// copy stream from file to RFileStream object
RFileReadStream inputFileStream(rFile);
CleanupClosePushL(inputFileStream);
// HBufC descriptor is created from the RFileStream object.
HBufC* fileData = HBufC::NewLC(inputFileStream, 32);
CAknInformationNote* informationNote;
informationNote = new (ELeave) CAknInformationNote;
// Show the information Note
informationNote->ExecuteLD(*fileData);
// Pop loaded resources from the cleanup stack
CleanupStack::PopAndDestroy(3); // filedata, inputFileStream, rFile
}
break;
case EHelp:
{
CArrayFix<TCoeHelpContext>* buf = CCoeAppUi::AppHelpContextL();
HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), buf);
}
break;
case EAbout:
{
CAknMessageQueryDialog* dlg = new (ELeave) CAknMessageQueryDialog();
dlg->PrepareLC(R_ABOUT_QUERY_DIALOG);
HBufC* title = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TITLE);
dlg->QueryHeading()->SetTextL(*title);
CleanupStack::PopAndDestroy(); //title
HBufC* msg = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TEXT);
dlg->SetMessageTextL(*msg);
CleanupStack::PopAndDestroy(); //msg
dlg->RunLD();
}
break;
default:
Panic( EStopWatchHXUi);
break;
}
}
void CStopWatchHXAppUi::HandleStatusPaneSizeChange()
{
iAppView->SetRect(ClientRect());
}
CArrayFix<TCoeHelpContext>* CStopWatchHXAppUi::HelpContextL() const
{
#warning "Please see comment about help and UID3..."
CArrayFixFlat<TCoeHelpContext>* array = new (ELeave) CArrayFixFlat<TCoeHelpContext> (1);
// CleanupStack::PushL(array);
// array->AppendL(TCoeHelpContext(KUidStopWatchHXApp, KGeneral_Information));
// CleanupStack::Pop(array);
return array;
}
appview.h:
#ifndef __STOPWATCHHXAPPVIEW_h__
#define __STOPWATCHHXAPPVIEW_h__
// constants
const TInt KNumberOfControls = 1;
// CLASS DECLARATION
class CStopWatchHXAppView: public CAknControl
{
public:
static CStopWatchHXAppView* NewL(const TRect& aRect);
static CStopWatchHXAppView* NewLC(const TRect& aRect);
virtual ~CStopWatchHXAppView();
public:
void Draw(const TRect& aRect) const;
virtual void SizeChanged();
virtual void HandlePointerEventL(const TPointerEvent& aPointerEvent);
TInt CountComponentControls();
CCoeControl * ComponentControl(TInt);
private:
void ConstructL(const TRect& aRect);
CStopWatchHXAppView();
CEikLabel *iLabel;
};
#endif // __STOPWATCHHXAPPVIEW_h__
// End of File
appview.cpp:
// INCLUDE FILES
#include <coemain.h>
#include "StopWatchHXAppView.h"
CStopWatchHXAppView* CStopWatchHXAppView::NewL(const TRect& aRect)
{
CStopWatchHXAppView* self = CStopWatchHXAppView::NewLC(aRect);
CleanupStack::Pop(self);
return self;
}
CStopWatchHXAppView* CStopWatchHXAppView::NewLC(const TRect& aRect)
{
CStopWatchHXAppView* self = new (ELeave) CStopWatchHXAppView;
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
// -----------------------------------------
// CStopWatchHXAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------
//
void CStopWatchHXAppView::ConstructL(const TRect& aRect)
{
// Create a window for this application view
CreateWindowL();
// create controls
iLabel = new (ELeave) CEikLabel;
iLabel->SetContainerWindowL(*this);
iLabel->SetTextL(_L("this is a label."));
iLabel->SetExtent(TPoint(10, 10), TSize(100, 50));
iLabel->MakeVisible(ETrue);
// Set the windows size
SetRect(aRect);
// Activate the window, which makes it ready to be drawn
ActivateL();
}
// -----------------------------------------
// CStopWatchHXAppView::CStopWatchHXAppView()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------
//
CStopWatchHXAppView::CStopWatchHXAppView()
{
// No implementation required
}
// -----------------------------------------
// CStopWatchHXAppView::~CStopWatchHXAppView()
// Destructor.
// -----------------------------------------
//
CStopWatchHXAppView::~CStopWatchHXAppView()
{
delete iLabel;
}
// -----------------------------------------
// CStopWatchHXAppView::Draw()
// Draws the display.
// -----------------------------------------
//
void CStopWatchHXAppView::Draw(const TRect& aRect) const
{
// Get the standard graphics context
CWindowGc& gc = SystemGc();
gc.Clear(aRect);
}
// -----------------------------------------
// CStopWatchHXAppView::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------
//
void CStopWatchHXAppView::SizeChanged()
{
DrawNow();
if (iLabel)
{
iLabel->SetExtent(TPoint(10, 10), TSize(100, 50));
}
}
// -----------------------------------------
// CStopWatchHXAppView::HandlePointerEventL()
// Called by framework to handle pointer touch events.
// Note: although this method is compatible with earlier SDKs,
// it will not be called in SDKs without Touch support.
// -----------------------------------------
//
void CStopWatchHXAppView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
// Call base class HandlePointerEventL()
CCoeControl::HandlePointerEventL(aPointerEvent);
}
// ------------------------------------------
TInt CStopWatchHXAppView::CountComponentControls()
{
return 1;
}
CCoeControl * CStopWatchHXAppView::ComponentControl(TInt aIndex)
{
switch(aIndex)
{
case 0:
return iLabel;
default:
return NULL;
}
return NULL;
}
// End of File
[解决办法]
上面代码是按照书上示例写的,在新的SDK上有这样的问题
[解决办法]
新建一个GUI工程
就可以显示label
[解决办法]
该回复于2010-08-23 16:07:33被版主删除
[解决办法]