2 * Win32 console functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
5 * Copyright 1997 Karl Garrison
6 * Copyright 1998 John Richardson
7 * Copyright 1998 Marcus Meissner
8 * Copyright 2001,2002,2004,2005,2010 Eric Pouech
9 * Copyright 2001 Alexandre Julliard
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #define NONAMELESSUNION
33 #define WIN32_NO_STATUS
40 #include "wine/condrv.h"
41 #include "wine/exception.h"
42 #include "wine/debug.h"
44 #include "kernel_private.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(console
);
48 /******************************************************************************
49 * GetConsoleWindow [KERNEL32.@] Get hwnd of the console window.
52 * Success: hwnd of the console window.
55 HWND WINAPI
GetConsoleWindow(void)
57 struct condrv_input_info info
;
60 ret
= DeviceIoControl( RtlGetCurrentPeb()->ProcessParameters
->ConsoleHandle
,
61 IOCTL_CONDRV_GET_INPUT_INFO
, NULL
, 0, &info
, sizeof(info
), NULL
, NULL
);
62 return ret
? LongToHandle( info
.win
) : NULL
;
66 /******************************************************************
67 * OpenConsoleW (KERNEL32.@)
70 * Open a handle to the current process console.
71 * Returns INVALID_HANDLE_VALUE on failure.
73 HANDLE WINAPI
OpenConsoleW(LPCWSTR name
, DWORD access
, BOOL inherit
, DWORD creation
)
75 SECURITY_ATTRIBUTES sa
;
77 TRACE("(%s, 0x%08x, %d, %u)\n", debugstr_w(name
), access
, inherit
, creation
);
79 if (!name
|| (wcsicmp( L
"CONIN$", name
) && wcsicmp( L
"CONOUT$", name
)) || creation
!= OPEN_EXISTING
)
81 SetLastError( ERROR_INVALID_PARAMETER
);
82 return INVALID_HANDLE_VALUE
;
85 sa
.nLength
= sizeof(sa
);
86 sa
.lpSecurityDescriptor
= NULL
;
87 sa
.bInheritHandle
= inherit
;
89 return CreateFileW( name
, access
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, &sa
, creation
, 0, NULL
);
92 /******************************************************************
93 * VerifyConsoleIoHandle (KERNEL32.@)
97 BOOL WINAPI
VerifyConsoleIoHandle(HANDLE handle
)
101 return !NtDeviceIoControlFile( handle
, NULL
, NULL
, NULL
, &io
, IOCTL_CONDRV_GET_MODE
,
102 NULL
, 0, &mode
, sizeof(mode
) );
105 /******************************************************************
106 * DuplicateConsoleHandle (KERNEL32.@)
110 HANDLE WINAPI
DuplicateConsoleHandle(HANDLE handle
, DWORD access
, BOOL inherit
,
114 return DuplicateHandle(GetCurrentProcess(), handle
, GetCurrentProcess(), &ret
,
115 access
, inherit
, options
) ? ret
: INVALID_HANDLE_VALUE
;
118 /******************************************************************
119 * CloseConsoleHandle (KERNEL32.@)
123 BOOL WINAPI
CloseConsoleHandle(HANDLE handle
)
125 return CloseHandle(handle
);
128 /******************************************************************
129 * GetConsoleInputWaitHandle (KERNEL32.@)
133 HANDLE WINAPI
GetConsoleInputWaitHandle(void)
135 return GetStdHandle( STD_INPUT_HANDLE
);
139 /***********************************************************************
140 * SetConsoleTitleA (KERNEL32.@)
142 BOOL WINAPI
SetConsoleTitleA( LPCSTR title
)
147 DWORD len
= MultiByteToWideChar( GetConsoleOutputCP(), 0, title
, -1, NULL
, 0 );
148 if (!(titleW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
)))) return FALSE
;
149 MultiByteToWideChar( GetConsoleOutputCP(), 0, title
, -1, titleW
, len
);
150 ret
= SetConsoleTitleW(titleW
);
151 HeapFree(GetProcessHeap(), 0, titleW
);
156 /***********************************************************************
157 * GetConsoleKeyboardLayoutNameA (KERNEL32.@)
159 BOOL WINAPI
GetConsoleKeyboardLayoutNameA(LPSTR layoutName
)
161 FIXME( "stub %p\n", layoutName
);
165 /***********************************************************************
166 * GetConsoleKeyboardLayoutNameW (KERNEL32.@)
168 BOOL WINAPI
GetConsoleKeyboardLayoutNameW(LPWSTR layoutName
)
172 FIXME( "stub %p\n", layoutName
);
176 /***********************************************************************
177 * GetConsoleTitleA (KERNEL32.@)
179 * See GetConsoleTitleW.
181 DWORD WINAPI
GetConsoleTitleA(LPSTR title
, DWORD size
)
183 WCHAR
*ptr
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
) * size
);
187 ret
= GetConsoleTitleW( ptr
, size
);
190 WideCharToMultiByte( GetConsoleOutputCP(), 0, ptr
, ret
+ 1, title
, size
, NULL
, NULL
);
193 HeapFree(GetProcessHeap(), 0, ptr
);
198 /***********************************************************************
199 * GetNumberOfConsoleMouseButtons (KERNEL32.@)
201 BOOL WINAPI
GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons
)
203 FIXME("(%p): stub\n", nrofbuttons
);
209 /******************************************************************
210 * GetConsoleDisplayMode (KERNEL32.@)
212 BOOL WINAPI
GetConsoleDisplayMode(LPDWORD lpModeFlags
)
214 TRACE("semi-stub: %p\n", lpModeFlags
);
215 /* It is safe to successfully report windowed mode */
220 /******************************************************************
221 * SetConsoleDisplayMode (KERNEL32.@)
223 BOOL WINAPI
SetConsoleDisplayMode(HANDLE hConsoleOutput
, DWORD dwFlags
,
224 COORD
*lpNewScreenBufferDimensions
)
226 TRACE("(%p, %x, (%d, %d))\n", hConsoleOutput
, dwFlags
,
227 lpNewScreenBufferDimensions
->X
, lpNewScreenBufferDimensions
->Y
);
230 /* We cannot switch to fullscreen */
236 /******************************************************************
241 * 0 if an error occurred, non-zero for success
244 DWORD WINAPI
GetConsoleAliasW(LPWSTR lpSource
, LPWSTR lpTargetBuffer
,
245 DWORD TargetBufferLength
, LPWSTR lpExename
)
247 FIXME("(%s,%p,%d,%s): stub\n", debugstr_w(lpSource
), lpTargetBuffer
, TargetBufferLength
, debugstr_w(lpExename
));
248 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
252 /******************************************************************
253 * GetConsoleProcessList (KERNEL32.@)
255 DWORD WINAPI
GetConsoleProcessList(LPDWORD processlist
, DWORD processcount
)
257 FIXME("(%p,%d): stub\n", processlist
, processcount
);
259 if (!processlist
|| processcount
< 1)
261 SetLastError(ERROR_INVALID_PARAMETER
);
268 /* Undocumented, called by native doskey.exe */
269 DWORD WINAPI
GetConsoleCommandHistoryA(DWORD unknown1
, DWORD unknown2
, DWORD unknown3
)
271 FIXME(": (0x%x, 0x%x, 0x%x) stub!\n", unknown1
, unknown2
, unknown3
);
272 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
276 /* Undocumented, called by native doskey.exe */
277 DWORD WINAPI
GetConsoleCommandHistoryW(DWORD unknown1
, DWORD unknown2
, DWORD unknown3
)
279 FIXME(": (0x%x, 0x%x, 0x%x) stub!\n", unknown1
, unknown2
, unknown3
);
280 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
284 /* Undocumented, called by native doskey.exe */
285 DWORD WINAPI
GetConsoleCommandHistoryLengthA(LPCSTR unknown
)
287 FIXME(": (%s) stub!\n", debugstr_a(unknown
));
288 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
292 /* Undocumented, called by native doskey.exe */
293 DWORD WINAPI
GetConsoleCommandHistoryLengthW(LPCWSTR unknown
)
295 FIXME(": (%s) stub!\n", debugstr_w(unknown
));
296 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
300 DWORD WINAPI
GetConsoleAliasesLengthA(LPSTR unknown
)
302 FIXME(": (%s) stub!\n", debugstr_a(unknown
));
303 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
307 DWORD WINAPI
GetConsoleAliasesLengthW(LPWSTR unknown
)
309 FIXME(": (%s) stub!\n", debugstr_w(unknown
));
310 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
314 DWORD WINAPI
GetConsoleAliasExesLengthA(void)
317 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
321 DWORD WINAPI
GetConsoleAliasExesLengthW(void)
324 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
328 VOID WINAPI
ExpungeConsoleCommandHistoryA(LPCSTR unknown
)
330 FIXME(": (%s) stub!\n", debugstr_a(unknown
));
331 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
334 VOID WINAPI
ExpungeConsoleCommandHistoryW(LPCWSTR unknown
)
336 FIXME(": (%s) stub!\n", debugstr_w(unknown
));
337 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
340 BOOL WINAPI
AddConsoleAliasA(LPSTR source
, LPSTR target
, LPSTR exename
)
342 FIXME(": (%s, %s, %s) stub!\n", debugstr_a(source
), debugstr_a(target
), debugstr_a(exename
));
343 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
347 BOOL WINAPI
AddConsoleAliasW(LPWSTR source
, LPWSTR target
, LPWSTR exename
)
349 FIXME(": (%s, %s, %s) stub!\n", debugstr_w(source
), debugstr_w(target
), debugstr_w(exename
));
350 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
355 BOOL WINAPI
SetConsoleIcon(HICON icon
)
357 FIXME(": (%p) stub!\n", icon
);
358 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
362 DWORD WINAPI
GetNumberOfConsoleFonts(void)
367 BOOL WINAPI
SetConsoleFont(HANDLE hConsole
, DWORD index
)
369 FIXME("(%p, %u): stub!\n", hConsole
, index
);
370 SetLastError(LOWORD(E_NOTIMPL
) /* win10 1709+ */);
374 BOOL WINAPI
SetConsoleKeyShortcuts(BOOL set
, BYTE keys
, VOID
*a
, DWORD b
)
376 FIXME(": (%u %u %p %u) stub!\n", set
, keys
, a
, b
);
377 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
382 BOOL WINAPI
GetCurrentConsoleFontEx(HANDLE hConsole
, BOOL maxwindow
, CONSOLE_FONT_INFOEX
*fontinfo
)
387 struct condrv_output_info info
;
388 WCHAR face_name
[LF_FACESIZE
- 1];
391 if (fontinfo
->cbSize
!= sizeof(CONSOLE_FONT_INFOEX
))
393 SetLastError(ERROR_INVALID_PARAMETER
);
397 if (!DeviceIoControl( hConsole
, IOCTL_CONDRV_GET_OUTPUT_INFO
, NULL
, 0,
398 &data
, sizeof(data
), &size
, NULL
))
400 SetLastError( ERROR_INVALID_HANDLE
);
407 fontinfo
->dwFontSize
.X
= min( data
.info
.width
, data
.info
.max_width
);
408 fontinfo
->dwFontSize
.Y
= min( data
.info
.height
, data
.info
.max_height
);
412 fontinfo
->dwFontSize
.X
= data
.info
.win_right
- data
.info
.win_left
+ 1;
413 fontinfo
->dwFontSize
.Y
= data
.info
.win_bottom
- data
.info
.win_top
+ 1;
415 size
-= sizeof(data
.info
);
416 if (size
) memcpy( fontinfo
->FaceName
, data
.face_name
, size
);
417 fontinfo
->FaceName
[size
/ sizeof(WCHAR
)] = 0;
418 fontinfo
->FontFamily
= data
.info
.font_pitch_family
;
419 fontinfo
->FontWeight
= data
.info
.font_weight
;
423 BOOL WINAPI
GetCurrentConsoleFont(HANDLE hConsole
, BOOL maxwindow
, CONSOLE_FONT_INFO
*fontinfo
)
426 CONSOLE_FONT_INFOEX res
;
428 res
.cbSize
= sizeof(CONSOLE_FONT_INFOEX
);
430 ret
= GetCurrentConsoleFontEx(hConsole
, maxwindow
, &res
);
433 fontinfo
->nFont
= res
.nFont
;
434 fontinfo
->dwFontSize
.X
= res
.dwFontSize
.X
;
435 fontinfo
->dwFontSize
.Y
= res
.dwFontSize
.Y
;
440 static COORD
get_console_font_size(HANDLE hConsole
, DWORD index
)
442 struct condrv_output_info info
;
445 if (index
>= GetNumberOfConsoleFonts())
447 SetLastError(ERROR_INVALID_PARAMETER
);
451 if (DeviceIoControl( hConsole
, IOCTL_CONDRV_GET_OUTPUT_INFO
, NULL
, 0, &info
, sizeof(info
), NULL
, NULL
))
453 c
.X
= info
.font_width
;
454 c
.Y
= info
.font_height
;
456 else SetLastError( ERROR_INVALID_HANDLE
);
460 #if defined(__i386__) && !defined(__MINGW32__) && !defined(_MSC_VER)
461 #undef GetConsoleFontSize
462 DWORD WINAPI
GetConsoleFontSize(HANDLE hConsole
, DWORD index
)
469 x
.c
= get_console_font_size(hConsole
, index
);
473 COORD WINAPI
GetConsoleFontSize(HANDLE hConsole
, DWORD index
)
475 return get_console_font_size(hConsole
, index
);
477 #endif /* !defined(__i386__) */
479 BOOL WINAPI
GetConsoleFontInfo(HANDLE hConsole
, BOOL maximize
, DWORD numfonts
, CONSOLE_FONT_INFO
*info
)
481 FIXME("(%p %d %u %p): stub!\n", hConsole
, maximize
, numfonts
, info
);
482 SetLastError(LOWORD(E_NOTIMPL
) /* win10 1709+ */);
486 BOOL WINAPI
SetCurrentConsoleFontEx(HANDLE hConsole
, BOOL maxwindow
, CONSOLE_FONT_INFOEX
*cfix
)
488 FIXME("(%p %d %p): stub!\n", hConsole
, maxwindow
, cfix
);
489 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);