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/debug.h"
42 #include "kernel_private.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(console
);
46 /******************************************************************************
47 * GetConsoleWindow [KERNEL32.@] Get hwnd of the console window.
50 * Success: hwnd of the console window.
53 HWND WINAPI
GetConsoleWindow(void)
58 ret
= DeviceIoControl( RtlGetCurrentPeb()->ProcessParameters
->ConsoleHandle
,
59 IOCTL_CONDRV_GET_WINDOW
, NULL
, 0, &win
, sizeof(win
), NULL
, NULL
);
60 return ret
? LongToHandle( win
) : NULL
;
64 /******************************************************************
65 * OpenConsoleW (KERNEL32.@)
68 * Open a handle to the current process console.
69 * Returns INVALID_HANDLE_VALUE on failure.
71 HANDLE WINAPI
OpenConsoleW(LPCWSTR name
, DWORD access
, BOOL inherit
, DWORD creation
)
73 SECURITY_ATTRIBUTES sa
;
75 TRACE("(%s, 0x%08x, %d, %u)\n", debugstr_w(name
), access
, inherit
, creation
);
77 if (!name
|| (wcsicmp( L
"CONIN$", name
) && wcsicmp( L
"CONOUT$", name
)) || creation
!= OPEN_EXISTING
)
79 SetLastError( ERROR_INVALID_PARAMETER
);
80 return INVALID_HANDLE_VALUE
;
83 sa
.nLength
= sizeof(sa
);
84 sa
.lpSecurityDescriptor
= NULL
;
85 sa
.bInheritHandle
= inherit
;
87 return CreateFileW( name
, access
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, &sa
, creation
, 0, NULL
);
90 /******************************************************************
91 * VerifyConsoleIoHandle (KERNEL32.@)
95 BOOL WINAPI
VerifyConsoleIoHandle(HANDLE handle
)
99 return !NtDeviceIoControlFile( handle
, NULL
, NULL
, NULL
, &io
, IOCTL_CONDRV_GET_MODE
,
100 NULL
, 0, &mode
, sizeof(mode
) );
103 /******************************************************************
104 * DuplicateConsoleHandle (KERNEL32.@)
108 HANDLE WINAPI
DuplicateConsoleHandle(HANDLE handle
, DWORD access
, BOOL inherit
,
112 return DuplicateHandle(GetCurrentProcess(), handle
, GetCurrentProcess(), &ret
,
113 access
, inherit
, options
) ? ret
: INVALID_HANDLE_VALUE
;
116 /******************************************************************
117 * CloseConsoleHandle (KERNEL32.@)
121 BOOL WINAPI
CloseConsoleHandle(HANDLE handle
)
123 return CloseHandle(handle
);
126 /******************************************************************
127 * GetConsoleInputWaitHandle (KERNEL32.@)
131 HANDLE WINAPI
GetConsoleInputWaitHandle(void)
133 return GetStdHandle( STD_INPUT_HANDLE
);
137 /***********************************************************************
138 * SetConsoleTitleA (KERNEL32.@)
140 BOOL WINAPI
SetConsoleTitleA( LPCSTR title
)
145 DWORD len
= MultiByteToWideChar( GetConsoleOutputCP(), 0, title
, -1, NULL
, 0 );
146 if (!(titleW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
)))) return FALSE
;
147 MultiByteToWideChar( GetConsoleOutputCP(), 0, title
, -1, titleW
, len
);
148 ret
= SetConsoleTitleW(titleW
);
149 HeapFree(GetProcessHeap(), 0, titleW
);
154 /***********************************************************************
155 * GetConsoleKeyboardLayoutNameA (KERNEL32.@)
157 BOOL WINAPI
GetConsoleKeyboardLayoutNameA(LPSTR layoutName
)
159 FIXME( "stub %p\n", layoutName
);
163 /***********************************************************************
164 * GetConsoleKeyboardLayoutNameW (KERNEL32.@)
166 BOOL WINAPI
GetConsoleKeyboardLayoutNameW(LPWSTR layoutName
)
170 FIXME( "stub %p\n", layoutName
);
174 /***********************************************************************
175 * GetConsoleTitleA (KERNEL32.@)
177 * See GetConsoleTitleW.
179 DWORD WINAPI
GetConsoleTitleA(LPSTR title
, DWORD size
)
181 WCHAR
*ptr
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
) * size
);
185 ret
= GetConsoleTitleW( ptr
, size
);
188 WideCharToMultiByte( GetConsoleOutputCP(), 0, ptr
, ret
+ 1, title
, size
, NULL
, NULL
);
191 HeapFree(GetProcessHeap(), 0, ptr
);
196 /***********************************************************************
197 * GetNumberOfConsoleMouseButtons (KERNEL32.@)
199 BOOL WINAPI
GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons
)
201 FIXME("(%p): stub\n", nrofbuttons
);
207 /******************************************************************
208 * GetConsoleDisplayMode (KERNEL32.@)
210 BOOL WINAPI
GetConsoleDisplayMode(LPDWORD lpModeFlags
)
212 TRACE("semi-stub: %p\n", lpModeFlags
);
213 /* It is safe to successfully report windowed mode */
218 /******************************************************************
219 * SetConsoleDisplayMode (KERNEL32.@)
221 BOOL WINAPI
SetConsoleDisplayMode(HANDLE hConsoleOutput
, DWORD dwFlags
,
222 COORD
*lpNewScreenBufferDimensions
)
224 TRACE("(%p, %x, (%d, %d))\n", hConsoleOutput
, dwFlags
,
225 lpNewScreenBufferDimensions
->X
, lpNewScreenBufferDimensions
->Y
);
228 /* We cannot switch to fullscreen */
234 /******************************************************************
239 * 0 if an error occurred, non-zero for success
242 DWORD WINAPI
GetConsoleAliasW(LPWSTR lpSource
, LPWSTR lpTargetBuffer
,
243 DWORD TargetBufferLength
, LPWSTR lpExename
)
245 FIXME("(%s,%p,%d,%s): stub\n", debugstr_w(lpSource
), lpTargetBuffer
, TargetBufferLength
, debugstr_w(lpExename
));
246 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
250 /******************************************************************
251 * GetConsoleProcessList (KERNEL32.@)
253 DWORD WINAPI
GetConsoleProcessList(LPDWORD processlist
, DWORD processcount
)
255 FIXME("(%p,%d): stub\n", processlist
, processcount
);
257 if (!processlist
|| processcount
< 1)
259 SetLastError(ERROR_INVALID_PARAMETER
);
266 /* Undocumented, called by native doskey.exe */
267 DWORD WINAPI
GetConsoleCommandHistoryA(DWORD unknown1
, DWORD unknown2
, DWORD unknown3
)
269 FIXME(": (0x%x, 0x%x, 0x%x) stub!\n", unknown1
, unknown2
, unknown3
);
270 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
274 /* Undocumented, called by native doskey.exe */
275 DWORD WINAPI
GetConsoleCommandHistoryW(DWORD unknown1
, DWORD unknown2
, DWORD unknown3
)
277 FIXME(": (0x%x, 0x%x, 0x%x) stub!\n", unknown1
, unknown2
, unknown3
);
278 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
282 /* Undocumented, called by native doskey.exe */
283 DWORD WINAPI
GetConsoleCommandHistoryLengthA(LPCSTR unknown
)
285 FIXME(": (%s) stub!\n", debugstr_a(unknown
));
286 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
290 /* Undocumented, called by native doskey.exe */
291 DWORD WINAPI
GetConsoleCommandHistoryLengthW(LPCWSTR unknown
)
293 FIXME(": (%s) stub!\n", debugstr_w(unknown
));
294 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
298 DWORD WINAPI
GetConsoleAliasesLengthA(LPSTR unknown
)
300 FIXME(": (%s) stub!\n", debugstr_a(unknown
));
301 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
305 DWORD WINAPI
GetConsoleAliasesLengthW(LPWSTR unknown
)
307 FIXME(": (%s) stub!\n", debugstr_w(unknown
));
308 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
312 DWORD WINAPI
GetConsoleAliasExesLengthA(void)
315 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
319 DWORD WINAPI
GetConsoleAliasExesLengthW(void)
322 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
326 VOID WINAPI
ExpungeConsoleCommandHistoryA(LPCSTR unknown
)
328 FIXME(": (%s) stub!\n", debugstr_a(unknown
));
329 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
332 VOID WINAPI
ExpungeConsoleCommandHistoryW(LPCWSTR unknown
)
334 FIXME(": (%s) stub!\n", debugstr_w(unknown
));
335 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
338 BOOL WINAPI
AddConsoleAliasA(LPSTR source
, LPSTR target
, LPSTR exename
)
340 FIXME(": (%s, %s, %s) stub!\n", debugstr_a(source
), debugstr_a(target
), debugstr_a(exename
));
341 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
345 BOOL WINAPI
AddConsoleAliasW(LPWSTR source
, LPWSTR target
, LPWSTR exename
)
347 FIXME(": (%s, %s, %s) stub!\n", debugstr_w(source
), debugstr_w(target
), debugstr_w(exename
));
348 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
353 BOOL WINAPI
SetConsoleIcon(HICON icon
)
355 FIXME(": (%p) stub!\n", icon
);
356 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
360 DWORD WINAPI
GetNumberOfConsoleFonts(void)
365 BOOL WINAPI
SetConsoleFont(HANDLE hConsole
, DWORD index
)
367 FIXME("(%p, %u): stub!\n", hConsole
, index
);
368 SetLastError(LOWORD(E_NOTIMPL
) /* win10 1709+ */);
372 BOOL WINAPI
SetConsoleKeyShortcuts(BOOL set
, BYTE keys
, VOID
*a
, DWORD b
)
374 FIXME(": (%u %u %p %u) stub!\n", set
, keys
, a
, b
);
375 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
380 BOOL WINAPI
GetCurrentConsoleFontEx(HANDLE hConsole
, BOOL maxwindow
, CONSOLE_FONT_INFOEX
*fontinfo
)
385 struct condrv_output_info info
;
386 WCHAR face_name
[LF_FACESIZE
- 1];
389 if (fontinfo
->cbSize
!= sizeof(CONSOLE_FONT_INFOEX
))
391 SetLastError(ERROR_INVALID_PARAMETER
);
395 if (!DeviceIoControl( hConsole
, IOCTL_CONDRV_GET_OUTPUT_INFO
, NULL
, 0,
396 &data
, sizeof(data
), &size
, NULL
))
398 SetLastError( ERROR_INVALID_HANDLE
);
405 fontinfo
->dwFontSize
.X
= min( data
.info
.width
, data
.info
.max_width
);
406 fontinfo
->dwFontSize
.Y
= min( data
.info
.height
, data
.info
.max_height
);
410 fontinfo
->dwFontSize
.X
= data
.info
.font_width
;
411 fontinfo
->dwFontSize
.Y
= data
.info
.font_height
;
413 size
-= sizeof(data
.info
);
414 if (size
) memcpy( fontinfo
->FaceName
, data
.face_name
, size
);
415 fontinfo
->FaceName
[size
/ sizeof(WCHAR
)] = 0;
416 fontinfo
->FontFamily
= data
.info
.font_pitch_family
;
417 fontinfo
->FontWeight
= data
.info
.font_weight
;
421 BOOL WINAPI
GetCurrentConsoleFont(HANDLE hConsole
, BOOL maxwindow
, CONSOLE_FONT_INFO
*fontinfo
)
424 CONSOLE_FONT_INFOEX res
;
426 res
.cbSize
= sizeof(CONSOLE_FONT_INFOEX
);
428 ret
= GetCurrentConsoleFontEx(hConsole
, maxwindow
, &res
);
431 fontinfo
->nFont
= res
.nFont
;
432 fontinfo
->dwFontSize
.X
= res
.dwFontSize
.X
;
433 fontinfo
->dwFontSize
.Y
= res
.dwFontSize
.Y
;
438 static COORD
get_console_font_size(HANDLE hConsole
, DWORD index
)
440 struct condrv_output_info info
;
443 if (index
>= GetNumberOfConsoleFonts())
445 SetLastError(ERROR_INVALID_PARAMETER
);
449 if (DeviceIoControl( hConsole
, IOCTL_CONDRV_GET_OUTPUT_INFO
, NULL
, 0, &info
, sizeof(info
), NULL
, NULL
))
451 c
.X
= info
.font_width
;
452 c
.Y
= info
.font_height
;
454 else SetLastError( ERROR_INVALID_HANDLE
);
458 #if defined(__i386__) && !defined(__MINGW32__) && !defined(_MSC_VER)
459 #undef GetConsoleFontSize
460 DWORD WINAPI
GetConsoleFontSize(HANDLE hConsole
, DWORD index
)
467 x
.c
= get_console_font_size(hConsole
, index
);
471 COORD WINAPI
GetConsoleFontSize(HANDLE hConsole
, DWORD index
)
473 return get_console_font_size(hConsole
, index
);
475 #endif /* !defined(__i386__) */
477 BOOL WINAPI
GetConsoleFontInfo(HANDLE hConsole
, BOOL maximize
, DWORD numfonts
, CONSOLE_FONT_INFO
*info
)
479 FIXME("(%p %d %u %p): stub!\n", hConsole
, maximize
, numfonts
, info
);
480 SetLastError(LOWORD(E_NOTIMPL
) /* win10 1709+ */);
484 BOOL WINAPI
SetCurrentConsoleFontEx(HANDLE hConsole
, BOOL maxwindow
, CONSOLE_FONT_INFOEX
*cfix
)
486 FIXME("(%p %d %p): stub!\n", hConsole
, maxwindow
, cfix
);
487 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);