简单自定义控件在view下可以运行在传统模式下运行显示空白

摘要:
简单的自定义控件-可以在视图中运行-可以在传统模式下运行。描述了空白显示的问题。我编写了一个自定义控件头文件#include<coectrl h>classCSimControl:publicCCoeControl{public:staticSimControl*NewL(constTRect&aRect,constCCoeControl*aParent);staticSimControl*NewLC

简单自定义控件-在view下可以运行-在传统模式下运行显示空白

问题描述

我写了一个自定义控件
头文件

#include <coecntrl.h>

class CSimControl : public CCoeControl  
{
public:
    
static CSimControl* NewL(const TRect& aRect,const CCoeControl* aParent);
    
static CSimControl* NewLC(const TRect& aRect,const CCoeControl* aParent);
public:
    CSimControl();
    
virtual ~CSimControl();
    
void Draw(const TRect& aRect) const;
    
void SizeChanged();
private:
    
void ConstructL(const TRect& aRect,const CCoeControl* aParent );
};

代码文件

#include "SimControl.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSimControl::CSimControl()
{

}

CSimControl::
~CSimControl()
{

}

CSimControl
* CSimControl::NewL( const TRect& aRect,const CCoeControl* aParent )
{
    CSimControl
* self = CSimControl::NewLC(aRect,aParent);
    CleanupStack::Pop();
    
return self;
}

CSimControl
* CSimControl::NewLC( const TRect& aRect,const CCoeControl* aParent )
{
    CSimControl
* self = new(ELeave)CSimControl();
    CleanupStack::PushL(self);
    self
->ConstructL(aRect,aParent);
    
return self;
}

void CSimControl::Draw( const TRect& aRect ) const
{

    CWindowGc
& gc = SystemGc();
    gc.Clear(aRect);
    
    gc.SetPenStyle(CGraphicsContext::ESolidPen);
    gc.SetPenColor(KRgbBlack);
    gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    gc.SetBrushColor(KRgbBlack);

    gc.DrawEllipse(aRect);
}

void CSimControl::SizeChanged()
{
    
}

void CSimControl::ConstructL(const TRect& aRect,const CCoeControl* aParent )
{
    
if (aParent == NULL)
    {
        CreateWindowL();
    } 
else
    {
        SetContainerWindowL(
*aParent);
    }
    SetRect(aRect);
    ActivateL();
}
 

我在 view 下可以显示这个控件,但是在传统模式下无法运行,传统模式下的代码

#include "SimControlLX2Container.h"

#include 
<eiklabel.h>  // for example label control


// ================= MEMBER FUNCTIONS =======================

// ---------------------------------------------------------
// CSimControlLX2Container::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CSimControlLX2Container::ConstructL(const TRect& aRect)
    {
    CreateWindowL();

    iLabel 
= new (ELeave) CEikLabel;
    iLabel
->SetContainerWindowL( *this );
    iLabel
->SetTextL( _L("Example View") );

    iToDoLabel 
= new (ELeave) CEikLabel;
    iToDoLabel
->SetContainerWindowL( *this );
    iToDoLabel
->SetTextL( _L("Add Your controls\n here") );

        iSimControl 
= CSimControl::NewL(aRect,NULL);
        iSimControl
->SetContainerWindowL(*this);
    SetRect(aRect);
    ActivateL();
    }

// Destructor
CSimControlLX2Container::~CSimControlLX2Container()
    {
    delete iLabel;
    delete iToDoLabel;
        delete iSimControl;
    }

// ---------------------------------------------------------
// CSimControlLX2Container::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CSimControlLX2Container::SizeChanged()
    {
    
// TODO: Add here control resize code etc.
    iLabel->SetExtent( TPoint(10,10), iLabel->MinimumSize() );
    iToDoLabel
->SetExtent( TPoint(10,100), iToDoLabel->MinimumSize() );
    }

// ---------------------------------------------------------
// CSimControlLX2Container::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CSimControlLX2Container::CountComponentControls() const
    {
    
return 3// return nbr of controls inside this container
    }

// ---------------------------------------------------------
// CSimControlLX2Container::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CSimControlLX2Container::ComponentControl(TInt aIndex) const
    {
    
switch ( aIndex )
        {
        
case 0:
            
return iLabel;
        
case 1:
            
return iToDoLabel;
                
case 2:
                        
return iSimControl;        default:
            
return NULL;
        }
    }

