@@ -21,6 +21,11 @@ public static class NativeMethods
21
21
public const uint ENABLE_PROCESSED_INPUT = 0x0001 ;
22
22
public const uint ENABLE_LINE_INPUT = 0x0002 ;
23
23
24
+ public const int FontTypeMask = 0x06 ;
25
+ public const int TrueTypeFont = 0x04 ;
26
+
27
+ internal static readonly IntPtr INVALID_HANDLE_VALUE = new IntPtr ( - 1 ) ; // WinBase.h
28
+
24
29
[ DllImport ( "kernel32.dll" , CharSet = CharSet . Unicode , SetLastError = true ) ]
25
30
public static extern IntPtr GetStdHandle ( uint handleId ) ;
26
31
@@ -58,6 +63,42 @@ public static extern int ToUnicode(uint uVirtKey, uint uScanCode, byte[] lpKeySt
58
63
59
64
[ DllImport ( "user32.dll" , CharSet = CharSet . Unicode , SetLastError = true ) ]
60
65
public static extern short VkKeyScan ( char @char ) ;
66
+
67
+ [ DllImport ( "kernel32.dll" , SetLastError = false , CharSet = CharSet . Unicode ) ]
68
+ public static extern uint GetConsoleOutputCP ( ) ;
69
+
70
+ [ DllImport ( "User32.dll" , SetLastError = false , CharSet = CharSet . Unicode ) ]
71
+ public static extern int ReleaseDC ( IntPtr hwnd , IntPtr hdc ) ;
72
+
73
+ [ DllImport ( "kernel32.dll" , SetLastError = true , CharSet = CharSet . Unicode ) ]
74
+ public static extern IntPtr GetConsoleWindow ( ) ;
75
+
76
+ [ DllImport ( "User32.dll" , SetLastError = true , CharSet = CharSet . Unicode ) ]
77
+ public static extern IntPtr GetDC ( IntPtr hwnd ) ;
78
+
79
+ [ DllImport ( "GDI32.dll" , SetLastError = true , CharSet = CharSet . Unicode ) ]
80
+ public static extern bool TranslateCharsetInfo ( IntPtr src , out CHARSETINFO Cs , uint options ) ;
81
+
82
+ [ DllImport ( "GDI32.dll" , SetLastError = true , CharSet = CharSet . Unicode ) ]
83
+ public static extern bool GetTextMetrics ( IntPtr hdc , out TEXTMETRIC tm ) ;
84
+
85
+ [ DllImport ( "GDI32.dll" , SetLastError = true , CharSet = CharSet . Unicode ) ]
86
+ public static extern bool GetCharWidth32 ( IntPtr hdc , uint first , uint last , out int width ) ;
87
+
88
+ [ DllImport ( "kernel32.dll" , SetLastError = true , CharSet = CharSet . Unicode ) ]
89
+ public static extern IntPtr CreateFile
90
+ (
91
+ string fileName ,
92
+ uint desiredAccess ,
93
+ uint ShareModes ,
94
+ IntPtr securityAttributes ,
95
+ uint creationDisposition ,
96
+ uint flagsAndAttributes ,
97
+ IntPtr templateFileWin32Handle
98
+ ) ;
99
+
100
+ [ DllImport ( "kernel32.dll" , SetLastError = true , CharSet = CharSet . Unicode ) ]
101
+ internal static extern bool GetCurrentConsoleFontEx ( IntPtr consoleOutput , bool bMaximumWindow , ref CONSOLE_FONT_INFO_EX consoleFontInfo ) ;
61
102
}
62
103
63
104
public delegate bool BreakHandler ( ConsoleBreakSignal ConsoleBreakSignal ) ;
@@ -72,13 +113,45 @@ public enum ConsoleBreakSignal : uint
72
113
None = 255 ,
73
114
}
74
115
116
+ public enum CHAR_INFO_Attributes : ushort
117
+ {
118
+ COMMON_LVB_LEADING_BYTE = 0x0100 ,
119
+ COMMON_LVB_TRAILING_BYTE = 0x0200
120
+ }
121
+
75
122
public enum StandardHandleId : uint
76
123
{
77
124
Error = unchecked ( ( uint ) - 12 ) ,
78
125
Output = unchecked ( ( uint ) - 11 ) ,
79
126
Input = unchecked ( ( uint ) - 10 ) ,
80
127
}
81
128
129
+ [ Flags ]
130
+ public enum AccessQualifiers : uint
131
+ {
132
+ // From winnt.h
133
+ GenericRead = 0x80000000 ,
134
+ GenericWrite = 0x40000000
135
+ }
136
+
137
+ public enum CreationDisposition : uint
138
+ {
139
+ // From winbase.h
140
+ CreateNew = 1 ,
141
+ CreateAlways = 2 ,
142
+ OpenExisting = 3 ,
143
+ OpenAlways = 4 ,
144
+ TruncateExisting = 5
145
+ }
146
+
147
+ [ Flags ]
148
+ public enum ShareModes : uint
149
+ {
150
+ // From winnt.h
151
+ ShareRead = 0x00000001 ,
152
+ ShareWrite = 0x00000002
153
+ }
154
+
82
155
public struct SMALL_RECT
83
156
{
84
157
public short Left ;
@@ -119,6 +192,69 @@ public override string ToString()
119
192
}
120
193
}
121
194
195
+ [ StructLayout ( LayoutKind . Sequential ) ]
196
+ public struct FONTSIGNATURE
197
+ {
198
+ //From public\sdk\inc\wingdi.h
199
+
200
+ // fsUsb*: A 128-bit Unicode subset bitfield (USB) identifying up to 126 Unicode subranges
201
+ internal uint fsUsb0 ;
202
+ internal uint fsUsb1 ;
203
+ internal uint fsUsb2 ;
204
+ internal uint fsUsb3 ;
205
+ // fsCsb*: A 64-bit, code-page bitfield (CPB) that identifies a specific character set or code page.
206
+ internal uint fsCsb0 ;
207
+ internal uint fsCsb1 ;
208
+ }
209
+
210
+ [ StructLayout ( LayoutKind . Sequential ) ]
211
+ public struct CHARSETINFO
212
+ {
213
+ //From public\sdk\inc\wingdi.h
214
+ internal uint ciCharset ; // Character set value.
215
+ internal uint ciACP ; // ANSI code-page identifier.
216
+ internal FONTSIGNATURE fs ;
217
+ }
218
+
219
+ [ StructLayout ( LayoutKind . Sequential , CharSet = CharSet . Unicode ) ]
220
+ public struct TEXTMETRIC
221
+ {
222
+ //From public\sdk\inc\wingdi.h
223
+ public int tmHeight ;
224
+ public int tmAscent ;
225
+ public int tmDescent ;
226
+ public int tmInternalLeading ;
227
+ public int tmExternalLeading ;
228
+ public int tmAveCharWidth ;
229
+ public int tmMaxCharWidth ;
230
+ public int tmWeight ;
231
+ public int tmOverhang ;
232
+ public int tmDigitizedAspectX ;
233
+ public int tmDigitizedAspectY ;
234
+ public char tmFirstChar ;
235
+ public char tmLastChar ;
236
+ public char tmDefaultChar ;
237
+ public char tmBreakChar ;
238
+ public byte tmItalic ;
239
+ public byte tmUnderlined ;
240
+ public byte tmStruckOut ;
241
+ public byte tmPitchAndFamily ;
242
+ public byte tmCharSet ;
243
+ }
244
+
245
+ [ StructLayout ( LayoutKind . Sequential , CharSet = CharSet . Unicode ) ]
246
+ public struct CONSOLE_FONT_INFO_EX
247
+ {
248
+ internal int cbSize ;
249
+ internal int nFont ;
250
+ internal short FontWidth ;
251
+ internal short FontHeight ;
252
+ internal int FontFamily ;
253
+ internal int FontWeight ;
254
+ [ MarshalAs ( UnmanagedType . ByValTStr , SizeConst = 32 ) ]
255
+ internal string FontFace ;
256
+ }
257
+
122
258
public struct CHAR_INFO
123
259
{
124
260
public ushort UnicodeChar ;
0 commit comments