win32 获取控制台句柄、cls

GetStdHandle(STD_OUTPUT_HANDLE);

#undef X
#undef Y

void cls(void)
{
	COORD coordScreen = { 0, 0 };	 /* here's where we'll home the
													cursor */
	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 */
 
	GetConsoleScreenBufferInfo( hOut, &csbi );
	dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
 
	/* fill the entire screen with blanks */
 
	FillConsoleOutputCharacter( hOut, (TCHAR)' ',
		dwConSize, coordScreen, &cCharsWritten);
 
	/* get the current text attribute */
 
	GetConsoleScreenBufferInfo( hOut, &csbi );
 
	/* now set the buffer's attributes accordingly */
 
	FillConsoleOutputAttribute( hOut, csbi.wAttributes,
		dwConSize, coordScreen, &cCharsWritten );
 
	/* put the cursor at (0, 0) */
 
	SetConsoleCursorPosition( hOut, coordScreen );
}

  

原文地址:https://www.cnblogs.com/ageane/p/hOut.html