如何在不填充屏幕的情况下清空屏幕

发布于 2024-12-17 17:19:20 字数 46 浏览 3 评论 0原文

是否存在中断服务例程来帮助我清除终端屏幕?它可以在 Windows 上运行吗?

Does an interrupt service routine exist to help me clear the screen of the terminal? Will it work on windows?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小耗子 2024-12-24 17:19:20

通过 BIOS 设置图形模式(int 10h,AH=0)将清除屏幕。

通过 BIOS 向上或向下滚动屏幕(int 10h,AH=6 或 7)也可以清除屏幕。

这只适用于您可以调用 BIOS 服务功能的情况。

MSDOS 是永远可以使用的地方。

在 Windows 中,这仅适用于 DOS 应用程序,并且 Windows 确实可以运行它们。 64 位版本的 Windows 根本不支持 DOS 应用程序,从 Windows Vista 开始,即使在 32 位版本的 Windows 中,许多 DOS 应用程序也无法完全运行。

还要记住,如果 DOS 应用程序在 Windows 的窗口中运行,则只有该窗口会被清除,而不是整个屏幕。

Setting a graphics mode through BIOS (int 10h with AH=0) will clear the screen.

Scrolling the screen up or down through BIOS (int 10h with AH=6 or 7) can clear the screen as well.

This will only work where you can invoke BIOS service functions.

MSDOS is where this will always work.

In Windows this will work only in DOS applications and if Windows can actually run them. 64-bit editions of Windows don't support DOS applications at all and starting with Windows Vista even in 32-bit editions of Windows many DOS apps don't work fully.

Remember also that if a DOS application runs in a window in Windows, only that window will get cleared, not the entire screen.

浪漫之都 2024-12-24 17:19:20

我让它工作(使用qemu,NASM)

http://www.gabrielececchetti.it/Teaching/CalcolatoriElettronici/Docs/i8086_and_DOS_interrupts.pdf

call cls
jmp $

cls:
  pusha
  mov ah, 0x00
  mov al, 0x03  ; text mode 80x25 16 colours
  int 0x10
  popa
  ret

I got this to work (used qemu, NASM)

(http://www.gabrielececchetti.it/Teaching/CalcolatoriElettronici/Docs/i8086_and_DOS_interrupts.pdf)

call cls
jmp $

cls:
  pusha
  mov ah, 0x00
  mov al, 0x03  ; text mode 80x25 16 colours
  int 0x10
  popa
  ret
装迷糊 2024-12-24 17:19:20

在汇编中,试试这个:

mov ah, 0x06
mov al, 0
int 10h

不,你不能在 Windows 上执行此操作。此代码只能用于引导加载程序和汇编内核(仅限 16 位,警告:请勿尝试 32 位!!!)

如果您想在 Windows(控制台应用程序)中执行此操作,请尝试以下操作:

C++

//YOU SHOULD INCLUDE STDIO.H and CONIO.H. You should also type:
//using namespace std

system("cls");

VB。 NET

//You should imports System and other Default namespaces
shell("cls")

C#

System.Diagnostics.Proccess.Start("CMD.exe /c cls");

注意:我认为我们无法使用 C# 或 VB 制作控制台应用程序。当然,我从来没有尝试过。只是说。但这些代码只适用于Windows。

In assembly, try this:

mov ah, 0x06
mov al, 0
int 10h

And no, you cannot do this on windows. This code can only be used for bootloaders, and assembly kernels (16 bit only, WARNING: DO NOT TRY ON 32 BIT!!!)

If you'd like to do in Windows (Console Applications), then try this:

C++

//YOU SHOULD INCLUDE STDIO.H and CONIO.H. You should also type:
//using namespace std

system("cls");

VB.NET

//You should imports System and other Default namespaces
shell("cls")

C#

System.Diagnostics.Proccess.Start("CMD.exe /c cls");

NOTE: I don't think we can make Console apps using C# or VB. Of course, i never tried. Just saying. But these codes only work for windows.

烙印 2024-12-24 17:19:20

对于 Windows 控制台应用程序,采用纯 C 语言:

#include <tchar.h>
#include <wincon.h>

VOID
ClearScreen(HANDLE hConsoleOutput)
{
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    COORD coPos;
    DWORD dwWritten;

    GetConsoleScreenBufferInfo(hConsoleOutput, &csbi);

    coPos.X = 0;
    coPos.Y = 0;
    FillConsoleOutputAttribute(hConsoleOutput, csbi.wAttributes,
                               csbi.dwSize.X * csbi.dwSize.Y,
                               coPos, &dwWritten);
    FillConsoleOutputCharacter(hConsoleOutput, TEXT(' '),
                               csbi.dwSize.X * csbi.dwSize.Y,
                               coPos, &dwWritten);
    SetConsoleCursorPosition(hConsoleOutput, coPos);
}

...

// In your main code:
/* Clear the full console screen */
ClearScreen(hOutput);

其中 hConsoleOutput 是控制台屏幕缓冲区的句柄(通过 GetStdHandle(STD_OUTPUT_HANDLE)CreateConsoleScreenBuffer( ...),或其他方式。
该函数的作用是,首先检索当前控制台屏幕缓冲区信息(包含其当前大小),然后使用默认文本属性和空格填充整个屏幕缓冲区,最后将光标置于 (0, 0)。

For Windows console applications, in plain C:

#include <tchar.h>
#include <wincon.h>

VOID
ClearScreen(HANDLE hConsoleOutput)
{
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    COORD coPos;
    DWORD dwWritten;

    GetConsoleScreenBufferInfo(hConsoleOutput, &csbi);

    coPos.X = 0;
    coPos.Y = 0;
    FillConsoleOutputAttribute(hConsoleOutput, csbi.wAttributes,
                               csbi.dwSize.X * csbi.dwSize.Y,
                               coPos, &dwWritten);
    FillConsoleOutputCharacter(hConsoleOutput, TEXT(' '),
                               csbi.dwSize.X * csbi.dwSize.Y,
                               coPos, &dwWritten);
    SetConsoleCursorPosition(hConsoleOutput, coPos);
}

...

// In your main code:
/* Clear the full console screen */
ClearScreen(hOutput);

where the hConsoleOutput is a HANDLE to a console screen-buffer (obtained either via GetStdHandle(STD_OUTPUT_HANDLE), or CreateConsoleScreenBuffer(...), or other means.
What this function does is to, first, retrieve the current console screen-buffer information (that contains its current size), then fill the complete screen-buffer with the default text attribute and with spaces, then finally place the cursor at (0,0).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文