当前位置: 首页>>代码示例>>C++>>正文


C++ CConsoleBase::ReadCancel方法代码示例

本文整理汇总了C++中CConsoleBase::ReadCancel方法的典型用法代码示例。如果您正苦于以下问题:C++ CConsoleBase::ReadCancel方法的具体用法?C++ CConsoleBase::ReadCancel怎么用?C++ CConsoleBase::ReadCancel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CConsoleBase的用法示例。


在下文中一共展示了CConsoleBase::ReadCancel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

TInt GetNumberEntry
(
	const TInt aMaxDigits,	// max numbers of digits
	const TInt aMin,		// min value allowed
	const TInt aMax,		// max value allowed
	const TInt aInputWait,	// (s) how long to wait for each user key entry
	const TInt aDefaultVal,	// default value if timed out
	const TDesC &aPrompt	// string prompt
)
/**
 * This method gets numeric user entry from the console. It checks that the key entered
 * is between 0 to 9 inclusive. This method exits by user hitting the
 * Enter key or timing out.
 *
 * @param aMaxNumbers integer for max numbers of digits
 * @param aMin integer for min value allowed
 * @param aMax integer for max value allowed
 * @param aInputWait integer for number of seconds to wait for each user key entry
 * @param aDefaultVal integer for default value if time-out occurs without
 * @param aPrompt string prompt
 * @return KErrNone.
 */
{
TInt keyFolded;				 // actual digit entered, not TKeyCode
TRequestStatus stat1,stat2;
RTimer timer;
TBool bCorrectEntry = EFalse;
TInt userNum = -1;
TInt limit;
TKeyCode key;

	TTimeIntervalMicroSeconds32 anInterval = aInputWait * 1000000;
	CConsoleBase *pConsole = test.Console();
	timer.CreateLocal();

	while (!bCorrectEntry)
		{
		userNum = -1;
		limit = aMaxDigits;
		key = EKeyNull;

		INFO_PRINTF1(aPrompt); // print prompt
		INFO_PRINTF1(_L(" (range %d-%d) or <CR> for default of %d: "), aMin, aMax, aDefaultVal);
		// exits loop when Enter keyed or limit reached (by decrement to 0)
		while ((key != EKeyEnter) && limit)
			{
			pConsole->Read(stat1);				// set read
			timer.After(stat2, anInterval);		// set wait for this period
			User::WaitForRequest(stat1,stat2);  // whatever comes first

			if(stat1 == KErrNone)					// user entered key
				{
				timer.Cancel();
				User::WaitForRequest(stat2);

				key = pConsole->KeyCode();
				if((key >= '0') && (key <= '9'))
					{
					// valid digit
					keyFolded = (TKeyCode)(key - '0');  // convert to digit
					INFO_PRINTF1(_L("%d"), keyFolded);	// echo
					limit--;			// tracks number of digits

					// "append" to number
					if (-1 == userNum)	   // ie first char entered
						{
						userNum = keyFolded;
						}
					else					//  next char entered
						{
						userNum = userNum * 10 + keyFolded;  // shift
						}
					}
				}
			else	// timer went off, use default unless valid key entered before timer expired
				{
				pConsole->ReadCancel();
				User::WaitForRequest(stat1);
				if (-1 == userNum)
					{
					// no value entered before timer went off
					userNum = aDefaultVal;
					}
				break;
				}
			} // endwhile

		test.Printf (_L("\n"));
		if ((userNum >= aMin) && (userNum <= aMax))
			{
			bCorrectEntry = ETrue;  // exit loop
			}
		else						// return to loop
			{
			if (userNum == -1)
				{
				// <CR> was entered before any numbers, so use default
				userNum = aDefaultVal;
				break;
				}
//.........这里部分代码省略.........
开发者ID:cdaffara,项目名称:symbiandump-os1,代码行数:101,代码来源:Te_LoopBackt_tsylb.cpp

示例2: DoCancel

// Cancel asynchronous read.
void ConsoleUI::DoCancel()
{
    con_->ReadCancel();
}
开发者ID:Antares84,项目名称:asuswrt-merlin,代码行数:5,代码来源:app_main.cpp


注:本文中的CConsoleBase::ReadCancel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。