Lm th? no ? th?c hi?n mn h?nh r? rng (CLS) trong m?t ?ng d?ng giao di?n i?u khi?n

D?ch tiu ? D?ch tiu ?
ID c?a bi: 99261 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?

? Trang ny

TM T?T

M?t s? phin b?n khng ph?i c?a Microsoft c++ cung c?p m?t ch?c nng clrscr ? xo mn h?nh trong m?t ?ng d?ng DOS. Tuy nhin, khng c khng c ch?c nng Win32 ?ng d?ng l?p tr?nh giao di?n (API) ho?c C-Runtime s? th?c hi?n ch?c nng ny.

? th?c hi?n tc v? ny cho m?t ?ng d?ng giao di?n i?u khi?n Win32, s? d?ng m?t trong nh?ng phng php sau y:
  • S? d?ng m?t hm h? th?ng.
  • Vi?t m?t ch?c nng l?p tr?nh s? r? rng mn h?nh.
Nh?ng phng php ny ?c m t? trong ph?n "Thng tin thm" sau.

THNG TIN THM

S? d?ng m?t ch?c nng h? th?ng

#include <stdlib.h>

void main()
{
   system("cls");
}
				

Vi?t m?t ch?c nng l?p tr?nh s? r? rng mn h?nh

Cc ch?c nng sau y xa mn h?nh:
 /* 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;
 }
				

Thu?c tnh

ID c?a bi: 99261 - L?n xem xt sau cng: 17 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft Win32 Application Programming Interface, khi ?c dng v?i:
    • Microsoft Windows 98 Standard Edition
    • Microsoft Windows Millennium Edition
T? kha:
kbapi kbcode kbconsole kbhowto kbkernbase kbmt KB99261 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:99261

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com