为了正常的体验网站,请在浏览器设置里面开启Javascript功能!
首页 > vc下的清屏函数

vc下的清屏函数

2017-11-13 5页 doc 20KB 11阅读

用户头像

is_180829

暂无简介

举报
vc下的清屏函数vc下的清屏函数 Ã?ÓÐÇåÆÁº?Êý ???ýÓÐ?öÏàµ?ÓëÇåÆÁµÄ?úÂë?º #include #include "stdafx.h" #include #include #include void ClearScreen(); int main(int argc, char* argv[]) { for (int i=0;i<10;i++) printf("%d,Hello World!\n",i); printf("press any key to clear scre...
vc下的清屏函数
vc下的清屏函数 Ã?ÓÐÇåÆÁº?Êý ???ýÓÐ?öÏàµ?ÓëÇåÆÁµÄ?úÂë?º #include #include "stdafx.h" #include #include #include void ClearScreen(); int main(int argc, char* argv[]) { for (int i=0;i<10;i++) printf("%d,Hello World!\n",i); printf("press any key to clear screen\n"); getch(); ClearScreen(); printf("done!\n"); getch(); return 0; } void ClearScreen() { HANDLE hOutput=GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO sbi; GetConsoleScreenBufferInfo(hOutput,&sbi); //?ÆËãµ??â?êÔÚ?º?åÖеÄÆ?ÒÆ DWORD len=sbi.dwSize.X*sbi.dwCursorPosition.Y+sbi.dwCursorPosition.X+1; COORD cd={0,0}; DWORD nw; //È???Ìî?ä?Õ?ñ FillConsoleOutputCharacter(hOutput,_T(' '),len,cd,&nw); //?ãµà,?â?ê?ص?×îÉÏ?Ç?ªÊ??? SetConsoleCursorPosition(hOutput,cd); } Top 2 Â?bljbljbljblj??Ã?ÔÂÇå?ç͵ÎÒÐÄ???Ø??ÓÚ 2002-09-23 07:54:00 µÃ?Ö 0 ÕâÊÇÎÒ?ÓÌì??ÍøµÄÒ?Î?ÀÏÐÖÄÇÑ?À?µÄ?? Top 3 Â?xiaoyueer??ÏþÔÂ?ù???Ø??ÓÚ 2002-09-23 08:53:49 µÃ?Ö 0 HOWTO: Performing Clear Screen (CLS) in a Console Application Q99261 -------------------------------------------------------------------------------- The information in this article applies to: Microsoft Win32 Application Programming Interface (API), used with: the operating system: Microsoft Windows NT, versions 3.51, 4.0 Microsoft Windows 95 the operating system: Microsoft Windows 2000 -------------------------------------------------------------------------------- SUMMARY Some non-Microsoft versions of C++ provide a clrscr function for clearing the screen in a DOS application. However, there is no Win32 Application Programming Interface (API) or C-Runtime function that will perform this function. There are two ways to accomplish this task for a Win32 console application. The first method is to use the system function as follows: #include void main() { system("cls"); } The second method is to write a function that will programmatically clear the screen. That method is described in the More Information section which follows. MORE INFORMATION The following function clears the screen: /* Standard error macro for reporting API errors */ #define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \ on line %d\n", __FILE__, GetLastError(), api, __LINE__);} void cls( HANDLE hConsole ) { COORD coordScreen = { 0, 0 }; /* here's where we'll home the cursor */ BOOL bSuccess; DWORD cCharsWritten; CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */ DWORD dwConSize; /* number of character cells in the current buffer */ /* get the number of character cells in the current buffer */ bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi ); PERR( bSuccess, "GetConsoleScreenBufferInfo" ); dwConSize = csbi.dwSize.X * csbi.dwSize.Y; /* fill the entire screen with blanks */ bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) ' ', dwConSize, coordScreen, &cCharsWritten ); PERR( bSuccess, "FillConsoleOutputCharacter" ); /* get the current text attribute */ bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi ); PERR( bSuccess, "ConsoleScreenBufferInfo" ); /* now set the buffer's attributes accordingly */ bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten ); PERR( bSuccess, "FillConsoleOutputAttribute" ); /* put the cursor at (0, 0) */ bSuccess = SetConsoleCursorPosition( hConsole, coordScreen ); PERR( bSuccess, "SetConsoleCursorPosition" ); return; } Additional query words: clearscreen Keywords : kbcode kbAPI kbConsole kbKernBase kbOSWinNT351 kbOSWinNT400 kbOSWin2000 kbDSupport kbGrpDSKernBase Issue type : kbhowto Technology : kbOSWin2000 kbOSWinNT kbOSWinSearch Last Reviewed: December 14, 2000 © 2001 Microsoft Corporation. All rights reserved. Terms of Use. -------------------------------------------------------------------------------- Send feedback to MSDN.Look here for MSDN Online resources.
/
本文档为【vc下的清屏函数】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索