1、创建:

新建工程,选择“控制台 EXE”类型

工程默认已添加两个文件,Program 为程序主模块,CConsole 为控制台类

常用属性和方法

Console.Title
Console.BufferWidth
Console.FullScreen

Console.Clear()
Console.Write()
Console.WriteText()
Console.WriteLine()
Console.ReadLine()
Console.ReadKey()
Console.ReadPassword()

更多属性和方法参见第3条

2、调试:

a、由于VB6 IDE固有原因,调试控制台程序时IDE无响应属正常现象,请勿手动关
闭控制台窗口!否则将直接退出IDE,请随时保存您的代码。

b、在[工程属性>生成>条件编译参数]选项中设置 VB_DEBUG=1 可帮助调试程序,
防止运行结束后直接退出控制台而看不到运行结果,正式编译时,可设为0。

3、编译:

a、启用 PowerVB Console Application Add-In 插件,在[外接程序]菜单中,选
择 Complie As Windows Console Application,可编译为 真正 的控制台程序。

b、控制台程序一般不使用对话框,推荐勾选[工程属性>通用>无用户界面]选项。

3、CConsole API 说明

属性:

■ BackColor
简介:背景色
原型:Public Property Get BackColor() As Byte
备注:值范围:0 - 15

■ BufferHeight
简介:缓冲区高度
原型:Public Property Get BufferHeight() As Integer

■ BufferWidth
简介:缓冲区宽度
原型:Public Property Get BufferWidth() As Integer

■ ConsoleWindow
简介:与控制台相关的窗口句柄
原型:Public Property Get ConsoleWindow() As Long

■ CursorCol
简介:光标所在列
原型:Public Property Get () As Integer

■ CursorRow
简介:光标所在行
原型:Public Property Get CursorRow() As Integer

■ CursorSize
简介:光标大小
原型:Public Property Get CursorSize() As Long
参数:值范围:1 - 100

■ CursorVisable
简介:光标是否可见
原型:Public Property Get CursorVisable() As Boolean

■ ForeColor
简介:前景色
原型:Public Property Get ForeColor() As Byte
备注:值范围:0 - 15

■ FullScreen
简介:是否全屏
原型:Public Property Get FullScreen() As Boolean

■ InputCodePage
简介:输入代码页
原型:Public Property Get InputCodePage() As Long

■ InputModeEcho
简介:输入模式 ENABLE_ECHO_INPUT
原型:Public Property Get InputModeEcho() As Boolean

■ InputModeInsert
简介:输入模式 ENABLE_INSERT_MODE
原型:Public Property Get InputModeInsert() As Boolean

■ InputModeLine
简介:输入模式 ENABLE_LINE_INPUT
原型:Public Property Get InputModeLine() As Boolean

■ InputModeMouse
简介:输入模式 ENABLE_MOUSE_INPUT
原型:Public Property Get InputModeMouse() As Boolean

■ InputModeProcessed
简介:输入模式 ENABLE_PROCESSED_INPUT
原型:Public Property Get InputModeProcessed() As Boolean

■ InputModeQuickEdit
简介:输入模式 ENABLE_QUICK_EDIT_MODE
原型:Public Property Get InputModeQuickEdit() As Boolean

■ InputModeWindow
简介:输入模式 ENABLE_WINDOW_INPUT
原型:Public Property Get InputModeWindow() As Boolean

■ OutputCodePage
简介:输出代码页
原型:Public Property Get OutputCodePage() As Long

■ OutputModeProcessed
简介:输出模式 ENABLE_PROCESSED_OUTPUT
原型:Public Property Get OutputModeProcessed() As Boolean

■ OutputModeWrapAtEol
简介:输出模式 ENABLE_WRAP_AT_EOL_OUTPUT
原型:Public Property Get OutputModeWrapAtEol() As Boolean

■ StdErr
简介:标准错误句柄
原型:Public Property Get StdErr() As Long

■ StdIn
简介:标准输入句柄
原型:Public Property Get StdIn() As Long

■ StdOut
简介:标准输出句柄
原型:Public Property Get StdOut() As Long

