winapi\um/
wincon.rs

1// Licensed under the Apache License, Version 2.0
2// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
4// All files in the project carrying such notice may not be copied, modified, or distributed
5// except according to those terms.
6//! This module contains the public data structures, data types, and procedures exported by the NT
7//! console subsystem.
8use ctypes::c_void;
9use shared::minwindef::{BOOL, DWORD, LPDWORD, LPVOID, LPWORD, UINT, ULONG, WORD};
10use shared::windef::{COLORREF, HWND};
11use um::minwinbase::SECURITY_ATTRIBUTES;
12use um::wingdi::LF_FACESIZE;
13use um::winnt::{CHAR, HANDLE, LPCSTR, LPCWSTR, LPSTR, LPWSTR, WCHAR};
14// Many definitions in wincontypes used to be defined in this file, so reexport them to avoid
15// breakage. For clarity they are imported in the order they are defined in that file rather
16// than winapi's usual alphabetical ordering, with some newlines and indentation to match their
17// grouping in the file.
18pub use um::wincontypes::{
19    COORD, PCOORD,
20    SMALL_RECT, PSMALL_RECT,
21    KEY_EVENT_RECORD_uChar, KEY_EVENT_RECORD, PKEY_EVENT_RECORD,
22    RIGHT_ALT_PRESSED, LEFT_ALT_PRESSED, RIGHT_CTRL_PRESSED, LEFT_CTRL_PRESSED, SHIFT_PRESSED,
23        NUMLOCK_ON, SCROLLLOCK_ON, CAPSLOCK_ON, ENHANCED_KEY, NLS_DBCSCHAR, NLS_ALPHANUMERIC,
24        NLS_KATAKANA, NLS_HIRAGANA, NLS_ROMAN, NLS_IME_CONVERSION, NLS_IME_DISABLE,
25    MOUSE_EVENT_RECORD, PMOUSE_EVENT_RECORD,
26    FROM_LEFT_1ST_BUTTON_PRESSED, RIGHTMOST_BUTTON_PRESSED, FROM_LEFT_2ND_BUTTON_PRESSED,
27        FROM_LEFT_3RD_BUTTON_PRESSED, FROM_LEFT_4TH_BUTTON_PRESSED, MOUSE_MOVED, DOUBLE_CLICK,
28        MOUSE_WHEELED, MOUSE_HWHEELED,
29    WINDOW_BUFFER_SIZE_RECORD, PWINDOW_BUFFER_SIZE_RECORD,
30    MENU_EVENT_RECORD, PMENU_EVENT_RECORD,
31    FOCUS_EVENT_RECORD, PFOCUS_EVENT_RECORD,
32    INPUT_RECORD_Event, INPUT_RECORD, PINPUT_RECORD,
33    KEY_EVENT, MOUSE_EVENT, WINDOW_BUFFER_SIZE_EVENT, MENU_EVENT, FOCUS_EVENT,
34    CHAR_INFO_Char, CHAR_INFO, PCHAR_INFO,
35    CONSOLE_FONT_INFO, PCONSOLE_FONT_INFO
36};
37pub const FOREGROUND_BLUE: WORD = 0x0001;
38pub const FOREGROUND_GREEN: WORD = 0x0002;
39pub const FOREGROUND_RED: WORD = 0x0004;
40pub const FOREGROUND_INTENSITY: WORD = 0x0008;
41pub const BACKGROUND_BLUE: WORD = 0x0010;
42pub const BACKGROUND_GREEN: WORD = 0x0020;
43pub const BACKGROUND_RED: WORD = 0x0040;
44pub const BACKGROUND_INTENSITY: WORD = 0x0080;
45pub const COMMON_LVB_LEADING_BYTE: WORD = 0x0100;
46pub const COMMON_LVB_TRAILING_BYTE: WORD = 0x0200;
47pub const COMMON_LVB_GRID_HORIZONTAL: WORD = 0x0400;
48pub const COMMON_LVB_GRID_LVERTICAL: WORD = 0x0800;
49pub const COMMON_LVB_GRID_RVERTICAL: WORD = 0x1000;
50pub const COMMON_LVB_REVERSE_VIDEO: WORD = 0x4000;
51pub const COMMON_LVB_UNDERSCORE: WORD = 0x8000;
52pub const COMMON_LVB_SBCSDBCS: WORD = 0x0300;
53STRUCT!{struct CONSOLE_SCREEN_BUFFER_INFO {
54    dwSize: COORD,
55    dwCursorPosition: COORD,
56    wAttributes: WORD,
57    srWindow: SMALL_RECT,
58    dwMaximumWindowSize: COORD,
59}}
60pub type PCONSOLE_SCREEN_BUFFER_INFO = *mut CONSOLE_SCREEN_BUFFER_INFO;
61STRUCT!{struct CONSOLE_SCREEN_BUFFER_INFOEX {
62    cbSize: ULONG,
63    dwSize: COORD,
64    dwCursorPosition: COORD,
65    wAttributes: WORD,
66    srWindow: SMALL_RECT,
67    dwMaximumWindowSize: COORD,
68    wPopupAttributes: WORD,
69    bFullscreenSupported: BOOL,
70    ColorTable: [COLORREF; 16],
71}}
72pub type PCONSOLE_SCREEN_BUFFER_INFOEX = *mut CONSOLE_SCREEN_BUFFER_INFOEX;
73STRUCT!{struct CONSOLE_CURSOR_INFO {
74    dwSize: DWORD,
75    bVisible: BOOL,
76}}
77pub type PCONSOLE_CURSOR_INFO = *mut CONSOLE_CURSOR_INFO;
78STRUCT!{struct CONSOLE_FONT_INFOEX {
79    cbSize: ULONG,
80    nFont: DWORD,
81    dwFontSize: COORD,
82    FontFamily: UINT,
83    FontWeight: UINT,
84    FaceName: [WCHAR; LF_FACESIZE],
85}}
86pub type PCONSOLE_FONT_INFOEX = *mut CONSOLE_FONT_INFOEX;
87pub const HISTORY_NO_DUP_FLAG: DWORD = 0x1;
88STRUCT!{struct CONSOLE_HISTORY_INFO {
89    cbSize: UINT,
90    HistoryBufferSize: UINT,
91    NumberOfHistoryBuffers: UINT,
92    dwFlags: DWORD,
93}}
94pub type PCONSOLE_HISTORY_INFO = *mut CONSOLE_HISTORY_INFO;
95STRUCT!{struct CONSOLE_SELECTION_INFO {
96    dwFlags: DWORD,
97    dwSelectionAnchor: COORD,
98    srSelection: SMALL_RECT,
99}}
100pub type PCONSOLE_SELECTION_INFO = *mut CONSOLE_SELECTION_INFO;
101pub const CONSOLE_NO_SELECTION: DWORD = 0x0000;
102pub const CONSOLE_SELECTION_IN_PROGRESS: DWORD = 0x0001;
103pub const CONSOLE_SELECTION_NOT_EMPTY: DWORD = 0x0002;
104pub const CONSOLE_MOUSE_SELECTION: DWORD = 0x0004;
105pub const CONSOLE_MOUSE_DOWN: DWORD = 0x0008;
106FN!{stdcall PHANDLER_ROUTINE(
107    CtrlType: DWORD,
108) -> BOOL}
109pub const CTRL_C_EVENT: DWORD = 0;
110pub const CTRL_BREAK_EVENT: DWORD = 1;
111pub const CTRL_CLOSE_EVENT: DWORD = 2;
112pub const CTRL_LOGOFF_EVENT: DWORD = 5;
113pub const CTRL_SHUTDOWN_EVENT: DWORD = 6;
114pub const ENABLE_PROCESSED_INPUT: DWORD = 0x0001;
115pub const ENABLE_LINE_INPUT: DWORD = 0x0002;
116pub const ENABLE_ECHO_INPUT: DWORD = 0x0004;
117pub const ENABLE_WINDOW_INPUT: DWORD = 0x0008;
118pub const ENABLE_MOUSE_INPUT: DWORD = 0x0010;
119pub const ENABLE_INSERT_MODE: DWORD = 0x0020;
120pub const ENABLE_QUICK_EDIT_MODE: DWORD = 0x0040;
121pub const ENABLE_EXTENDED_FLAGS: DWORD = 0x0080;
122pub const ENABLE_AUTO_POSITION: DWORD = 0x0100;
123pub const ENABLE_VIRTUAL_TERMINAL_INPUT: DWORD = 0x0200;
124pub const ENABLE_PROCESSED_OUTPUT: DWORD = 0x0001;
125pub const ENABLE_WRAP_AT_EOL_OUTPUT: DWORD = 0x0002;
126pub const ENABLE_VIRTUAL_TERMINAL_PROCESSING: DWORD = 0x0004;
127pub const DISABLE_NEWLINE_AUTO_RETURN: DWORD = 0x0008;
128pub const ENABLE_LVB_GRID_WORLDWIDE: DWORD = 0x0010;
129extern "system" {
130    pub fn PeekConsoleInputW(
131        hConsoleInput: HANDLE,
132        lpBuffer: PINPUT_RECORD,
133        nLength: DWORD,
134        lpNumberOfEventsRead: LPDWORD,
135    ) -> BOOL;
136    pub fn WriteConsoleInputA(
137        hConsoleInput: HANDLE,
138        lpBuffer: *const INPUT_RECORD,
139        nLength: DWORD,
140        lpNumberOfEventsWritten: LPDWORD,
141    ) -> BOOL;
142    pub fn WriteConsoleInputW(
143        hConsoleInput: HANDLE,
144        lpBuffer: *const INPUT_RECORD,
145        nLength: DWORD,
146        lpNumberOfEventsWritten: LPDWORD,
147    ) -> BOOL;
148    pub fn ReadConsoleOutputA(
149        hConsoleOutput: HANDLE,
150        lpBuffer: PCHAR_INFO,
151        dwBufferSize: COORD,
152        dwBufferCoord: COORD,
153        lpReadRegion: PSMALL_RECT,
154    ) -> BOOL;
155    pub fn ReadConsoleOutputW(
156        hConsoleOutput: HANDLE,
157        lpBuffer: PCHAR_INFO,
158        dwBufferSize: COORD,
159        dwBufferCoord: COORD,
160        lpReadRegion: PSMALL_RECT,
161    ) -> BOOL;
162    pub fn WriteConsoleOutputA(
163        hConsoleOutput: HANDLE,
164        lpBuffer: *const CHAR_INFO,
165        dwBufferSize: COORD,
166        dwBufferCoord: COORD,
167        lpWriteRegion: PSMALL_RECT,
168    ) -> BOOL;
169    pub fn WriteConsoleOutputW(
170        hConsoleOutput: HANDLE,
171        lpBuffer: *const CHAR_INFO,
172        dwBufferSize: COORD,
173        dwBufferCoord: COORD,
174        lpWriteRegion: PSMALL_RECT,
175    ) -> BOOL;
176    pub fn ReadConsoleOutputCharacterA(
177        hConsoleOutput: HANDLE,
178        lpCharacter: LPSTR,
179        nLength: DWORD,
180        dwReadCoord: COORD,
181        lpNumberOfCharsRead: LPDWORD,
182    ) -> BOOL;
183    pub fn ReadConsoleOutputCharacterW(
184        hConsoleOutput: HANDLE,
185        lpCharacter: LPWSTR,
186        nLength: DWORD,
187        dwReadCoord: COORD,
188        lpNumberOfCharsRead: LPDWORD,
189    ) -> BOOL;
190    pub fn ReadConsoleOutputAttribute(
191        hConsoleOutput: HANDLE,
192        lpAttribute: LPWORD,
193        nLength: DWORD,
194        dwReadCoord: COORD,
195        lpNumberOfAttrsRead: LPDWORD,
196    ) -> BOOL;
197    pub fn WriteConsoleOutputCharacterA(
198        hConsoleOutput: HANDLE,
199        lpCharacter: LPCSTR,
200        nLength: DWORD,
201        dwWriteCoord: COORD,
202        lpNumberOfCharsWritten: LPDWORD,
203    ) -> BOOL;
204    pub fn WriteConsoleOutputCharacterW(
205        hConsoleOutput: HANDLE,
206        lpCharacter: LPCWSTR,
207        nLength: DWORD,
208        dwWriteCoord: COORD,
209        lpNumberOfCharsWritten: LPDWORD,
210    ) -> BOOL;
211    pub fn WriteConsoleOutputAttribute(
212        hConsoleOutput: HANDLE,
213        lpAttribute: *const WORD,
214        nLength: DWORD,
215        dwWriteCoord: COORD,
216        lpNumberOfAttrsWritten: LPDWORD,
217    ) -> BOOL;
218    pub fn FillConsoleOutputCharacterA(
219        hConsoleOutput: HANDLE,
220        cCharacter: CHAR,
221        nLength: DWORD,
222        dwWriteCoord: COORD,
223        lpNumberOfCharsWritten: LPDWORD,
224    ) -> BOOL;
225    pub fn FillConsoleOutputCharacterW(
226        hConsoleOutput: HANDLE,
227        cCharacter: WCHAR,
228        nLength: DWORD,
229        dwWriteCoord: COORD,
230        lpNumberOfCharsWritten: LPDWORD,
231    ) -> BOOL;
232    pub fn FillConsoleOutputAttribute(
233        hConsoleOutput: HANDLE,
234        wAttribute: WORD,
235        nLength: DWORD,
236        dwWriteCoord: COORD,
237        lpNumberOfAttrsWritten: LPDWORD,
238    ) -> BOOL;
239}
240pub const CONSOLE_REAL_OUTPUT_HANDLE: *mut c_void = -2isize as *mut c_void;
241pub const CONSOLE_REAL_INPUT_HANDLE: *mut c_void = -3isize as *mut c_void;
242extern "system" {
243    pub fn GetConsoleScreenBufferInfo(
244        hConsoleOutput: HANDLE,
245        lpConsoleScreenBufferInfo: PCONSOLE_SCREEN_BUFFER_INFO,
246    ) -> BOOL;
247    pub fn GetConsoleScreenBufferInfoEx(
248        hConsoleOutput: HANDLE,
249        lpConsoleScreenBufferInfoEx: PCONSOLE_SCREEN_BUFFER_INFOEX,
250    ) -> BOOL;
251    pub fn SetConsoleScreenBufferInfoEx(
252        hConsoleOutput: HANDLE,
253        lpConsoleScreenBufferInfoEx: PCONSOLE_SCREEN_BUFFER_INFOEX,
254    ) -> BOOL;
255    pub fn GetLargestConsoleWindowSize(
256        hConsoleOutput: HANDLE,
257    ) -> COORD;
258    pub fn GetConsoleCursorInfo(
259        hConsoleOutput: HANDLE,
260        lpConsoleCursorInfo: PCONSOLE_CURSOR_INFO,
261    ) -> BOOL;
262    pub fn GetCurrentConsoleFont(
263        hConsoleOutput: HANDLE,
264        bMaximumWindow: BOOL,
265        lpConsoleCurrentFont: PCONSOLE_FONT_INFO,
266    ) -> BOOL;
267    pub fn GetCurrentConsoleFontEx(
268        hConsoleOutput: HANDLE,
269        bMaximumWindow: BOOL,
270        lpConsoleCurrentFontEx: PCONSOLE_FONT_INFOEX,
271    ) -> BOOL;
272    pub fn SetCurrentConsoleFontEx(
273        hConsoleOutput: HANDLE,
274        bMaximumWindow: BOOL,
275        lpConsoleCurrentFontEx: PCONSOLE_FONT_INFOEX,
276    ) -> BOOL;
277    pub fn GetConsoleHistoryInfo(
278        lpConsoleHistoryInfo: PCONSOLE_HISTORY_INFO,
279    ) -> BOOL;
280    pub fn SetConsoleHistoryInfo(
281        lpConsoleHistoryInfo: PCONSOLE_HISTORY_INFO,
282    ) -> BOOL;
283    pub fn GetConsoleFontSize(
284        hConsoleOutput: HANDLE,
285        nFont: DWORD,
286    ) -> COORD;
287    pub fn GetConsoleSelectionInfo(
288        lpConsoleSelectionInfo: PCONSOLE_SELECTION_INFO,
289    ) -> BOOL;
290    pub fn GetNumberOfConsoleMouseButtons(
291        lpNumberOfMouseButtons: LPDWORD,
292    ) -> BOOL;
293    pub fn SetConsoleActiveScreenBuffer(
294        hConsoleOutput: HANDLE,
295    ) -> BOOL;
296    pub fn FlushConsoleInputBuffer(
297        hConsoleInput: HANDLE,
298    ) -> BOOL;
299    pub fn SetConsoleScreenBufferSize(
300        hConsoleOutput: HANDLE,
301        dwSize: COORD,
302    ) -> BOOL;
303    pub fn SetConsoleCursorPosition(
304        hConsoleOutput: HANDLE,
305        dwCursorPosition: COORD,
306    ) -> BOOL;
307    pub fn SetConsoleCursorInfo(
308        hConsoleOutput: HANDLE,
309        lpConsoleCursorInfo: *const CONSOLE_CURSOR_INFO,
310    ) -> BOOL;
311    pub fn ScrollConsoleScreenBufferA(
312        hConsoleOutput: HANDLE,
313        lpScrollRectangle: *const SMALL_RECT,
314        lpClipRectangle: *const SMALL_RECT,
315        dwDestinationOrigin: COORD,
316        lpFill: *const CHAR_INFO,
317    ) -> BOOL;
318    pub fn ScrollConsoleScreenBufferW(
319        hConsoleOutput: HANDLE,
320        lpScrollRectangle: *const SMALL_RECT,
321        lpClipRectangle: *const SMALL_RECT,
322        dwDestinationOrigin: COORD,
323        lpFill: *const CHAR_INFO,
324    ) -> BOOL;
325    pub fn SetConsoleWindowInfo(
326        hConsoleOutput: HANDLE,
327        bAbsolute: BOOL,
328        lpConsoleWindow: *const SMALL_RECT,
329    ) -> BOOL;
330    pub fn SetConsoleTextAttribute(
331        hConsoleOutput: HANDLE,
332        wAttributes: WORD,
333    ) -> BOOL;
334    pub fn GenerateConsoleCtrlEvent(
335        dwCtrlEvent: DWORD,
336        dwProcessGroupId: DWORD,
337    ) -> BOOL;
338    pub fn FreeConsole() -> BOOL;
339    pub fn AttachConsole(
340        dwProcessId: DWORD,
341    ) -> BOOL;
342}
343pub const ATTACH_PARENT_PROCESS: DWORD = 0xFFFFFFFF;
344extern "system" {
345    pub fn GetConsoleTitleA(
346        lpConsoleTitle: LPSTR,
347        nSize: DWORD,
348    ) -> DWORD;
349    pub fn GetConsoleTitleW(
350        lpConsoleTitle: LPWSTR,
351        nSize: DWORD,
352    ) -> DWORD;
353    pub fn GetConsoleOriginalTitleA(
354        lpConsoleTitle: LPSTR,
355        nSize: DWORD,
356    ) -> DWORD;
357    pub fn GetConsoleOriginalTitleW(
358        lpConsoleTitle: LPWSTR,
359        nSize: DWORD,
360    ) -> DWORD;
361    pub fn SetConsoleTitleA(
362        lpConsoleTitle: LPCSTR,
363    ) -> BOOL;
364    pub fn SetConsoleTitleW(
365        lpConsoleTitle: LPCWSTR,
366    ) -> BOOL;
367}
368STRUCT!{struct CONSOLE_READCONSOLE_CONTROL {
369    nLength: ULONG,
370    nInitialChars: ULONG,
371    dwCtrlWakeupMask: ULONG,
372    dwControlKeyState: ULONG,
373}}
374pub type PCONSOLE_READCONSOLE_CONTROL = *mut CONSOLE_READCONSOLE_CONTROL;
375pub const CONSOLE_TEXTMODE_BUFFER: DWORD = 1;
376extern "system" {
377    pub fn CreateConsoleScreenBuffer(
378        dwDesiredAccess: DWORD,
379        dwShareMode: DWORD,
380        lpSecurityAttributes: *const SECURITY_ATTRIBUTES,
381        dwFlags: DWORD,
382        lpScreenBufferData: LPVOID,
383    ) -> HANDLE;
384    pub fn SetConsoleCP(
385        wCodePageID: UINT,
386    ) -> BOOL;
387    pub fn SetConsoleOutputCP(
388        wCodePageID: UINT,
389    ) -> BOOL;
390}
391pub const CONSOLE_FULLSCREEN: DWORD = 1;
392pub const CONSOLE_FULLSCREEN_HARDWARE: DWORD = 2;
393extern "system" {
394    pub fn GetConsoleDisplayMode(
395        lpModeFlags: LPDWORD,
396    ) -> BOOL;
397}
398pub const CONSOLE_FULLSCREEN_MODE: DWORD = 1;
399pub const CONSOLE_WINDOWED_MODE: DWORD = 2;
400extern "system" {
401    pub fn SetConsoleDisplayMode(
402        hConsoleOutput: HANDLE,
403        dwFlags: DWORD,
404        lpNewScreenBufferDimensions: PCOORD,
405    ) -> BOOL;
406    pub fn GetConsoleWindow() -> HWND;
407    pub fn GetConsoleProcessList(
408        lpdwProcessList: LPDWORD,
409        dwProcessCount: DWORD,
410    ) -> DWORD;
411    pub fn AddConsoleAliasA(
412        Source: LPSTR,
413        Target: LPSTR,
414        ExeName: LPSTR,
415    ) -> BOOL;
416    pub fn AddConsoleAliasW(
417        Source: LPWSTR,
418        Target: LPWSTR,
419        ExeName: LPWSTR,
420    ) -> BOOL;
421    pub fn GetConsoleAliasA(
422        Source: LPSTR,
423        TargetBuffer: LPSTR,
424        TargetBufferLength: DWORD,
425        ExeName: LPSTR,
426    ) -> DWORD;
427    pub fn GetConsoleAliasW(
428        Source: LPWSTR,
429        TargetBuffer: LPWSTR,
430        TargetBufferLength: DWORD,
431        ExeName: LPWSTR,
432    ) -> DWORD;
433    pub fn GetConsoleAliasesLengthA(
434        ExeName: LPSTR,
435    ) -> DWORD;
436    pub fn GetConsoleAliasesLengthW(
437        ExeName: LPWSTR,
438    ) -> DWORD;
439    pub fn GetConsoleAliasExesLengthA() -> DWORD;
440    pub fn GetConsoleAliasExesLengthW() -> DWORD;
441    pub fn GetConsoleAliasesA(
442        AliasBuffer: LPSTR,
443        AliasBufferLength: DWORD,
444        ExeName: LPSTR,
445    ) -> DWORD;
446    pub fn GetConsoleAliasesW(
447        AliasBuffer: LPWSTR,
448        AliasBufferLength: DWORD,
449        ExeName: LPWSTR,
450    ) -> DWORD;
451    pub fn GetConsoleAliasExesA(
452        ExeNameBuffer: LPSTR,
453        ExeNameBufferLength: DWORD,
454    ) -> DWORD;
455    pub fn GetConsoleAliasExesW(
456        ExeNameBuffer: LPWSTR,
457        ExeNameBufferLength: DWORD,
458    ) -> DWORD;
459}