Symbian全屏显示问题

来源:互联网 发布:蛇口 兰溪谷 网络 编辑:程序博客网 时间:2024/05/01 14:22

一:
二阶构造函数里就有如下代码:
void CTestScreenAppUi::ConstructL()
{
BaseConstructL();
iAppContainer
=
new (ELeave) CTestScreenContainer;
iAppContainer
->SetMopParent(this );
iAppContainer
->
ConstructL( ClientRect() );
AddToStackL(iAppContainer);
}


    这里面有很关键的一句,就是我用红色显示的那段代码。它把当前UI的ClientRect()传递给Container类,我们都知道Container 类是控件类,负责整个程序的界面显示,那么UI传递给Container的这个ClientRect()到底是什么东东呢?我们看看SDK HELP:
ClientRect()
TRect ClientRect() const;

Description
Gets the area of the screen available to the application for drawing, not including the space that is available for any of the following, where required: non-application areas which should always be displayed, an application status pane, an application button group, an application menu bar, an application title band and an application tool bar.

Importantly, the co-ordinates of the rectangle are relative to the whole screen area so, for example, the co-ordinate for the top, left point of the area available for drawing may be (0, 45).

Return value
TRect The area of the screen available to the application for drawing.



    从Description我们可以看到:ClientRect()获得应用程序绘制的有效屏幕区域,但是这个区域不包括那些总是显示的非应用程序区域,比 如:应用程序状态面板(application status pane)、按钮(button group)、应用程序的菜单bar、标题、工具条。

而且更重要的是从下面一行可以看出,这个ClientRect()所获得区域的top-left坐标是(0,45)。

    通过上面的分析我们知道,UI在构造我们的Container时传递一个所谓的"客户矩形区域",这个"客户矩形区域"的top-left坐标是 (0,45),从而也就知道如果要让我们的程序全屏显示,那么我们需要改变的是构造Container的时候传递的矩形大小。

那么就有如下几种方法:

①如果我们知道屏幕尺寸,那么就可以把iAppContainer->ConstructL( );里面的参数改为TRect (0,0,176,208)。

②上面的程序不具有适配性,因为我们把屏幕的宽度和高度写死了。

    我们来看Symbian给我们提供的一个方法

ApplicationRect()
TRect ApplicationRect() const;

Description
Gets the total area of the screen available to the application. This includes the space that is available for a toolbar, toolband or title band, if the application requires them.

Return value
TRect The total area of the screen available to the application.

    Description写的很明显了,我就不翻译了。这个方法可以获得屏幕的整个尺寸,我们把程序可以改为:

iAppContainer->ConstructL( ApplicationRect() );

从而实现程序的全屏显示。


传统结构的应用,可以在继承自CAknAppUi的AppUi中通过隐藏按钮区:Cba()->MakeVisible(EFalse)和隐藏状态栏:

StatusPane()->MakeVisible(EFalse)来实现。

需要指出的是,以上操作最好在加载视图之前进行,例如:
 void CxxxAppUi::ConstructL()
    {
    BaseConstructL();
   
    Cba()->MakeVisible(EFalse);

    StatusPane()->MakeVisible(EFalse);

    iAppView = CxxxAppView::NewL( ClientRect() );
    }

也就是要先隐藏按钮区和状态栏,让视图控制获得按钮区(controlpane)和状态栏(statuspane)加上主屏幕(mainpane)的区域显示整个视图对象,否则就会出现视图控制区域非全屏的情况。

此外,AppUi中还必须定义一个HandleKeyEventL方法处理按键,如下:

 

 TKeyResponse  CxxxAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
if (aType==EEventKeyDown && (aKeyEvent.iScanCode == EStdKeyDevice0 || aKeyEvent.iScanCode == EStdKeyDevice1))   
{
Cba()->MakeVisible(ETrue);
}
else
{
Cba()->MakeVisible(EFalse);  
}
return EKeyWasNotConsumed;
}

这样可以在按左右功能键时显示按钮区,不用时再隐藏。

 


而多视图结构的应用(AppUi继承自CAknViewAppUi),最简单的方法是在某个视图(view)的容器(container)中:

 

 void CxxxContainer::ConstructL( const TRect& aRect )
{
...

SetExtentToWholeScreen();

ActivateL();
}

同样的左右功能键按下时可以按钮区,且不用定义HandleKeyEventL。要注意的是:SetExtentToWholeScreen()必须放在ActivateL()前。

另外,在多视图结构应用的AppUi中,StatusPane()->MakeVisible(EFalse)也同样有效,只是最好放在SetDefaultViewL()后

原创粉丝点击