// ---------------------------------------------------------
// CSimControlLX2Container::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CSimControlLX2Container::Draw(const TRect& aRect) const
    {
    CWindowGc
& gc = SystemGc();
    
// TODO: Add your drawing code here
    
// example code...
    gc.SetPenStyle( CGraphicsContext::ENullPen );
    gc.SetBrushColor( KRgbGray );
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect( aRect );
    }

// ---------------------------------------------------------
// CSimControlLX2Container::HandleControlEventL(
//     CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CSimControlLX2Container::HandleControlEventL(
    CCoeControl
* /*aControl*/,TCoeEvent /*aEventType*/)
    {
    
// TODO: Add your control event handler code here
    }


// End of File  

运行后,屏幕一片空白
找了好长时间也不有找到原因,后来在网友的帮助下终于找到原因了

就是在 Container 中的 SizeChange 方法也要添加代码

void CSimControlLX2Container::SizeChanged()
    {
    
// TODO: Add here control resize code etc.
    iLabel->SetExtent( TPoint(10,10), iLabel->MinimumSize() );
    iToDoLabel
->SetExtent( TPoint(10,100), iToDoLabel->MinimumSize() );
    TSize aSize;
    aSize.SetSize(
200,200);
    iSimControl
->SetExtent(TPoint(10,10
),aSize);
    }

加粗部分是

现在还有一个缺点是,没有画全,不过没有关系,这个应该在后面就可以解决了

终于走出了一步了

免责声明:文章转载自《简单自定义控件在view下可以运行在传统模式下运行显示空白》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇在Unity中使用Lua脚本【问题解决记录】无法识别的标志“-sdlMode”,在“p2”中下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

VC:CString用法整理(转载)

1.CString::IsEmpty BOOL IsEmpty( ) const; 返回值:如果CString 对象的长度为0,则返回非零值;否则返回0。 说明:此成员函数用来测试一个CString 对象是否是空的。 示例: 下面的例子说明了如何使用CString::IsEmpty。 // CString::IsEmpty 示例 CStrin...

elementui源码解析markdown处理

一些参考网址: markdown-it官网:markdown-it | markdown-it 中文文档 (docschina.org) markdown-it插件的分析和源码分析参考地址:https://zhuanlan.zhihu.com/p/64290806 参考例子:https://gitee.com/springliuliu/mdToHtm...

FFmpeg原始帧处理-滤镜API用法详解

本文为作者原创,转载请注明出处:https://www.cnblogs.com/leisure_chn/p/10429145.html 在 FFmpeg 中,滤镜(filter)处理的是未压缩的原始音视频数据(RGB/YUV视频帧,PCM音频帧等)。一个滤镜的输出可以连接到另一个滤镜的输入,多个滤镜可以连接起来,构成滤镜链/滤镜图,各种滤镜的组合为 FFm...

使用Tensorflow对模型进行量化

本文旨在将迁移学习训练好的模型基于tensorflow工具进行量化。 环境配置及迁移学习部分可参考博文[https://www.cnblogs.com/hayley111/p/12887853.html]。 首先使用如下workflow理解模型部署的过程,本文主要描述的是quant这一步。 1. 环境准备: 安装bazel bazel是一个开源的构造和测...

前端上传数据-图片和视频格式校验

上一篇用 promise 嵌套实现了按 excel 行顺序上传数据,这篇要解决的问题是图片和视频格式校验,图片主要有 jpg png gif 视频 mp4 由于用户选择的资源可能并不是真正的多媒体文件,使用 js 的 file.type 方法获取的文件类型可能不准确,比如将 .xlsx 改为 .jpg, file.type 得到的类型是image/jpeg...

L3-002 特殊堆栈 (30分) vector容器的模拟、vector容器的一些用法

vector容器的简单应用,我们可以用vector维护一个有序数组,每次对要插入的数用upper_bound或者lower_bound来 为这个数找一个应该插入到vector的位置。另外再找一个数组来维护插入数的顺序,来面对pop操作 在从小到大的排序数组中, lower_bound( begin,end,num):从数组的begin位置到end-1位置...