终端控件示例
此样本程序演示如何使用 IccTerminal , IccTermId 和 IccTerminalData 类。
前两行包括 Foundation Classes 的头文件以及用于为应用程序设置操作环境的标准 main 函数。
void IccUserControl::run()
{
IccTerminal& term = *terminal();
term.erase();
IccUserControl 类的 run 方法包含此示例的用户代码。 作为要使用的终端,示例通过创建终端对象并清除关联的屏幕来启动。
term.sendLine( "First part of the line..." );
term.send( "... a continuation of the line." );
term.sendLine( "Start this on the next line" );
term.sendLine( 40, "Send this to column 40 of current line" );
term.send( 5, 10, "Send this to row 5, column 10" );
term.send( 6, 40, "Send this to row 6, column 40" );
此片段显示如何使用 send 和 sendLine 方法将数据发送到终端。 All of these methods can take IccBuf references (const IccBuf&) instead of string literals (const char*).
term.setNewLine();
这将向屏幕发送空行。
term.setColor( IccTerminal::red );
term.sendLine( "A Red line of text.");
term.setColor( IccTerminal::blue );
term.setHighlight( IccTerminal::reverse );
term.sendLine( "A Blue, Reverse video line of text.");
setColor 方法用于设置屏幕上文本的颜色,而 setHighlight 方法用于设置突出显示。
term << "A cout sytle interface... " <<
endl;
term << "you can " << "chain input together; "
<< "use different types, eg numbers: " << (short)123 <<
" "
<< (long)4567890 << " " << (double)123456.7891234
<< endl;
term << "... and everything is buffered till you issue a flush."
<< flush;
此片段显示如何使用类似于 iostream 的接口 endl 在下一行上启动数据。 为了提高性能,您可以在发出 flush 之前缓冲终端中的数据,这会将数据发送到屏幕。
term.send( 24,1, "Program 'icc$trm' complete: Hit PF12
to End" );
term.waitForAID( IccTerminal::PF12 );
term.erase();
waitForAID 方法导致终端在调用 擦除 方法以清除显示之前等待指定的键被命中。
return;
}
run 结束,这会将控制权返回给 CICS®。