×
Namespaces

Variants
Actions

如何完成自定义的CAknQueryDialog对话框

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

兼容于
平台安全性
需要的签名: Self-Signed
能力: None

文章
翻译:
hoolee
最后由 hamishwillee 在 27 Aug 2012 编辑


  • 详细描述

下列代码演示了如何完成一个自定义的对话框。在这个情况下对话框就像程序的splash屏。本对话框会在程序运行2秒后关闭。

下列代码可以自签名运行。

  • MMP文件

需要下列链接库和能力

CAPABILITY None       
 
LIBRARY avkon.lib
LIBRARY eikcoctl.lib
LIBRARY eikdlg.lib
LIBRARY euser.lib
  • 头文件
#include <aknquerydialog.h>
#include <e32std.h>
#include <e32base.h>
#include <eikbtgpc.h>
 
class CSplashScreenDialog : public CAknQueryDialog
{
public: // Construction
CSplashScreenDialog();
virtual ~CSplashScreenDialog();
void PreLayoutDynInitL();
void PostLayoutDynInitL();
TBool OkToExitL(TInt aButtonId);
 
private: // From base classes
void SizeChanged();
TInt CountComponentControls() const;
CCoeControl* ComponentControl(TInt aIndex) const;
void Draw( const TRect& /*aRect*/ ) const;
void SetSizeAndPosition(const TSize &aSize);
 
private: // Internal methods
void CalculatePositionAndSize();
static TInt HideDialog(TAny* aAny);
 
private: // Data
CPeriodic* iPeriodic;
};
  • 源文件
#include "csplashscreendialog.h"
 
const TInt KShowTime(2000000);
 
CSplashScreenDialog::CSplashScreenDialog()
{
// Closes this dialog after KShowTime 2s
TRAPD(err,
iPeriodic = CPeriodic::NewL(CActive::EPriorityIdle);
);
if (!err)
{
iPeriodic->Start(KShowTime, KShowTime, TCallBack(HideDialog, this));
}
}
 
CSplashScreenDialog::~CSplashScreenDialog()
{
if (iPeriodic)
{
iPeriodic->Cancel();
}
delete iPeriodic;
}
 
void CSplashScreenDialog::PreLayoutDynInitL()
{
CAknQueryDialog::PreLayoutDynInitL();
SetEditableL(EFalse);
}
 
void CSplashScreenDialog::PostLayoutDynInitL()
{
// No CBA buttons
CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
cba->MakeVisible(EFalse);
 
// Calculate position of the dialog
CalculatePositionAndSize();
}
 
TBool CSplashScreenDialog::OkToExitL(TInt /*aButtonId*/)
{
return ETrue;
}
 
TInt CSplashScreenDialog::CountComponentControls() const
{
// No child components in this example
return(0);
}
 
CCoeControl* CSplashScreenDialog::ComponentControl(TInt /*aIndex*/) const
{
// No child components in this example
return NULL;
}
 
void CSplashScreenDialog::CalculatePositionAndSize()
{
// Set full screen
SetExtentToWholeScreen();
}
 
void CSplashScreenDialog::SetSizeAndPosition(const TSize &aSize)
{
CAknQueryDialog::SetSizeAndPosition( aSize );
CalculatePositionAndSize();
}
 
void CSplashScreenDialog::SizeChanged()
{
// Update screen
DrawNow();
}
 
void CSplashScreenDialog::Draw( const TRect& /*aRect*/ ) const
{
// Get the standard graphics context
CWindowGc& gc = SystemGc();
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushColor( KRgbBlack);
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
 
// Clear screen
gc.Clear(Rect());
gc.SetBrushStyle( CGraphicsContext::ENullBrush );
 
// Draw round rect
gc.SetPenStyle( CGraphicsContext::ESolidPen );
gc.SetPenColor(KRgbWhite);
gc.DrawRect(Rect());
 
// TODO: Implement what you need
}
 
TInt CSplashScreenDialog::HideDialog(TAny* aAny)
{
CSplashScreenDialog* self = static_cast<CSplashScreenDialog*>( aAny );
 
// Cancel CPeriodic timer
self->iPeriodic->Cancel();
 
// Closes itself
TRAP_IGNORE(
self->TryExitL(1);
);
return KErrNone;
}
  • 自定义对话框资源
RESOURCE DIALOG r_custom_dialog
{
flags = EGeneralQueryFlags;
buttons = R_AVKON_SOFTKEYS_EMPTY;
}
  • 运行对话框
iSplashScreenDialog = new (ELeave) CSplashScreenDialog();
iSplashScreenDialog->ExecuteLD(R_CUSTOM_DIALOG);
// Execution continues here after dialog has hided itself
iSplashScreenDialog = NULL;
  • 后记

该对话框可以显示2秒

Version Hint

Windows Phone: [[Category:Windows Phone]]
[[Category:Windows Phone 7.5]]
[[Category:Windows Phone 8]]

Nokia Asha: [[Category:Nokia Asha]]
[[Category:Nokia Asha Platform 1.0]]

Series 40: [[Category:Series 40]]
[[Category:Series 40 1st Edition]] [[Category:Series 40 2nd Edition]]
[[Category:Series 40 3rd Edition (initial release)]] [[Category:Series 40 3rd Edition FP1]] [[Category:Series 40 3rd Edition FP2]]
[[Category:Series 40 5th Edition (initial release)]] [[Category:Series 40 5th Edition FP1]]
[[Category:Series 40 6th Edition (initial release)]] [[Category:Series 40 6th Edition FP1]] [[Category:Series 40 Developer Platform 1.0]] [[Category:Series 40 Developer Platform 1.1]] [[Category:Series 40 Developer Platform 2.0]]

Symbian: [[Category:Symbian]]
[[Category:S60 1st Edition]] [[Category:S60 2nd Edition (initial release)]] [[Category:S60 2nd Edition FP1]] [[Category:S60 2nd Edition FP2]] [[Category:S60 2nd Edition FP3]]
[[Category:S60 3rd Edition (initial release)]] [[Category:S60 3rd Edition FP1]] [[Category:S60 3rd Edition FP2]]
[[Category:S60 5th Edition]]
[[Category:Symbian^3]] [[Category:Symbian Anna]] [[Category:Nokia Belle]]

This page was last modified on 27 August 2012, at 05:10.
87 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×