⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mydialog.cpp

📁 symbian下自制按钮实现
💻 CPP
字号:
// MyDialog.cpp: implementation of the CMyDialog class.
//
//////////////////////////////////////////////////////////////////////



#include <avkon.hrh>
#include <eiklabel.h> 

#include <aknappui.h>

#include <StuSym.rsg>
#include "stusym.hrh"
#include "MyDialog.h"
#include <aknnotewrappers.h> 

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

CMyDialog::CMyDialog( TRect aRect ):iRect(aRect)
{  
    igBtn[0] = NULL ;
	igBtn[1] = NULL ;
    igBtn[2] = NULL ;  
}

CMyDialog::~CMyDialog( ) 
{
	/*
	delete igBtn[0] ;
	delete igBtn[1] ;
	delete igBtn[2] ;
	*/

}  

TBool CMyDialog::RunAaaLD( TRect & aRect )
{
   CMyDialog * pDlg = new(ELeave)CMyDialog(aRect) ;
   pDlg->PrepareLC(R_STUSYM_BTNDLG_DLG) ;
   // pDlg->SetRect( aRect ) ;
   return pDlg->RunLD(  ) ;
   //pDlg->run 
   //return  pDlg->ExecuteLD(R_STUSYM_BTNDLG_DLG ) ; 
   //return ETrue ;
}

TBool CMyDialog::OkToExitL(TInt aButtonId)
{
	// Translate the button presses into commands for the appui & current
	// view to handle
	if (aButtonId == EAknSoftkeyOk)
	{
		 //iAvkonAppUi->ProcessCommandL(EAknSoftkeyOk);
		 //增加处理代码
		 return ETrue ;
	}
	// It's not ok to exit the dialog as this is the main window. Let the appui decide
	// what to do in exit conditions
}

void CMyDialog::PreLayoutDynInitL(  ) 
{   
   igBtn[0] = static_cast<CBtnCtrl*>(ControlOrNull(EDlg_BtnDlg_Line_UPLOAD_ID));
   igBtn[1] = static_cast<CBtnCtrl*>(ControlOrNull(EDlg_BtnDlg_Line_DOWNLOAD_ID));
   igBtn[2] = static_cast<CBtnCtrl*>(ControlOrNull(EDlg_BtnDlg_Line_VIEW_ID));
}

void CMyDialog::PostLayoutDynInitL( )
{
	
    igBtn[0]->SetExtent(TPoint(5,0),TSize(50,20) ) ;
	igBtn[1]->SetExtent(TPoint(5,21),TSize(50,20) ) ;
	igBtn[2]->SetExtent(TPoint(5,42),TSize(50,20) ) ;
	this->ResetLineMinimumSizes( ) ;
}

TKeyResponse CMyDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
   
   	if (aType != EEventKey)
	{
		return EKeyWasNotConsumed;
	}

    if (aKeyEvent.iScanCode == EStdKeyUpArrow)
	{
        igBtn[inCurrBtn]->SetFocus(EFalse,EDrawNow) ; 
        inCurrBtn-- ;
		if( inCurrBtn < 0 )
		   inCurrBtn= 2 ; 	
        igBtn[inCurrBtn]->SetFocus( ETrue ,EDrawNow) ; 
	    return EKeyWasConsumed;
	}
	else if (aKeyEvent.iScanCode == EStdKeyDownArrow)
	{
	    igBtn[inCurrBtn]->SetFocus(EFalse,EDrawNow) ; //原来的失去焦点 
	    inCurrBtn++ ; 
        inCurrBtn %= 3 ;
        igBtn[inCurrBtn]->SetFocus(ETrue,EDrawNow) ; //现在的获取焦点  
		return EKeyWasConsumed;
	}
	else if (aKeyEvent.iScanCode == EStdKeyDevice3)
	{

          TBuf<20> strHint ;   
          switch (inCurrBtn) 
          {
            case EBtnUp :
			{
    			_LIT(kStrUP,"正在上传!") ;
                strHint.Append(kStrUP)  ;
                break;
			}
            case EBtnDown :
			{ 
			    _LIT(kStrDown,"正在下载!") ;
                strHint.Append(kStrDown)  ;
                break; 
			}
            case EBtnView :
			{
				 _LIT(kStrView,"正在查看!") ;
                strHint.Append(kStrView)  ;
                break ;                
			}

            default :
				//User::Panic(KShapeDrawerPanicName, EShapeDrawerInvalidBrushType);
				return  EKeyWasConsumed  ;
         }

		CAknInformationNote * pNote = new(ELeave)CAknInformationNote( ) ;
 		pNote->ExecuteLD(strHint ) ;
       
		return EKeyWasConsumed;
	}
   	return EKeyWasNotConsumed ;
}


SEikControlInfo CMyDialog::CreateCustomControlL(TInt aControlType)
{
	SEikControlInfo controlInfo;
	controlInfo.iControl = NULL;
	controlInfo.iTrailerTextId = 0;
	controlInfo.iFlags = 0;
    
	TRect btnRect , cltRect ;
    cltRect = Rect( ) ;

	switch (aControlType)
	{
	case ECustomCtrl_UPLOAD_Btn: //上传 
	{
        TPoint iTl =cltRect.iTl;
        btnRect.iTl = TPoint(iTl.iX + 5, iTl.iY + 5) ;
	    btnRect.SetWidth( 50 ) ;
        btnRect.SetHeight(20 ) ;
        _LIT(kStrUp,"上传");
		controlInfo.iControl = CBtnCtrl::NewL(btnRect,this,kStrUp);
		break;
    }
	case ECustomCtrl_DOWNLOAD_Btn: // 下载
	{
		TPoint iTl =cltRect.iTl;
        btnRect.iTl = TPoint(iTl.iX + 5, iTl.iY + 30) ;
	    btnRect.SetWidth( 50 ) ;
        btnRect.SetHeight(20 ) ;
        _LIT(kStrDown,"下载");
		controlInfo.iControl = CBtnCtrl::NewL(btnRect,this,kStrDown);
		break;
    }
	case ECustomCtrl_VIEW_Btn: //查看
	{
		TPoint iTl =cltRect.iTl;
        btnRect.iTl = TPoint(iTl.iX + 5, iTl.iY + 55) ;
	    btnRect.SetWidth( 50 ) ;
        btnRect.SetHeight(20 ) ;
        _LIT(kStrView,"查看");
		controlInfo.iControl = CBtnCtrl::NewL(btnRect,this,kStrView);
		break;
    }
	default:
		break;
	}
	return controlInfo;
}

  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -