The OpenD Programming Language

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