All pastes #9658 Raw Edit

yath

public cpp v1 · immutable
#9658 ·published 2005-04-16 11:26 UTC
rendered paste body
#include <windows.h>#include <stdio.h>#include <string>#include <iostream>using namespace std;typedef struct _CONSOLE_FONT_INFO {  DWORD index;  COORD size;} CONSOLE_FONT_INFO;typedef BOOL (WINAPI *GetConsoleFontInfoFunc)(HANDLE, BOOL, DWORD, CONSOLE_FONT_INFO*);typedef BOOL (WINAPI *GetCurrentConsoleFontFunc)(HANDLE, BOOL, CONSOLE_FONT_INFO*);typedef BOOL (WINAPI *SetConsoleFontFunc)(HANDLE, DWORD);GetConsoleFontInfoFunc pGetConsoleFontInfo;GetCurrentConsoleFontFunc pGetCurrentConsoleFont;SetConsoleFontFunc pSetConsoleFont; void printErr(string prefix) {	LPTSTR err;	if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,		NULL, GetLastError(), 0, (LPTSTR)&err, 0, NULL) == 0) {		cerr << "Fehler in FormatMessage(). GetLastError() == " << GetLastError() <<			endl;		return;	}	cerr << "Fehler: " << prefix << endl << err << flush;	LocalFree(err);}bool loadFuns() {	HINSTANCE krnldll = LoadLibrary("KERNEL32.DLL");	if (krnldll == NULL) {		printErr("Konnte KERNEL32.DLL nicht laden.");		return false;	}	pGetConsoleFontInfo = (GetConsoleFontInfoFunc)GetProcAddress(krnldll,							"GetConsoleFontInfo");	if (pGetConsoleFontInfo == NULL) {		printErr("Adresse von GetConsoleFontInfo() konnte nicht geholt werden.");		return false;	}	pGetCurrentConsoleFont = (GetCurrentConsoleFontFunc)GetProcAddress(krnldll,							"GetCurrentConsoleFont");	if (pGetCurrentConsoleFont == NULL) {		printErr("Adresse von GetCurrentConsoleFont() konnte nicht geholt werden.");		return false;	}	pSetConsoleFont = (SetConsoleFontFunc)GetProcAddress(krnldll,							"SetConsoleFont");	if (pSetConsoleFont == NULL) {		printErr("Adresse SetConsoleFont() konnte nicht geholt werden.");		return false;	}	 return true;}void printCurrentFont(HANDLE h) {	string infoString;	CONSOLE_FONT_INFO info;	BOOL ret;	ret = pGetCurrentConsoleFont(h, FALSE, &info);	if (ret == FALSE) {		printErr("Aktueller Konsolenfont konnte nicht ermittelt werden.");		return;	}	cout << info.size.X << "x" << info.size.Y << 		((info.index & 1) ? " Rasterschriftart" : " Truetype");}bool loadTTFont() {	HANDLE h;	CONSOLE_FONT_INFO info;	BOOL ret;	cout << "Wechsle Schriftart... " << flush;			h = GetStdHandle(STD_OUTPUT_HANDLE);	if (h == INVALID_HANDLE_VALUE) {		printErr("Standardausgabehandle konnte nicht geholt werden.");		return false;	}	printCurrentFont(h);	ret = pGetCurrentConsoleFont(h, FALSE, &info);	if (ret == FALSE) {		printErr("Aktueller Konsolenfont konnte nicht ermittelt werden.");		return false;	}		if (info.index % 2 == 0) {		cout << " - Unverändert" << endl;		return true;	}	ret = pSetConsoleFont(h, info.index+1);	if (ret == FALSE) {		printErr("Konnte Konsolenfont nicht setzen.");		return false;	}	cout << " -> ";	printCurrentFont(h);	cout << endl;	return true;}bool activateCodepage(UINT codepage) {	BOOL ret;	ret = SetConsoleCP(codepage);	if (ret == FALSE) {		printErr("Eingabecodepage konnte nicht gesetzt werden.");		return false;	}	ret = SetConsoleOutputCP(codepage);	if (ret == FALSE) {		printErr("Ausgabecodepage konnte nicht gesetzt werden.");		return false;	}	cout << "Codepage " << codepage << " aktiviert." << endl;	return true;}int main(void) {	if (!loadFuns() || !loadTTFont() || !activateCodepage(1252)) {		cout << "Umlaute funktionieren mglw. nicht richtig." << endl;	}		cout << "Möpse" << endl;	return 0;}