1 #Region "Microsoft.VisualBasic::67fedef44703b1edc201af2fb50c49f7, Microsoft.VisualBasic.Core\ApplicationServices\Terminal\xConsole\Helpers.vb"
2
3     ' Author:
4     
5     '       asuka (amethyst.asuka@gcmodeller.org)
6     '       xie (genetics@smrucc.org)
7     '       xieguigang (xie.guigang@live.com)
8     
9     ' Copyright (c) 2018 GPL3 Licensed
10     
11     
12     ' GNU GENERAL PUBLIC LICENSE (GPL3)
13     
14     
15     ' This program is free software: you can redistribute it and/or modify
16     ' it under the terms of the GNU General Public License as published by
17     ' the Free Software Foundation, either version 3 of the License, or
18     ' (at your option) any later version.
19     
20     ' This program is distributed in the hope that it will be useful,
21     ' but WITHOUT ANY WARRANTY; without even the implied warranty of
22     ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23     ' GNU General Public License for more details.
24     
25     ' You should have received a copy of the GNU General Public License
26     ' along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28
29
30     ' /********************************************************************************/
31
32     ' Summaries:
33
34     '     Module Helpers
35     
36     '         FunctionSetConsoleFont, (+2 OverloadsSetConsoleIcon
37     '         Enum StdHandle
38     
39     
40     
41     
42     '         Structure ConsoleFont
43     
44     '             Properties: ConsoleFonts, ConsoleFontsCount
45     
46     '             FunctionGetConsoleFontInfo, GetNumberOfConsoleFonts, GetStdHandle, SetConsoleFont
47     
48     '  
49     
50     
51     
52     
53     ' /********************************************************************************/
54
55 #End Region
56
57 Imports System.Drawing
58 Imports System.Runtime.InteropServices
59
60 Namespace Terminal
61
62     ''' <summary>
63     ''' Console helper. http://blogs.microsoft.co.il/blogs/pavely/archive/2009/07/23/changing-console-fonts.aspx
64     ''' </summary>
65     Public Module Helpers
66
67         <DllImport("kernel32")>
68         Public Function SetConsoleIcon(hIcon As IntPtr) As Boolean
69         End Function
70
71         Public Function SetConsoleIcon(icon As Icon) As Boolean
72             Return SetConsoleIcon(icon.Handle)
73         End Function
74
75         <DllImport("kernel32")>
76         Public Function SetConsoleFont(hOutput As IntPtr, index As UIntegerAs Boolean
77         End Function
78
79         Private Enum StdHandle
80             OutputHandle = -11
81         End Enum
82
83         <DllImport("kernel32")>
84         Private Function GetStdHandle(index As StdHandle) As IntPtr
85         End Function
86
87         Public Function SetConsoleFont(index As UIntegerAs Boolean
88             Return SetConsoleFont(GetStdHandle(StdHandle.OutputHandle), index)
89         End Function
90
91         <DllImport("kernel32")>
92         Private Function GetConsoleFontInfo(hOutput As IntPtr,
93                                             <MarshalAs(UnmanagedType.Bool)> bMaximize As Boolean,
94                                             count As UInteger,
95                                             <MarshalAs(UnmanagedType.LPArray), Out> fonts As ConsoleFont()) As Boolean
96         End Function
97
98         <DllImport("kernel32")>
99         Private Function GetNumberOfConsoleFonts() As UInteger
100         End Function
101
102         Public ReadOnly Property ConsoleFontsCount() As UInteger
103             Get
104                 Return GetNumberOfConsoleFonts()
105             End Get
106         End Property
107
108         Public ReadOnly Property ConsoleFonts() As ConsoleFont()
109             Get
110                 Dim fonts As ConsoleFont() = New ConsoleFont(GetNumberOfConsoleFonts() - 1) {}
111                 If fonts.Length > 0 Then
112                     GetConsoleFontInfo(GetStdHandle(StdHandle.OutputHandle), FalseCUInt(fonts.Length), fonts)
113                 End If
114                 Return fonts
115             End Get
116         End Property
117
118 #Region "HELPER"
119
120         ''' <summary>
121         ''' http://blogs.microsoft.co.il/blogs/pavely/archive/2009/07/23/changing-console-fonts.aspx
122         ''' </summary>
123         <StructLayout(LayoutKind.Sequential, Pack:=1)>
124         Public Structure ConsoleFont
125             Public Index As UInteger
126             Public SizeX As Short, SizeY As Short
127         End Structure
128
129 #End Region
130
131     End Module
132 End Namespace