Beispiel #1
1
void Window::changeFont(int x, int y){
	CONSOLE_FONT_INFOEX fontInfo = { sizeof (CONSOLE_FONT_INFOEX) };
	bool value = GetCurrentConsoleFontEx(wHnd, 0, &fontInfo);
	fontInfo.dwFontSize.X = x;
	fontInfo.dwFontSize.Y = y;
	bool value2 = SetCurrentConsoleFontEx(wHnd, 0, &fontInfo);
}
Beispiel #2
0
// usar esta de preferência a não ser que se esteja no XP ou anterior
void Consola::setTextSize(int x, int y) {
	CONSOLE_FONT_INFOEX cfont;

	cfont.cbSize=sizeof(CONSOLE_FONT_INFOEX);

	GetCurrentConsoleFontEx(hconsola, false, & cfont);
	cfont.dwFontSize.X = x;
	cfont.dwFontSize.Y = y;
	SetCurrentConsoleFontEx(hconsola, false, &cfont);
}
Beispiel #3
0
JNIEXPORT void JNICALL Java_com_yifanlu_Josh_Josh_SETCURRENTCONSOLEFONTEX
  (JNIEnv *env, jclass jcls, jlong pointer, jboolean maximum, jint font, jint sizeX, jint sizeY)
{
    HANDLE hConsole = pointerToHandle(pointer);
	CONSOLE_FONT_INFOEX extendedInfo;
	GetCurrentConsoleFontEx(hConsole, (maximum ? TRUE : FALSE), &extendedInfo);
	
	extendedInfo.nFont = font;
	extendedInfo.dwFontSize.X = sizeX;
	extendedInfo.dwFontSize.Y = sizeY;

	SetCurrentConsoleFontEx(hConsole, (maximum ? TRUE : FALSE), &extendedInfo);
}
/**
* @brief (Only for Windows and for newer WINAPI) Sets the Console font size to the defined FontSize_X and FontSize_Y
* @param [in] FontSize defined font size informations
*/
void SetConsoleFont(SIZES FontSize) {
#if !defined(WINXP) && !defined(BASIGMINGW) /* Minimum supported client: Windows Vista */
    HANDLE outcon;
    CONSOLE_FONT_INFOEX font;

    outcon = GetStdHandle(STD_OUTPUT_HANDLE);      /* Getting windows console standard handler */
    font = {sizeof(CONSOLE_FONT_INFOEX)};          /* CONSOLE_FONT_INFOEX is defined in some windows header */
    GetCurrentConsoleFontEx(outcon, false, &font); /* Getting current font settings */
    font.FontFamily = 54;       /* Lucida console font */
    font.dwFontSize.X = FontSize.X;
    font.dwFontSize.Y = FontSize.Y;
    SetCurrentConsoleFontEx(outcon, false, &font); /* Setting font settings */
#endif /* WINXP, BASIGMINGW */
}
Beispiel #5
0
void setFontSize(int x, int y)
{
    HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_FONT_INFOEX conFont = {0};
    conFont.cbSize = sizeof(CONSOLE_FONT_INFOEX);
    BOOL i = GetCurrentConsoleFontEx(hConsole,0,&conFont);
    if(!i)
        return GetLastError();
    conFont.dwFontSize.Y = y;
    conFont.dwFontSize.X = x;
    conFont.FontWeight = 100;
    conFont.FontFamily = FF_ROMAN;
    i = SetCurrentConsoleFontEx(hConsole, 0, &conFont);
    if(!i)
        return GetLastError();
}
Beispiel #6
0
static void warn_if_raster_font(void)
{
	DWORD fontFamily = 0;
	DECLARE_PROC_ADDR(kernel32.dll, BOOL, GetCurrentConsoleFontEx,
			HANDLE, BOOL, PCONSOLE_FONT_INFOEX);

	/* don't bother if output was ascii only */
	if (!non_ascii_used)
		return;

	/* GetCurrentConsoleFontEx is available since Vista */
	if (INIT_PROC_ADDR(GetCurrentConsoleFontEx)) {
		CONSOLE_FONT_INFOEX cfi;
		cfi.cbSize = sizeof(cfi);
		if (GetCurrentConsoleFontEx(console, 0, &cfi))
			fontFamily = cfi.FontFamily;
	} else {
		/* pre-Vista: check default console font in registry */
		HKEY hkey;
		if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_CURRENT_USER, "Console",
				0, KEY_READ, &hkey)) {
			DWORD size = sizeof(fontFamily);
			RegQueryValueExA(hkey, "FontFamily", NULL, NULL,
					(LPVOID) &fontFamily, &size);
			RegCloseKey(hkey);
		}
	}

	if (!(fontFamily & TMPF_TRUETYPE)) {
		const wchar_t *msg = L"\nWarning: Your console font probably "
			L"doesn\'t support Unicode. If you experience strange "
			L"characters in the output, consider switching to a "
			L"TrueType font such as Consolas!\n";
		DWORD dummy;
		WriteConsoleW(console, msg, wcslen(msg), &dummy, NULL);
	}
}
Beispiel #7
0
Window::Window(int pwidth, int pheight)
{
	height = pheight;
	width = pwidth;

	// Setup the handles
	outHnd = GetStdHandle(STD_OUTPUT_HANDLE);
	inHnd = GetStdHandle(STD_INPUT_HANDLE);

	// Set console window size
	COORD bufferSize = {pwidth, pheight};
	SMALL_RECT windowSize = {0, 0, pwidth-1, pheight-1};
	
	// set the size of the CONSOLE_FONT_INFOEX
	CONSOLE_FONT_INFOEX font;
	font.cbSize = sizeof(CONSOLE_FONT_INFOEX);
	GetCurrentConsoleFontEx(outHnd, false, &font); // Get current size
 
	// set size to be 3x5; 5x8; 6x12; 8x16; 8x18; 10x20;
	font.dwFontSize.X = 8;
	font.dwFontSize.Y = 16;
	 
	// Set the info for hiding the flashing cursor
	CONSOLE_CURSOR_INFO cursor;
	cursor.bVisible = 0;
	cursor.dwSize = sizeof(CONSOLE_CURSOR_INFO); // Get current size
	
	// Submit the settings
	SetConsoleTitle(TEXT("Adventure CMD!"));
	SetConsoleWindowInfo(outHnd, TRUE, &windowSize);
	SetConsoleScreenBufferSize(outHnd, bufferSize);
	SetCurrentConsoleFontEx(outHnd, false, &font);
	SetConsoleCursorInfo(outHnd, &cursor);
	srand(time(0));

}
Beispiel #8
0
// ----------------------------------------------------------------------------
int main () {
  
  LPGetNumberOfConsoleFonts   GetNumberOfConsoleFonts;
  HMODULE                     hmod;
  HANDLE                      OutConsole;
  static CONSOLE_FONT_INFOEX  font;
  static CONSOLE_FONT_INFOEX  newfont;
  unsigned int                OldCode=0;
  // Permet, en mode debug, dans la fenêtre Variables and Call Stack de CVI, de vérifier qu'en hexa les 'é' sont bine codés 'xE9' ce qui en codepage 850 correspond à 'Ú'
  char                        str[] = "Bel été et je dépense mes €";

  // évite un warning à la compile
  str[0]=str[0];
  
  // ----------------------------------------------------------------------------
  // http://blogs.msdn.com/b/michkap/archive/2011/09/22/10215125.aspx
  OutConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  
  // ATTENTION : penser à bien initialiser lea taille de la structure
  font.cbSize = sizeof(CONSOLE_FONT_INFOEX);
  GetCurrentConsoleFontEx(OutConsole, 0, &font);
  
  if ((font.FontFamily & TMPF_TRUETYPE) == TMPF_TRUETYPE) {
    puts("La console utilise une police TrueType.");
  }else{
    puts("La console n'utilise pas une police TrueType.");
  }
  
  // GetNumberOfConsoleFonts() is a Win SDK undocumented function
  hmod = GetModuleHandleA("KERNEL32.DLL");
  GetNumberOfConsoleFonts = (LPGetNumberOfConsoleFonts)GetProcAddress(hmod, "GetNumberOfConsoleFonts");   
  if (!hmod || !GetNumberOfConsoleFonts){
    FreeLibrary(hmod);
    puts("Y a un problème!"); 
    puts("Strike ENTER to exit :");
    getchar();
  }else{
    printf("Il y a %d polices pour la console\n", GetNumberOfConsoleFonts());
  }
  
  // http://fr.wikipedia.org/wiki/Page_de_code_850
  OldCode = GetConsoleOutputCP();
  printf("Le code page courant est : %d\n", OldCode);
  
  puts("Strike ENTER to continue :");
  getchar();
  
  // ----------------------------------------------------------------------------
  // http://support.microsoft.com/kb/99795/en-us
  // Si on met une font TT type Consolas ou Lucida Console ça passe
  puts("****   Affichage simple : Bel été  et je dépense mes €");  
  
  puts("Strike ENTER to continue :");
  getchar();
  
  // ----------------------------------------------------------------------------
  // é = 130 en dec et 0x82 en hexa
  // il n'y a pas de code pour le caractère '€' 
  // http://fr.wikipedia.org/wiki/Page_de_code_850
  puts("****   Affichage avec des code hexa : Bel \x82t\x82.");
  puts("ATTENTION : pas de code hexa pour le caract\x8Are \"euro\""); 
  
  puts("Strike ENTER to continue :");
  getchar();
  
  // ----------------------------------------------------------------------------
  // http://fr.wikipedia.org/wiki/Windows-1252    
  puts("On tente de passer en code page 1252");
  // http://support.microsoft.com/kb/99795/en-us
  // SetConsoleOutputCP does not effect the displaying of extended characters of the console font named "Raster Font."
  SetConsoleOutputCP(1252); 
  printf("Le code page courant est : %d\n", GetConsoleOutputCP());   
  
  puts("");    
  puts("****   Affichage en 1252 : Bel été et je dépense mes €");
  puts("ATTENTION : les caractères accentués n'apparaissent correctement qu'avec une police TrueType");  
  
  puts("Strike ENTER to continue :");
  getchar();
  
  // ----------------------------------------------------------------------------
  // http://msdn.microsoft.com/en-us/library/system.console.aspx
  puts("On force la police en mode TrueType");
  
  newfont.cbSize = sizeof(CONSOLE_FONT_INFOEX);     
  newfont.FontFamily = TMPF_TRUETYPE; 
  mbstowcs(newfont.FaceName, "Lucida Console", 100);
  // Faut bien initialiser X et Y
  newfont.dwFontSize.Y = font.dwFontSize.Y;
  newfont.dwFontSize.X = font.dwFontSize.X;
  newfont.FontWeight = font.FontWeight;  
  SetCurrentConsoleFontEx(OutConsole, 0, &newfont);
  
  GetNumberOfConsoleFonts = (LPGetNumberOfConsoleFonts)GetProcAddress(hmod, "GetNumberOfConsoleFonts");  
  printf("Il y a dorénavant %d polices pour la console\n", GetNumberOfConsoleFonts());         
  
  puts("Strike ENTER to continue :");
  getchar();
  
  // ----------------------------------------------------------------------------
  puts("");
  puts("****   Affichage 1252 avec la police modifiée : Bel été et je dépense mes €");         
  puts("ATTENTION : si au départ la police n'était pas TrueType, l'affichage en 1252 qui n'était pas correct l'est dorénavant");
  puts("Pensez à jeter un oeil sur les différents type d'affichage précédents et à observer comment ils ont évolués.");
  puts("");
  
  // ----------------------------------------------------------------------------
  SetConsoleOutputCP(850);  
  puts("****   Affichage en 850 avec la police modifiée : Bel été et je dépense mes €");  
  
  // ----------------------------------------------------------------------------
  puts("");
  // Rouge
  SetConsoleTextAttribute(OutConsole, FOREGROUND_RED|FOREGROUND_INTENSITY);
  puts("Strike ENTER to exit :");
  getchar();
  
  // ----------------------------------------------------------------------------
  // Hide the console and set the default parameters back 
  //ShowWindow( GetConsoleWindow(), SW_HIDE);   
  SetConsoleTextAttribute(OutConsole, FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
  SetConsoleOutputCP(OldCode);    
  SetCurrentConsoleFontEx(OutConsole, 0, &font);         
  FreeLibrary(hmod);
  
}