■ Title
简介:控制台标题
原型:Public Property Get Title() As String

■ ViewHeight
简介:视口高度
原型:Public Property Get ViewHeight() As Integer

■ ViewHeightMax
简介:最大视口高度
原型:Public Property Get ViewHeightMax() As Integer

■ ViewWidth
简介:视口宽度
原型:Public Property Get ViewWidth() As Integer

■ ViewWidthMax
简介:最大视口宽度
原型:Public Property Get ViewWidthMax() As Integer

方法:

● Clear
简介:清屏
原型:Public Sub Clear(Optional ByVal pToDefault As Boolean = False)
参数:是否恢复属性

● FillRectText
简介:填充矩形文本
原型:Public Function FillRectText( _
        ByVal pRow As Integer, _
        ByVal pCol As Integer, _
        ByVal pWidth As Integer, _
        ByVal pHeight As Integer, _
        ByVal pChar As Byte _
    ) As Long
参数:行
参数:列
参数:宽度
参数:高度
参数:字符
返回:实际填充数量

● FillRectAttribute
简介:填充矩形属性
原型:Public Function FillRectAttribute( _
        ByVal pRow As Integer, _
        ByVal pCol As Integer, _
        ByVal pWidth As Integer, _
        ByVal pHeight As Integer, _
        ByVal pForeColor As Byte, _
        ByVal pBackColor As Byte, _
        ByVal pReverseColor As Boolean _
    ) As Long
参数:行
参数:列
参数:宽度
参数:高度
参数:前景色
参数:背景色
参数:反转色
返回:实际填充数量

● FillRectEx
简介:填充矩形文本,扩展
原型:Public Function FillRectEx( _
        ByVal pRow As Integer, _
        ByVal pCol As Integer, _
        ByVal pWidth As Integer, _
        ByVal pHeight As Integer, _
        ByVal pChar As Byte, _
        ByVal pForeColor As Byte, _
        ByVal pBackColor As Byte, _
        ByVal pReverseColor As Boolean _
    ) As Long
参数:行
参数:列
参数:宽度
参数:高度
参数:字符
参数:前景色
参数:背景色
参数:反转色
返回:实际填充数量

● FillText
简介:填充文本
原型:Public Function FillText( _
        ByVal pRow As Integer, _
        ByVal pCol As Integer, _
        ByVal pCount As Long, _
        ByVal pChar As Byte _
    ) As Long
参数:行
参数:列
参数:字符
参数:数量
返回:实际填充数量

● FillTextAttribute
简介:填充属性
原型:Public Function FillTextAttribute( _
        ByVal pRow As Integer, _
        ByVal pCol As Integer, _
        ByVal pCount As Long, _
        ByVal pForeColor As Byte, _
        ByVal pBackColor As Byte, _
        ByVal pReverseColor As Boolean _
    ) As Long
参数:行
参数:列
参数:数量
参数:前景色
参数:背景色
参数:反转色
返回:实际填充数量

● FillTextEx
简介:填充文本,扩展
原型:Public Function FillTextEx( _
        ByVal pRow As Integer, _
        ByVal pCol As Integer, _
        ByVal pCount As Long, _
        ByVal pChar As Byte, _
        ByVal pForeColor As Byte, _
        ByVal pBackColor As Byte, _
        ByVal pReverseColor As Boolean _
    ) As Long
参数:行
参数:列
参数:数量
参数:字符
参数:前景色
参数:背景色
参数:反转色
返回:实际填充数量

● MakeAttribute
简介:合成字符属性
原型:Public Function MakeAttribute( _
        ByVal pForeColor As Byte, _
        ByVal pBackColor As Byte, _
        ByVal pReverseColor As Boolean _
    ) As Integer
参数:前景色
参数:背景色
参数:反转色
返回:合成的属性

● MoveCursor
简介:移动光标
原型:Public Sub MoveCursor(ByVal pRow As Integer, ByVal pCol As Integer)
参数:行
参数:列

● ReadBufferAttribute
简介:读取缓冲属性
原型:Public Function ReadBufferAttribute( _
        ByVal pRow As Integer, _
        ByVal pCol As Integer, _
        ByVal pCount As Long _
    ) As Integer()
