[KERNEL32]
[reactos.git] / reactos / dll / win32 / kernel32 / client / console / console.c
index 657196d..12d820c 100644 (file)
@@ -240,17 +240,29 @@ IntCheckForConsoleFileName(IN LPCWSTR pszName,
 
 
 /*
- * @unimplemented (Undocumented)
+ * @implemented (Undocumented)
+ * @note See http://undoc.airesoft.co.uk/kernel32.dll/ConsoleMenuControl.php
  */
-BOOL
+HMENU
 WINAPI
-ConsoleMenuControl(HANDLE hConsole,
-                   DWORD Unknown1,
-                   DWORD Unknown2)
+ConsoleMenuControl(HANDLE hConsoleOutput,
+                   DWORD dwCmdIdLow,
+                   DWORD dwCmdIdHigh)
 {
-    DPRINT1("ConsoleMenuControl(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", hConsole, Unknown1, Unknown2);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return FALSE;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCONSOLE_MENUCONTROL MenuControlRequest = &ApiMessage.Data.MenuControlRequest;
+
+    MenuControlRequest->OutputHandle = hConsoleOutput;
+    MenuControlRequest->dwCmdIdLow   = dwCmdIdLow;
+    MenuControlRequest->dwCmdIdHigh  = dwCmdIdHigh;
+    MenuControlRequest->hMenu        = NULL;
+
+    CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                        NULL,
+                        CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepMenuControl),
+                        sizeof(CONSOLE_MENUCONTROL));
+
+    return MenuControlRequest->hMenu;
 }
 
 
@@ -334,12 +346,12 @@ GetConsoleDisplayMode(LPDWORD lpModeFlags)
  */
 DWORD
 WINAPI
