1 /**
2  * Windows API header module
3  *
4  * Translated from MinGW Windows headers
5  *
6  * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
7  * Source: $(DRUNTIMESRC core/sys/windows/_wincon.d)
8  */
9 /// Automatically imported and edited from the druntime module
10 /// core.sys.windows.wincon for the auto-generated win32 package.
11 module win32.wincon;
12 //version (Windows):
13 @system:
14 
15 version (ANSI) {} else version = Unicode;
16 version (Win32_UseLib) pragma(lib, "kernel32");
17 
18 import win32.w32api, win32.windef;
19 
20 // FIXME: clean up Windows version support
21 
22 enum {
23     FOREGROUND_BLUE             = 0x0001,
24     FOREGROUND_GREEN            = 0x0002,
25     FOREGROUND_RED              = 0x0004,
26     FOREGROUND_INTENSITY        = 0x0008,
27     BACKGROUND_BLUE             = 0x0010,
28     BACKGROUND_GREEN            = 0x0020,
29     BACKGROUND_RED              = 0x0040,
30     BACKGROUND_INTENSITY        = 0x0080,
31 
32     COMMON_LVB_LEADING_BYTE     = 0x0100,
33     COMMON_LVB_TRAILING_BYTE    = 0x0200,
34     COMMON_LVB_GRID_HORIZONTAL  = 0x0400,
35     COMMON_LVB_GRID_LVERTICAL   = 0x0800,
36     COMMON_LVB_GRID_RVERTICAL   = 0x1000,
37     COMMON_LVB_REVERSE_VIDEO    = 0x4000,
38     COMMON_LVB_UNDERSCORE       = 0x8000,
39 
40     COMMON_LVB_SBCSDBCS         = 0x0300,
41 }
42 
43 static if (_WIN32_WINNT >= 0x501) {
44     enum {
45         CONSOLE_FULLSCREEN_MODE = 1,
46         CONSOLE_WINDOWED_MODE   = 0
47     }
48 }
49 
50 enum {
51     CTRL_C_EVENT        = 0,
52     CTRL_BREAK_EVENT    = 1,
53     CTRL_CLOSE_EVENT    = 2,
54     CTRL_LOGOFF_EVENT   = 5,
55     CTRL_SHUTDOWN_EVENT = 6
56 }
57 
58 enum {
59     ENABLE_PROCESSED_INPUT        = 1,
60     ENABLE_LINE_INPUT             = 2,
61     ENABLE_ECHO_INPUT             = 4,
62     ENABLE_WINDOW_INPUT           = 8,
63     ENABLE_MOUSE_INPUT            = 16,
64     ENABLE_INSERT_MODE            = 32,
65     ENABLE_QUICK_EDIT_MODE        = 64,
66     ENABLE_EXTENDED_FLAGS         = 128,
67     ENABLE_AUTO_POSITION          = 256,
68     ENABLE_VIRTUAL_TERMINAL_INPUT = 512
69 }
70 
71 enum {
72     ENABLE_PROCESSED_OUTPUT            = 1,
73     ENABLE_WRAP_AT_EOL_OUTPUT          = 2,
74     ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4,
75     DISABLE_NEWLINE_AUTO_RETURN        = 8,
76     ENABLE_LVB_GRID_WORLDWIDE          = 16
77 }
78 
79 enum {
80     KEY_EVENT                 = 1,
81     MOUSE_EVENT               = 2,
82     WINDOW_BUFFER_SIZE_EVENT  = 4,
83     MENU_EVENT                = 8,
84     FOCUS_EVENT               = 16
85 }
86 enum {
87     RIGHT_ALT_PRESSED  = 1,
88     LEFT_ALT_PRESSED   = 2,
89     RIGHT_CTRL_PRESSED = 4,
90     LEFT_CTRL_PRESSED  = 8,
91     SHIFT_PRESSED      = 16,
92     NUMLOCK_ON         = 32,
93     SCROLLLOCK_ON      = 64,
94     CAPSLOCK_ON        = 128,
95     ENHANCED_KEY       = 256
96 }
97 enum {
98     FROM_LEFT_1ST_BUTTON_PRESSED  = 1,
99     RIGHTMOST_BUTTON_PRESSED      = 2,
100     FROM_LEFT_2ND_BUTTON_PRESSED  = 4,
101     FROM_LEFT_3RD_BUTTON_PRESSED  = 8,
102     FROM_LEFT_4TH_BUTTON_PRESSED  = 16
103 }
104 
105 enum {
106     MOUSE_MOVED   = 1,
107     DOUBLE_CLICK  = 2,
108     MOUSE_WHEELED = 4
109 }
110 
111 struct CHAR_INFO {
112     union _Char {
113         WCHAR UnicodeChar = 0;
114         CHAR AsciiChar;
115     }
116     union {
117         _Char Char;
118         WCHAR UnicodeChar;
119         CHAR AsciiChar;
120     }
121     WORD Attributes;
122 }
123 alias CHAR_INFO* PCHAR_INFO;
124 
125 struct SMALL_RECT {
126     SHORT Left;
127     SHORT Top;
128     SHORT Right;
129     SHORT Bottom;
130 }
131 alias SMALL_RECT* PSMALL_RECT;
132 
133 struct CONSOLE_CURSOR_INFO {
134     DWORD dwSize;
135     BOOL  bVisible;
136 }
137 alias CONSOLE_CURSOR_INFO* PCONSOLE_CURSOR_INFO;
138 
139 struct COORD {
140     SHORT X;
141     SHORT Y;
142 }
143 alias COORD* PCOORD;
144 
145 struct CONSOLE_FONT_INFO {
146     DWORD nFont;
147     COORD dwFontSize;
148 }
149 alias CONSOLE_FONT_INFO* PCONSOLE_FONT_INFO;
150 
151 struct CONSOLE_SCREEN_BUFFER_INFO {
152     COORD      dwSize;
153     COORD      dwCursorPosition;
154     WORD       wAttributes;
155     SMALL_RECT srWindow;
156     COORD      dwMaximumWindowSize;
157 }
158 alias CONSOLE_SCREEN_BUFFER_INFO* PCONSOLE_SCREEN_BUFFER_INFO;
159 
160 alias extern(Windows) BOOL function(DWORD) nothrow PHANDLER_ROUTINE;
161 
162 struct KEY_EVENT_RECORD {
163     BOOL  bKeyDown;
164     WORD  wRepeatCount;
165     WORD  wVirtualKeyCode;
166     WORD  wVirtualScanCode;
167     union _uChar {
168         WCHAR UnicodeChar = 0;
169         CHAR  AsciiChar;
170     }
171     union {
172         WCHAR UnicodeChar = 0;
173         CHAR  AsciiChar;
174         _uChar uChar;
175     }
176     DWORD dwControlKeyState;
177 }
178 alias KEY_EVENT_RECORD* PKEY_EVENT_RECORD;
179 
180 struct MOUSE_EVENT_RECORD {
181     COORD dwMousePosition;
182     DWORD dwButtonState;
183     DWORD dwControlKeyState;
184     DWORD dwEventFlags;
185 }
186 alias MOUSE_EVENT_RECORD* PMOUSE_EVENT_RECORD;
187 
188 struct WINDOW_BUFFER_SIZE_RECORD {
189     COORD dwSize;
190 }
191 alias WINDOW_BUFFER_SIZE_RECORD* PWINDOW_BUFFER_SIZE_RECORD;
192 
193 struct MENU_EVENT_RECORD {
194     UINT dwCommandId;
195 }
196 alias MENU_EVENT_RECORD* PMENU_EVENT_RECORD;
197 
198 struct FOCUS_EVENT_RECORD {
199     BOOL bSetFocus;
200 }
201 alias FOCUS_EVENT_RECORD* PFOCUS_EVENT_RECORD;
202 
203 struct INPUT_RECORD {
204     WORD EventType;
205     union _Event {
206         KEY_EVENT_RECORD KeyEvent;
207         MOUSE_EVENT_RECORD MouseEvent;
208         WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent;
209         MENU_EVENT_RECORD MenuEvent;
210         FOCUS_EVENT_RECORD FocusEvent;
211     }
212     union {
213         KEY_EVENT_RECORD KeyEvent;
214         MOUSE_EVENT_RECORD MouseEvent;
215         WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent;
216         MENU_EVENT_RECORD MenuEvent;
217         FOCUS_EVENT_RECORD FocusEvent;
218         _Event Event;
219     }
220 }
221 alias INPUT_RECORD* PINPUT_RECORD;
222 
223 extern (Windows) nothrow @nogc:
224 
225 BOOL AllocConsole();
226 HANDLE CreateConsoleScreenBuffer(DWORD, DWORD, const(SECURITY_ATTRIBUTES)*, DWORD, LPVOID);
227 BOOL FillConsoleOutputAttribute(HANDLE, WORD, DWORD, COORD, PDWORD);
228 BOOL FillConsoleOutputCharacterA(HANDLE, CHAR, DWORD, COORD, PDWORD);
229 BOOL FillConsoleOutputCharacterW(HANDLE, WCHAR, DWORD, COORD, PDWORD);
230 BOOL FlushConsoleInputBuffer(HANDLE);
231 BOOL FreeConsole();
232 BOOL GenerateConsoleCtrlEvent(DWORD, DWORD);
233 UINT GetConsoleCP();
234 BOOL GetConsoleCursorInfo(HANDLE, PCONSOLE_CURSOR_INFO);
235 BOOL GetConsoleMode(HANDLE,PDWORD);
236 UINT GetConsoleOutputCP();
237 BOOL GetConsoleScreenBufferInfo(HANDLE, PCONSOLE_SCREEN_BUFFER_INFO);
238 DWORD GetConsoleTitleA(LPSTR, DWORD);
239 DWORD GetConsoleTitleW(LPWSTR, DWORD);
240 COORD GetLargestConsoleWindowSize(HANDLE);
241 BOOL GetNumberOfConsoleInputEvents(HANDLE, PDWORD);
242 BOOL GetNumberOfConsoleMouseButtons(PDWORD);
243 BOOL PeekConsoleInputA(HANDLE, PINPUT_RECORD, DWORD, PDWORD);
244 BOOL PeekConsoleInputW(HANDLE, PINPUT_RECORD, DWORD, PDWORD);
245 BOOL ReadConsoleA(HANDLE, PVOID, DWORD, PDWORD, PVOID);
246 BOOL ReadConsoleW(HANDLE, PVOID, DWORD, PDWORD, PVOID);
247 BOOL ReadConsoleInputA(HANDLE, PINPUT_RECORD, DWORD, PDWORD);
248 BOOL ReadConsoleInputW(HANDLE, PINPUT_RECORD, DWORD, PDWORD);
249 BOOL ReadConsoleOutputAttribute(HANDLE, LPWORD, DWORD, COORD, LPDWORD);
250 BOOL ReadConsoleOutputCharacterA(HANDLE, LPSTR, DWORD, COORD, PDWORD);
251 BOOL ReadConsoleOutputCharacterW(HANDLE, LPWSTR, DWORD, COORD, PDWORD);
252 BOOL ReadConsoleOutputA(HANDLE, PCHAR_INFO, COORD, COORD, PSMALL_RECT);
253 BOOL ReadConsoleOutputW(HANDLE, PCHAR_INFO, COORD, COORD, PSMALL_RECT);
254 BOOL ScrollConsoleScreenBufferA(HANDLE, const(SMALL_RECT)*, const(SMALL_RECT)*, COORD, const(CHAR_INFO)*);
255 BOOL ScrollConsoleScreenBufferW(HANDLE, const(SMALL_RECT)*, const(SMALL_RECT)*, COORD, const(CHAR_INFO)*);
256 BOOL SetConsoleActiveScreenBuffer(HANDLE);
257 BOOL SetConsoleCP(UINT);
258 BOOL SetConsoleCtrlHandler(PHANDLER_ROUTINE, BOOL);
259 BOOL SetConsoleCursorInfo(HANDLE, const(CONSOLE_CURSOR_INFO)*);
260 BOOL SetConsoleCursorPosition(HANDLE, COORD);
261 
262 
263 static if (_WIN32_WINNT >= 0x500) {
264 BOOL GetConsoleDisplayMode(LPDWORD);
265 HWND GetConsoleWindow();
266 }
267 
268 static if (_WIN32_WINNT >= 0x501) {
269 BOOL AttachConsole(DWORD);
270 BOOL SetConsoleDisplayMode(HANDLE, DWORD, PCOORD);
271 enum DWORD ATTACH_PARENT_PROCESS = cast(DWORD)-1;
272 }
273 
274 BOOL SetConsoleMode(HANDLE, DWORD);
275 BOOL SetConsoleOutputCP(UINT);
276 BOOL SetConsoleScreenBufferSize(HANDLE, COORD);
277 BOOL SetConsoleTextAttribute(HANDLE, WORD);
278 BOOL SetConsoleTitleA(LPCSTR);
279 BOOL SetConsoleTitleW(LPCWSTR);
280 BOOL SetConsoleWindowInfo(HANDLE, BOOL, const(SMALL_RECT)*);
281 BOOL WriteConsoleA(HANDLE, PCVOID, DWORD, PDWORD, PVOID);
282 BOOL WriteConsoleW(HANDLE, PCVOID, DWORD, PDWORD, PVOID);
283 BOOL WriteConsoleInputA(HANDLE, const(INPUT_RECORD)*, DWORD, PDWORD);
284 BOOL WriteConsoleInputW(HANDLE, const(INPUT_RECORD)*, DWORD, PDWORD);
285 BOOL WriteConsoleOutputA(HANDLE, const(CHAR_INFO)*, COORD, COORD, PSMALL_RECT);
286 BOOL WriteConsoleOutputW(HANDLE, const(CHAR_INFO)*, COORD, COORD, PSMALL_RECT);
287 BOOL WriteConsoleOutputAttribute(HANDLE, const(WORD)*, DWORD, COORD, PDWORD);
288 BOOL WriteConsoleOutputCharacterA(HANDLE, LPCSTR, DWORD, COORD, PDWORD);
289 BOOL WriteConsoleOutputCharacterW(HANDLE, LPCWSTR, DWORD, COORD, PDWORD);
290 
291 version (Unicode) {
292     alias FillConsoleOutputCharacterW FillConsoleOutputCharacter;
293     alias GetConsoleTitleW GetConsoleTitle;
294     alias PeekConsoleInputW PeekConsoleInput;
295     alias ReadConsoleW ReadConsole;
296     alias ReadConsoleInputW ReadConsoleInput;
297     alias ReadConsoleOutputW ReadConsoleOutput;
298     alias ReadConsoleOutputCharacterW ReadConsoleOutputCharacter;
299     alias ScrollConsoleScreenBufferW ScrollConsoleScreenBuffer;
300     alias SetConsoleTitleW SetConsoleTitle;
301     alias WriteConsoleW WriteConsole;
302     alias WriteConsoleInputW WriteConsoleInput;
303     alias WriteConsoleOutputW WriteConsoleOutput;
304     alias WriteConsoleOutputCharacterW WriteConsoleOutputCharacter;
305 } else {
306     alias FillConsoleOutputCharacterA FillConsoleOutputCharacter;
307     alias GetConsoleTitleA GetConsoleTitle;
308     alias PeekConsoleInputA PeekConsoleInput;
309     alias ReadConsoleA ReadConsole;
310     alias ReadConsoleInputA ReadConsoleInput;
311     alias ReadConsoleOutputA ReadConsoleOutput;
312     alias ReadConsoleOutputCharacterA ReadConsoleOutputCharacter;
313     alias ScrollConsoleScreenBufferA ScrollConsoleScreenBuffer;
314     alias SetConsoleTitleA SetConsoleTitle;
315     alias WriteConsoleA WriteConsole;
316     alias WriteConsoleInputA WriteConsoleInput;
317     alias WriteConsoleOutputA WriteConsoleOutput;
318     alias WriteConsoleOutputCharacterA WriteConsoleOutputCharacter;
319 }