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

📄 worldview.cpp

📁 Symbian多视图下实现菜单的隐藏
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CWorldView from CAknView
*  Part of  : World
*  Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/

// INCLUDE FILES
#include <aknviewappui.h>
#include <avkon.hrh>

#include <Ldcno17song.rsg>
#include "Ldcno17song.hrh"
#include "WorldView.h"
#include "WorldContainer.h" 

#include "Ldcno17song.mbg"
#include "akncontext.h"
#include "akntitle.h"
#include "Ldcno17songappui.h"

#include "HelloView.h"
#include <aknnotewrappers.h>

#include <eikmenup.h>		//for CEikMenuPane
#include <eikmenub.h>	// for CEikMenuBar

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

// C++ default constructor can NOT contain any code, that
// might leave.
//
CWorldView* CWorldView::NewL()
{
    CWorldView* self = NewLC();
    CleanupStack::Pop(self);
    return self;
}

CWorldView* CWorldView::NewLC()
{
    CWorldView* self = new (ELeave) CWorldView;
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
}

CWorldView::CWorldView()
    {
    }

// EPOC default constructor can leave.
void CWorldView::ConstructL()
    {
    BaseConstructL(R_WORLD_VIEW); // 
    }

// Destructor
CWorldView::~CWorldView()
    {
    }

// ---------------------------------------------------------
// TUid CWorldView::Id()
// Returns Id of the view.
// ---------------------------------------------------------
TUid CWorldView::Id() const
    {
    return KViewId2;
    }

// ---------------------------------------------------------
// CWorldView::HandleCommandL(TInt aCommand)
// Handles commands
// ---------------------------------------------------------
void CWorldView::HandleCommandL(TInt aCommand)
    {   
		switch(aCommand)
		{
		case ELdcno17songCmdWorldDispalyAllMenuItem:
			{	//  隐藏和显示开关;
			m_nMenuFlag = 0 ; // 显示菜单;	
			break;
			}
				
		case ELdcno17songCmdWorldHideMenuItem:
			{	// 隐藏菜单;
			m_nMenuFlag = 1 ; // 隐藏菜单;			
			break;
			}	
			
		case ELdcno17songCmdChageMenuBar:
			{
				//change the MenuBar of the view.
				//RESOURCE MENU_BAR R_FREE_INIT_MENUBAR
				//换成hello的menubar
				MenuBar()->SetMenuTitleResourceId( R_FREE_INIT_MENUBAR );		// 之前是WORLDMENU(VIEW)切换到HELLOview
				break;
			}
		case ELdcno17songHelloCmdBack:
			{
				
//				break;
			}
		case ELdcno17songWorldCmdBack:
			{
				//change the MenuBar of the view.
				//RESOURCE MENU_BAR R_FREE_INIT_MENUBAR
				//换成world的menubar
				MenuBar()->SetMenuTitleResourceId( R_MH_WORLD_MENUBAR );
			
				//显示和隐藏的开关:0.显示所有菜单栏
				m_nMenuFlag = 0;
				break;
			}

		case ELdcno17songCmdLogon:	//EMyWorldCmdChageView:
			{	//切换视图
				AppUi()->ActivateLocalViewL(KViewId1);				
				break;
			}
			
		default:
			{
				AppUi()->HandleCommandL(aCommand);		// 子菜单退出功能;
				break;
			}
		}
    }

// ---------------------------------------------------------
// CWorldView::HandleClientRectChange()
// Handles client rect change.
// ---------------------------------------------------------
void CWorldView::HandleClientRectChange()
    {
    if (iContainer)
        {
        iContainer->SetRect(ClientRect());
        }
    }