-GetConsoleFontInfo(DWORD Unknown0,
-                   DWORD Unknown1,
-                   DWORD Unknown2,
-                   DWORD Unknown3)
+GetConsoleFontInfo(HANDLE hConsoleOutput,
+                   BOOL bMaximumWindow,
+                   DWORD nFontCount,
+                   PCONSOLE_FONT_INFO lpConsoleFontInfo)
 {
-    DPRINT1("GetConsoleFontInfo(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1, Unknown2, Unknown3);
+    DPRINT1("GetConsoleFontInfo(0x%p, %d, %lu, 0x%p) UNIMPLEMENTED!\n", hConsoleOutput, bMaximumWindow, nFontCount, lpConsoleFontInfo);
     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
     return 0;
 }
@@ -354,7 +366,7 @@ GetConsoleFontSize(HANDLE hConsoleOutput,
                    DWORD nFont)
 {
     COORD Empty = {0, 0};
-    DPRINT1("GetConsoleFontSize(0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput, nFont);
+    DPRINT1("GetConsoleFontSize(0x%p, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput, nFont);
     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
     return Empty;
 }
@@ -373,7 +385,7 @@ GetConsoleHardwareState(HANDLE hConsoleOutput,
     CONSOLE_API_MESSAGE ApiMessage;
     PCONSOLE_GETSETHWSTATE HardwareStateRequest = &ApiMessage.Data.HardwareStateRequest;
 
-    DPRINT1("GetConsoleHardwareState(%d, 0x%p) UNIMPLEMENTED!\n", Flags, State);
+    DPRINT1("GetConsoleHardwareState(%lu, 0x%p) UNIMPLEMENTED!\n", Flags, State);
 
     if (State == NULL)
     {
@@ -412,13 +424,13 @@ GetConsoleInputWaitHandle(VOID)
 /*
  * @unimplemented
  */
-INT
+BOOL
 WINAPI
 GetCurrentConsoleFont(HANDLE hConsoleOutput,
                       BOOL bMaximumWindow,
                       PCONSOLE_FONT_INFO lpConsoleCurrentFont)
 {
-    DPRINT1("GetCurrentConsoleFont(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput, bMaximumWindow, lpConsoleCurrentFont);
+    DPRINT1("GetCurrentConsoleFont(0x%p, 0x%x, 0x%p) UNIMPLEMENTED!\n", hConsoleOutput, bMaximumWindow, lpConsoleCurrentFont);
     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
     return 0;
 }
@@ -529,16 +541,32 @@ OpenConsoleW(LPCWSTR wsName,
 
 
 /*
- * @unimplemented (Undocumented)
+ * @implemented (Undocumented)
+ * @note See http://undoc.airesoft.co.uk/kernel32.dll/SetConsoleCursor.php
  */
 BOOL
 WINAPI
-SetConsoleCursor(DWORD Unknown0,
-                 DWORD Unknown1)
+SetConsoleCursor(HANDLE hConsoleOutput,
+                 HCURSOR hCursor)
 {
-    DPRINT1("SetConsoleCursor(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return FALSE;
+    NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCONSOLE_SETCURSOR SetCursorRequest = &ApiMessage.Data.SetCursorRequest;
+
+    SetCursorRequest->OutputHandle = hConsoleOutput;
+    SetCursorRequest->hCursor      = hCursor;
+
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                                 NULL,
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCursor),
+                                 sizeof(CONSOLE_SETCURSOR));
+    if (!NT_SUCCESS(Status))
+    {
+        BaseSetLastNTError(Status);
+        return FALSE;
+    }
+
+    return TRUE;
 }
 
 
@@ -582,10 +610,10 @@ SetConsoleDisplayMode(HANDLE hConsoleOutput,
  */
 BOOL
 WINAPI
-SetConsoleFont(DWORD Unknown0,
-               DWORD Unknown1)
+SetConsoleFont(HANDLE hConsoleOutput,
+               DWORD nFont)
 {
-    DPRINT1("SetConsoleFont(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1);
+    DPRINT1("SetConsoleFont(0x%p, %lu) UNIMPLEMENTED!\n", hConsoleOutput, nFont);
     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
     return FALSE;
 }
@@ -604,7 +632,7 @@ SetConsoleHardwareState(HANDLE hConsoleOutput,
     CONSOLE_API_MESSAGE ApiMessage;
     PCONSOLE_GETSETHWSTATE HardwareStateRequest = &ApiMessage.Data.HardwareStateRequest;
 
-    DPRINT1("SetConsoleHardwareState(%d, %d) UNIMPLEMENTED!\n", Flags, State);
+    DPRINT1("SetConsoleHardwareState(%lu, %lu) UNIMPLEMENTED!\n", Flags, State);
 
     HardwareStateRequest->OutputHandle = hConsoleOutput;
     HardwareStateRequest->State = State;
@@ -640,57 +668,102 @@ SetConsoleKeyShortcuts(DWORD Unknown0,
 
 
 /*
- * @unimplemented (Undocumented)
+ * @implemented (Undocumented)
+ * @note See http://undoc.airesoft.co.uk/kernel32.dll/SetConsoleMaximumWindowSize.php
+ *       Does nothing, returns TRUE only. Checked on Windows Server 2003.
  */
 BOOL
 WINAPI
-SetConsoleMaximumWindowSize(DWORD Unknown0,
-                            DWORD Unknown1)
+SetConsoleMaximumWindowSize(HANDLE hConsoleOutput,
+                            COORD dwMaximumSize)
 {
-    DPRINT1("SetConsoleMaximumWindowSize(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return FALSE;
+    DPRINT1("SetConsoleMaximumWindowSize(0x%p, {%d, %d}) does nothing\n",
+            hConsoleOutput, dwMaximumSize.X, dwMaximumSize.Y);
+    return TRUE;
 }
 
 
 /*
- * @unimplemented (Undocumented)
+ * @implemented (Undocumented)
  */
 BOOL
 WINAPI
-SetConsoleMenuClose(DWORD Unknown0)
+SetConsoleMenuClose(BOOL bEnable)
 {
-    DPRINT1("SetConsoleMenuClose(0x%x) UNIMPLEMENTED!\n", Unknown0);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return FALSE;
+    NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCONSOLE_SETMENUCLOSE SetMenuCloseRequest = &ApiMessage.Data.SetMenuCloseRequest;
+
+    SetMenuCloseRequest->Enable = bEnable;
+
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                                 NULL,
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetMenuClose),
+                                 sizeof(CONSOLE_SETMENUCLOSE));
+    if (!NT_SUCCESS(Status))
+    {
+        BaseSetLastNTError(Status);
+        return FALSE;
+    }
+
+    return TRUE;
 }
 
 
 /*
- * @unimplemented (Undocumented)
+ * @implemented (Undocumented)
+ * @note See http://comments.gmane.org/gmane.comp.lang.harbour.devel/27844
+ *       Usage example: https://github.com/harbour/core/commit/d79a1b7b812cbde6ddf718ebfd6939a24f633e52
  */
 BOOL
 WINAPI
-SetConsolePalette(DWORD Unknown0,
-                  DWORD Unknown1,
-                  DWORD Unknown2)
+SetConsolePalette(HANDLE hConsoleOutput,
+                  HPALETTE hPalette,
+                  UINT dwUsage)
 {
-    DPRINT1("SetConsolePalette(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1, Unknown2);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return FALSE;
+    NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCONSOLE_SETPALETTE SetPaletteRequest = &ApiMessage.Data.SetPaletteRequest;
+
+    SetPaletteRequest->OutputHandle  = hConsoleOutput;
+    SetPaletteRequest->PaletteHandle = hPalette;
+    SetPaletteRequest->Usage         = dwUsage;
+
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                                 NULL,
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetPalette),
+                                 sizeof(CONSOLE_SETPALETTE));
+    if (!NT_SUCCESS(Status))
+    {
+        BaseSetLastNTError(Status);
+        return FALSE;
+    }
+
+    return TRUE;
 }
 
 /*
- * @unimplemented (Undocumented)
+ * @implemented (Undocumented)
+ * @note See http://undoc.airesoft.co.uk/kernel32.dll/ShowConsoleCursor.php
  */
-DWORD
+INT
 WINAPI
-ShowConsoleCursor(DWORD Unknown0,
-                  DWORD Unknown1)
+ShowConsoleCursor(HANDLE hConsoleOutput,
+                  BOOL bShow)
 {
-    DPRINT1("ShowConsoleCursor(0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return 0;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCONSOLE_SHOWCURSOR ShowCursorRequest = &ApiMessage.Data.ShowCursorRequest;
+
+    ShowCursorRequest->OutputHandle = hConsoleOutput;
+    ShowCursorRequest->Show         = bShow;
+    ShowCursorRequest->RefCount     = 0;
+
+    CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                        NULL,
+                        CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepShowCursor),
+                        sizeof(CONSOLE_SHOWCURSOR));
+
+    return ShowCursorRequest->RefCount;
 }
 
 
@@ -731,38 +804,6 @@ VerifyConsoleIoHandle(HANDLE Handle)
 }
 
 
-/*
- * @unimplemented
- */
-DWORD
-WINAPI
-WriteConsoleInputVDMA(DWORD Unknown0,
-                      DWORD Unknown1,
-                      DWORD Unknown2,
-                      DWORD Unknown3)
-{
-    DPRINT1("WriteConsoleInputVDMA(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1, Unknown2, Unknown3);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return 0;
-}
-
-
-/*
- * @unimplemented
- */
-DWORD
-WINAPI
-WriteConsoleInputVDMW(DWORD Unknown0,
-                      DWORD Unknown1,
-                      DWORD Unknown2,
-                      DWORD Unknown3)
-{
-    DPRINT1("WriteConsoleInputVDMW(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1, Unknown2, Unknown3);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return 0;
-}
-
-
 /*
  * @implemented (Undocumented)
  */
@@ -882,8 +923,6 @@ AllocConsole(VOID)
     CONSOLE_API_MESSAGE ApiMessage;
     PCONSOLE_ALLOCCONSOLE AllocConsoleRequest = &ApiMessage.Data.AllocConsoleRequest;
     PCSR_CAPTURE_BUFFER CaptureBuffer;
-    LPWSTR AppPath = NULL;
-    SIZE_T Length = 0;
 
     if (Parameters->ConsoleHandle)
     {
@@ -904,16 +943,10 @@ AllocConsole(VOID)
                               sizeof(CONSOLE_START_INFO),
                               (PVOID*)&AllocConsoleRequest->ConsoleStartInfo);
 
-/** Copied from BasepInitConsole **********************************************/
-    InitConsoleInfo(AllocConsoleRequest->ConsoleStartInfo);
-
-    AppPath = AllocConsoleRequest->ConsoleStartInfo->AppPath;
-    Length = min(MAX_PATH, Parameters->ImagePathName.Length / sizeof(WCHAR));
-    wcsncpy(AppPath, Parameters->ImagePathName.Buffer, Length);
-    AppPath[Length] = L'\0';
-/******************************************************************************/
+    InitConsoleInfo(AllocConsoleRequest->ConsoleStartInfo,
+                    &Parameters->ImagePathName);
 
-    AllocConsoleRequest->Console = NULL;
+    AllocConsoleRequest->ConsoleHandle  = NULL;
     AllocConsoleRequest->CtrlDispatcher = ConsoleControlDispatcher;
     AllocConsoleRequest->PropDispatcher = PropDialogHandler;
 
@@ -930,7 +963,7 @@ AllocConsole(VOID)
         return FALSE;
     }
 
-    Parameters->ConsoleHandle = AllocConsoleRequest->Console;
+    Parameters->ConsoleHandle = AllocConsoleRequest->ConsoleHandle;
     SetStdHandle(STD_INPUT_HANDLE , AllocConsoleRequest->InputHandle );
     SetStdHandle(STD_OUTPUT_HANDLE, AllocConsoleRequest->OutputHandle);
     SetStdHandle(STD_ERROR_HANDLE , AllocConsoleRequest->ErrorHandle );
@@ -1203,7 +1236,7 @@ BOOL
 WINAPI
 GetNumberOfConsoleMouseButtons(LPDWORD lpNumberOfMouseButtons)
 {
-    DPRINT1("GetNumberOfConsoleMouseButtons(0x%x) UNIMPLEMENTED!\n", lpNumberOfMouseButtons);
+    DPRINT1("GetNumberOfConsoleMouseButtons(0x%p) UNIMPLEMENTED!\n", lpNumberOfMouseButtons);
     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
     return FALSE;
 }
@@ -1903,17 +1936,15 @@ GetConsoleCP(VOID)
     CONSOLE_API_MESSAGE ApiMessage;
 
     /* Get the Input Code Page */
-    ApiMessage.Data.ConsoleCPRequest.InputCP = TRUE;
+    ApiMessage.Data.ConsoleCPRequest.InputCP  = TRUE;
+    ApiMessage.Data.ConsoleCPRequest.CodePage = 0;
 
     Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
                                  CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCP),
                                  sizeof(CONSOLE_GETSETINPUTOUTPUTCP));
-    if (!NT_SUCCESS(Status))
-    {
-        BaseSetLastNTError(Status);
-        return 0;
-    }
+
+    if (!NT_SUCCESS(Status)) BaseSetLastNTError(Status);
 
     return ApiMessage.Data.ConsoleCPRequest.CodePage;
 }
@@ -1932,17 +1963,15 @@ SetConsoleCP(UINT wCodePageID)
     CONSOLE_API_MESSAGE ApiMessage;
 
     /* Set the Input Code Page */
-    ApiMessage.Data.ConsoleCPRequest.InputCP = TRUE;
+    ApiMessage.Data.ConsoleCPRequest.InputCP  = TRUE;
     ApiMessage.Data.ConsoleCPRequest.CodePage = wCodePageID;
 
     Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
                                  CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCP),
                                  sizeof(CONSOLE_GETSETINPUTOUTPUTCP));
-    if (!NT_SUCCESS(Status))
-    {
-        BaseSetLastNTError(Status);
-    }
+
+    if (!NT_SUCCESS(Status)) BaseSetLastNTError(Status);
 
     return NT_SUCCESS(Status);
 }
@@ -1961,17 +1990,15 @@ GetConsoleOutputCP(VOID)
     CONSOLE_API_MESSAGE ApiMessage;
 
     /* Get the Output Code Page */
-    ApiMessage.Data.ConsoleCPRequest.InputCP = FALSE;
+    ApiMessage.Data.ConsoleCPRequest.InputCP  = FALSE;
+    ApiMessage.Data.ConsoleCPRequest.CodePage = 0;
 
     Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
                                  CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCP),
                                  sizeof(CONSOLE_GETSETINPUTOUTPUTCP));
