fly_indiz
Silver Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору
Цитата: А еще - может кто знает как из скрипта сменить текущий шрифт консоли запущенного скрипта? | Ура, нашел! :-) Код: [string] $ConsoleHelperAPI = @' using System; using System.Runtime.InteropServices; public static class ConsoleHelper { [DllImport("kernel32.dll", SetLastError = true)] internal static extern IntPtr GetStdHandle(int nStdHandle); [return: MarshalAs(UnmanagedType.Bool)] [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] internal static extern bool SetCurrentConsoleFontEx(IntPtr hConsoleOutput, bool MaximumWindow, ref CONSOLE_FONT_INFOEX ConsoleCurrentFontEx); [return: MarshalAs(UnmanagedType.Bool)] [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] internal static extern bool GetCurrentConsoleFontEx(IntPtr hConsoleOutput, bool MaximumWindow, ref CONSOLE_FONT_INFOEX ConsoleCurrentFontEx); private const int StdHandle = -11; private static readonly IntPtr ConsoleOutputHandle = GetStdHandle(StdHandle); [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct CONSOLE_FONT_INFOEX { internal int cbSize; internal int nFont; public short FontWidth; public short FontHeight; public int FontFamily; public int FontWeight; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string FaceName; } public static CONSOLE_FONT_INFOEX[] GetConsoleFontInfo() { CONSOLE_FONT_INFOEX currentFontInfo = new CONSOLE_FONT_INFOEX { cbSize = Marshal.SizeOf<CONSOLE_FONT_INFOEX>() }; GetCurrentConsoleFontEx(ConsoleOutputHandle, false, ref currentFontInfo); return new[] { currentFontInfo }; } public static void SetConsoleFont(string faceName, short fontSize = 0) { CONSOLE_FONT_INFOEX currentFontInfo = new CONSOLE_FONT_INFOEX { cbSize = Marshal.SizeOf<CONSOLE_FONT_INFOEX>() }; if (GetCurrentConsoleFontEx(ConsoleOutputHandle, false, ref currentFontInfo)) { if (faceName == "Terminal") { CONSOLE_FONT_INFOEX setFontInfo = new CONSOLE_FONT_INFOEX { cbSize = Marshal.SizeOf<CONSOLE_FONT_INFOEX>(), nFont = 0, FontWidth = 8, FontHeight = 12, FontFamily = 48, FontWeight = 400, FaceName = faceName }; SetCurrentConsoleFontEx(ConsoleOutputHandle, false, ref setFontInfo); } else { CONSOLE_FONT_INFOEX setFontInfo = new CONSOLE_FONT_INFOEX { cbSize = Marshal.SizeOf<CONSOLE_FONT_INFOEX>(), nFont = 0, FontHeight = fontSize > 0 ? fontSize : currentFontInfo.FontHeight, FontFamily = 54, FontWeight = 400, FaceName = faceName }; SetCurrentConsoleFontEx(ConsoleOutputHandle, false, ref setFontInfo); } } } } '@ if ( -not ( 'ConsoleHelper' -as [type] )) { Add-Type $ConsoleHelperAPI -ErrorAction Stop } [ConsoleHelper]::SetConsoleFont( 'Consolas', 16 ) |
| Всего записей: 2620 | Зарегистр. 28-04-2006 | Отправлено: 13:11 17-09-2021 | Исправлено: fly_indiz, 13:40 19-09-2021 |
|