参数:行
参数:列
参数:读取多少个属性
返回:属性数组,每个值1-4位为前景色,5-8位为背景色,15位为反转色

● ReadBufferText
简介:读取缓冲文本
原型:Public Function ReadBufferText( _
        ByVal pRow As Integer, _
        ByVal pCol As Integer, _
        ByVal pCount As Long _
    ) As String
参数:行
参数:列
参数:读取多少个
返回:读取的文本

● ReadKey
简介:读取键盘按键
原型:Public Function ReadKey() As Integer
返回:按键的虚拟键码,参考KeyCodeConstants枚局常量

● ReadLine
简介:读取整行输入
原型:Public Function ReadLine(Optional pPrompt As String = "") As String
参数:提示
返回:输入文本,不包括回车换行

● ReadPassword
简介:读取密码
原型:Public Function ReadPassword(Optional pPrompt As String = "") As String
参数:提示
返回:输入文本,不包括回车换行

● ReverseTextColor
简介:反转前景色和背景色
原型:Public Function ReverseTextColor( _
        ByVal pRow As Integer, _
        ByVal pCol As Integer, _
        ByVal pCount As Long, _
        ByVal pReverse As Boolean _
    ) As Long
参数:行
参数:列
参数:数量
参数:是否反转
返回:实际反转数量

● ReverseRectColor
简介:反转矩形前景色和背景色
原型:Public Function ReverseRectColor( _
        ByVal pRow As Integer, _
        ByVal pCol As Integer, _
        ByVal pWidth As Integer, _
        ByVal pHeight As Integer, _
        ByVal pReverse As Boolean _
    ) As Long
参数:行
参数:列
参数:宽度
参数:高度
参数:是否反转
返回:实际反转数量

● SetViewSize
简介:设置视口尺寸
原型:Public Sub SetViewSize(ByVal pWidth As Integer, ByVal pHeight As Integer)
参数:宽
参数:高

● SplitAttribute
简介:分解字符属性
原型:Public Function SplitAttribute( _
        ByVal pAttribute As Integer, _
        ByRef pForeColor As Byte, _
        ByRef pBackColor As Byte, _
        ByRef pReverseColor As Boolean _
    )
参数:属性
参数:前景色
参数:背景色
参数:反转色

● StrLen
简介:测试文本长度,单字节算1,双字节算2
原型:Public Function StrLen(pStr As String) As Long
参数:内容

● WriteBufferAttribute
简介:写入缓冲属性
原型:Public Function WriteBufferAttribute( _
        ByVal pRow As Integer, _
        ByVal pCol As Integer, _
        ByRef pAttributes() As Integer, _
        ByVal pCount As Long _
    ) As Long
参数:行
参数:列
参数:属性数组,每个属性值1-4位为前景色,5-8位为背景色,15位为反转色
参数:写入多少个字符
返回:实际写入多少个字符

● WriteLine
简介:写入整行文本
原型:Public Function WriteLine(Optional ByVal pBuf As String = "") As Long
参数:内容
返回:实际写入字符个数

● WriteLineEx
简介:写入整行文本,扩展
原型:Public Function WriteLineEx( _
        ByVal pBuf As String, _
        Optional ByVal pForeColor As Integer = -1, _
        Optional ByVal pBackColor As Integer = -1 _
    ) As Long
参数:内容
参数:前景色
参数:背景色
返回:实际写入字符个数

● WriteText
简介:写入文本
原型:Public Function WriteText(pBuf As String) As Long
参数:内容
返回:实际写入字符个数

● WriteTextEx
简介:写入文本,扩展
原型:Public Function WriteTextEx( _
        ByVal pBuf As String, _
        Optional ByVal pForeColor As Integer = -1, _
        Optional ByVal pBackColor As Integer = -1 _
    ) As Long
参数:内容
参数:前景色
参数:背景色
返回:实际写入字符个数

Views: 61

Hi, I’m 邓伟

本来无一物,何处惹尘埃

首评

发表回复