-    if (!NT_SUCCESS(Status))
-    {
-        BaseSetLastNTError (Status);
-        return 0;
-    }
+
+    if (!NT_SUCCESS(Status)) BaseSetLastNTError(Status);
 
     return ApiMessage.Data.ConsoleCPRequest.CodePage;
 }
@@ -1990,17 +2017,15 @@ SetConsoleOutputCP(UINT wCodePageID)
     CONSOLE_API_MESSAGE ApiMessage;
 
     /* Set the Output Code Page */
-    ApiMessage.Data.ConsoleCPRequest.InputCP = FALSE;
+    ApiMessage.Data.ConsoleCPRequest.InputCP  = FALSE;
     ApiMessage.Data.ConsoleCPRequest.CodePage = wCodePageID;
 
     Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
                                  NULL,
                                  CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCP),
                                  sizeof(CONSOLE_GETSETINPUTOUTPUTCP));
-    if (!NT_SUCCESS(Status))
-    {
-        BaseSetLastNTError(Status);
-    }
+
+    if (!NT_SUCCESS(Status)) BaseSetLastNTError(Status);
 
     return NT_SUCCESS(Status);
 }
@@ -2135,7 +2160,7 @@ AttachConsole(DWORD dwProcessId)
         return FALSE;
     }
 
-    Parameters->ConsoleHandle = AttachConsoleRequest->Console;
+    Parameters->ConsoleHandle = AttachConsoleRequest->ConsoleHandle;
     SetStdHandle(STD_INPUT_HANDLE , AttachConsoleRequest->InputHandle );
     SetStdHandle(STD_OUTPUT_HANDLE, AttachConsoleRequest->OutputHandle);
     SetStdHandle(STD_ERROR_HANDLE , AttachConsoleRequest->ErrorHandle );