本文整理汇总了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;
}
//.........这里部分代码省略.........
示例2: DoCancel
// Cancel asynchronous read.
void ConsoleUI::DoCancel()
{
con_->ReadCancel();
}