// ---------------------------------------------------------
// CWorldView::DoActivateL(...)
// Creates the Container class object.
// ---------------------------------------------------------
void CWorldView::DoActivateL(const TVwsViewId& /*aPrevViewId*/,
                                    TUid /*aCustomMessageId*/,
                                    const TDesC8& /*aCustomMessage*/)
    {
    iContainer = new (ELeave) CWorldContainer;
    iContainer->SetMopParent(this);


	TRect rc;	// 系统类实例化对象;
	rc.SetRect(ClientRect().iTl, TSize(176, 144));// 对象应用SetRect()设置区域,解决客户区域显示不全的问题;
    iContainer->ConstructL(rc); // WorldVIEW.h中定义的CWorldContainer* iContainer;
    //iContainer->ConstructL(ClientRect());
    AppUi()->AddToStackL(*this, iContainer); //视图类里的函数通过this指针调用 CCoeAppUi类的AddToStackL函数;


	TBuf<KMaxPath> pathMbm;
#ifdef __WINS__
	pathMbm.Copy(_L("z:\\system\\apps\\Ldcno17song\\Ldcno17song.mbm"));
#else
	CLdcno17songAppUi* pApp = (CLdcno17songAppUi*)CEikonEnv::Static()->AppUi();
	pApp->GetAppPath(pathMbm);
	pathMbm.Append(_L("Ldcno17song.mbm"));
#endif
	
	CEikStatusPane* statusPane = StatusPane();  //   得到一个面板,定义一个指向控制区域的指针;
	
	//set icon		// 定义图标;// 定义一个图标指针指向面板;
	CAknContextPane* contextPane = (CAknContextPane*) statusPane->ControlL(TUid::Uid(EEikStatusPaneUidContext));
	CFbsBitmap* bitmap = iEikonEnv->CreateBitmapL(pathMbm, EMbmLdcno17songSnoopy_1_icon);		// 图标;
	CFbsBitmap* bitmapMask = iEikonEnv->CreateBitmapL(pathMbm, EMbmLdcno17songSnoopy_1_mask);	
	
	//contextPane->SetPicture(bitmap);
	contextPane->SetPicture(bitmap, bitmapMask);
	
	//set title		// 定义标题;
	// 	CAknTitlePane* titlePane = (CAknTitlePane*) statusPane->ControlL(TUid::Uid(EEikStatusPaneUidTitle));
	// 	titlePane->SetTextL(_L("Hello view!"));
	
	//load chinese words  // 定义中文标题;
	TBuf<32> sTmpTitle;		// 标题;
	CEikonEnv::Static()->ReadResource(sTmpTitle, R_QTN_MH_HELLO_TITLE);   // 宏;
	
	CAknTitlePane* titlePane = (CAknTitlePane*) statusPane->ControlL(TUid::Uid(EEikStatusPaneUidTitle));
	titlePane->SetTextL(sTmpTitle);
	
	//show		// 显示函数,疑问是否是系统自带?
//	 	CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
// 			informationNote->ExecuteLD(sTmpTitle);
    }

// ---------------------------------------------------------
// CWorldView::DoDeactivate()
// Deletes the Container class object.
// ---------------------------------------------------------
void CWorldView::DoDeactivate()
    {
    if (iContainer)
        {
		AppUi()->RemoveFromStack(iContainer);
		delete iContainer;
		iContainer = NULL;
        }
    }

//菜单动态效果
void CWorldView::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)	// class CAknCcpuSupport 类中的函数;
{
	if(aResourceId != R_MH_WORLD_MENU)
		return;
	
	//标志位:相当于显示或不显示菜单栏的开关
	switch(m_nMenuFlag)
	{
	case 0://当m_nMenuFlag==0时,显示所有菜单栏,即不隐藏菜单栏
		{
			aMenuPane->SetItemDimmed(ELdcno17songCmdWorldDispalyAllMenuItem, ETrue);	// 系统定义T类中
			aMenuPane->SetItemDimmed(ELdcno17songCmdWorldHideMenuItem, EFalse);
			aMenuPane->SetItemDimmed(ELdcno17songCmdWorldSubMenuPane, EFalse);
			break;
		}
	case 1://当m_nMenuFlag==1时,隐藏部分菜单栏
		{
			aMenuPane->SetItemDimmed(ELdcno17songCmdWorldDispalyAllMenuItem, EFalse);
			aMenuPane->SetItemDimmed(ELdcno17songCmdWorldHideMenuItem, ETrue);
			aMenuPane->SetItemDimmed(ELdcno17songCmdWorldSubMenuPane, ETrue);
			break;
		}
	default:
		{
			break;
		}
	}
}

// End of File

⌨️ 快捷键说明

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