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

📄 capturescreenappui.cpp

📁 Symbian UIQ3平台输入法应用。
💻 CPP
字号:
/*****************************************************************************

 
 COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2006.

 

 The software is the copyrighted work of Sony Ericsson Mobile Communications AB.

 The use of the software is subject to the terms of the end-user license 

 agreement which accompanies or is included with the software. The software is 

 provided "as is" and Sony Ericsson specifically disclaim any warranty or 

 condition whatsoever regarding merchantability or fitness for a specific 

 purpose, title or non-infringement. No warranty of any kind is made in 

 relation to the condition, suitability, availability, accuracy, reliability, 

 merchantability and/or non-infringement of the software provided herein.

 

 *****************************************************************************/
 

// capturescreenAppUi.cpp

#include "capturescreenAppUi.h"
#include <QikCommand.h>

#include <Mda\Common\Video.h>
#include "capturescreenBaseView.h"

#include <EIKDIALG.H>

#include "capturescreen.rsg"


/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/
void CcapturescreenAppUi::ConstructL()
{
  	CQikAppUi::ConstructL();
  	CcapturescreenBaseView* baseView = CcapturescreenBaseView::NewLC(*this);
  	AddViewL(*baseView);
  	iBaseView = baseView;
  	CleanupStack::Pop(baseView);
  
 	iPeriodic = CPeriodic::NewL(CActive::EPriorityStandard);
	iMda = CMdaImageBitmapToFileUtility::NewL(*this);
	iBitmap = new (ELeave) CFbsBitmap;	
}

/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/
CcapturescreenAppUi::~CcapturescreenAppUi()
{
	iMda->Cancel();	
	iMda->Close();

	delete iPeriodic;
	delete iMda;
	delete iBitmap;	
}

/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/
void CcapturescreenAppUi::HandleCommandL(CQikCommand &aCommand)
{
  	TQikViewMode viewMode = iBaseView->ViewMode();

  	switch(aCommand.Id())
  	{
        case EMyAbout:
        {
           CEikDialog* dialog = new (ELeave) CEikDialog();             
           dialog->ExecuteLD(R_ABOUT_DIALOG);        
        }
        return;


        case EMyCaptureToD:
        {
        	iDrive = DriveD;
        	StartCapture();
        }
        return;


        case EMyCaptureToC:
        {
        	iDrive = DriveC;
        	StartCapture();
        }
        return;


        case EMyStop:
        {
        	StopCapture();
        }
        return;


  	}
  	CQikAppUi::HandleCommandL(aCommand);
}






/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/ 
void CcapturescreenAppUi::StopCapture()
{        
	if(iPeriodic->IsActive())
	{
		iPeriodic->Cancel();
	}
	
	InfoMessage(_L("Capture stopped"), _L(""));		
}





/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/ 
void CcapturescreenAppUi::StartCapture()
{        
	if(iPeriodic->IsActive())
	{
		iPeriodic->Cancel();
	}


	iTime = 31;
	updateTime();
			
	TBuf<64> message;

	TBuf<32> text;
	text.Num(30); 	

	message.Append(_L("Countdown: "));
	message.Append(text);
	
	if(iDrive == DriveC)
	{
		iBaseView->SetCurrentText(_L("Capturing screen to C:"));			
	}
	else
	{
		iBaseView->SetCurrentText(_L("Capturing screen to D:"));
	}	
	
	iBaseView->SetText(message);
	
   	iPeriodic->Start(1000000, 1000000, TCallBack(MyFunc,this));
}





/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/ 
void CcapturescreenAppUi::updateTime()
{
	iTime--;

	iBaseView->SetTime(iTime);

	if(iTime == 0)
	{
		capture();
	}
}






/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/  
TInt CcapturescreenAppUi::MyFunc(TAny* aObj)
{
  CcapturescreenAppUi* p = (CcapturescreenAppUi*)aObj;

  p->updateTime();
  
  return 0;
}


/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/  
void CcapturescreenAppUi::InfoMessage(const TDesC &text)
{  
	iBaseView->SetCurrentText(text);
	iBaseView->SetText(_L(""));			
	User::InfoPrint(text);
}


/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/  
void CcapturescreenAppUi::InfoMessage(const TDesC &currentText, const TDesC &text)
{  
	iBaseView->SetCurrentText(currentText);
	iBaseView->SetText(text);	
	User::InfoPrint(currentText);
}





/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/  
void CcapturescreenAppUi::capture()
{        
	iPeriodic->Cancel();
	if(iMda->IsActive())
	{
		return;
	}

	CWsScreenDevice& sd =  *CEikonEnv::Static()->ScreenDevice();

	TSize screenSize = sd.SizeInPixels();
	TDisplayMode displayMode = sd.DisplayMode();

	User::LeaveIfError(iBitmap->Create(screenSize, displayMode));

	TInt error = sd.CopyScreenToBitmap(iBitmap);		
  			
	if(error != KErrNone)
	{
		User::InfoPrint(_L("Could not capture screen"));		    			
		return;	
	}


	//resize if flip closed
	TQikUiConfig cc = CQUiConfigClient::Static().CurrentConfig(); 
	TInt screenmode = cc.ScreenMode();

	if(screenmode == EQikUiConfigSmallPortrait)
	{
		iBitmap->Resize(TSize(240, 256));
	}
	else if(screenmode == EQikUiConfigSmallLandscape)
	{
		iBitmap->Resize(TSize(256, 240));
	}

								
	TFileName aFile;
	if(!CreateUniqueFileName(aFile))
	{
		InfoMessage(_L("Could not create file"));
		return;
	}


	TMda24BppBmpCodec codec;
	TMdaBmpClipFormat format;
				
	iMda->CreateL(aFile, &format, &codec, NULL);
}








/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/  
bool CcapturescreenAppUi::CreateUniqueFileName(TFileName& aFile)
{
	RFs& fs = CEikonEnv::Static()->FsSession();

	TBuf<64> path;

	TBuf<64> bmp;
	bmp = _L(".bmp");


	if(iDrive == DriveD)
	{
		path = _L("d:\\capture");		
	}
	else
	{
		path = _L("c:\\Media files\\picture\\capture");
	}


	for(int i = 0 ; i < 100 ; i++)
	{
		TBuf<32> mynum;
		mynum.Num(i);

		aFile.Format(_L("%S%S%S"), &path, &mynum, &bmp);

		TUint	attrib;
		if (fs.Att(aFile, attrib) != KErrNone)
		{
			return true;
		}
	}


	return false;
}





/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/  
void CcapturescreenAppUi::MiuoCreateComplete(TInt aError)
{
	if (aError != KErrNone)
	{
		InfoMessage(_L("Capture failed"));				
		return;
	}
	
	
	TRAPD(err, iMda->ConvertL(*iBitmap, 0));
	if(err != KErrNone)
	{
		InfoMessage(_L("Capture failed"));
	}
}


/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/  
void CcapturescreenAppUi::MiuoOpenComplete(TInt aError)
{
	if (aError)
	{
		InfoMessage(_L("MiuoOpenComplete failed"));
	}

}


/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/  
void CcapturescreenAppUi::MiuoConvertComplete(TInt aError)
{
	if (aError)
	{
		InfoMessage(_L("MiuoConvertComplete failed"));	
	}
	else
	{
		if(iDrive == DriveC)
		{
			InfoMessage(_L("Screen captured to C:"),_L(""));
		}
		else
		{
			InfoMessage(_L("Screen captured to D:"),_L(""));		
		}		
	}	
}

⌨️ 快捷键说明

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