2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) INRIA - Allan CORNET
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
7 * This file is hereby licensed under the terms of the GNU GPL v2.0,
8 * pursuant to article 5.3.4 of the CeCILL v.2.1.
9 * This file was originally licensed under the terms of the CeCILL v2.1,
10 * and continues to be available under such terms.
11 * For more information, see the COPYING file which you should have received
12 * along with this program.
16 /*--------------------------------------------------------------------------*/
18 #define _WIN32_WINNT 0x0500 // GetConsoleWindow
22 #pragma comment(lib, "shlwapi.lib")
24 #include "WinConsole.h"
25 #include "WndThread.h"
28 #include "os_string.h"
29 /*--------------------------------------------------------------------------*/
30 #define NameConsole "Console"
31 /*--------------------------------------------------------------------------*/
32 static CONSOLE_SCREEN_BUFFER_INFO csbiInfoSave;
33 static UINT savedCodePage;
34 static char ScilexConsoleName[MAX_PATH];
35 /*--------------------------------------------------------------------------*/
36 void UpdateConsoleColors(void)
38 HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
45 FillConsoleOutputAttribute(hConsole,
46 BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY,
47 csbiInfoSave.dwSize.X * csbiInfoSave.dwSize.Y,
51 SetConsoleTextAttribute(hConsole, BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY);
54 /*--------------------------------------------------------------------------*/
55 void SaveConsoleColors(void)
57 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfoSave);
59 /*--------------------------------------------------------------------------*/
60 void RestoreConsoleColors(void)
62 HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
69 FillConsoleOutputAttribute(hConsole,
70 csbiInfoSave.wAttributes,
71 csbiInfoSave.dwSize.X * csbiInfoSave.dwSize.Y,
74 SetConsoleTextAttribute(hConsole, csbiInfoSave.wAttributes);
76 /*--------------------------------------------------------------------------*/
77 void UpdateConsoleFont(void)
79 //change codepage to cp65001
80 SetConsoleOutputCP(65001);
82 /*--------------------------------------------------------------------------*/
83 void SaveConsoleFont(void)
85 savedCodePage = GetConsoleCP();
87 /*--------------------------------------------------------------------------*/
88 void RestoreConsoleFont(void)
90 SetConsoleCP(savedCodePage);
92 /*--------------------------------------------------------------------------*/
93 void RenameConsole(void)
96 char CurrentConsoleName[MAX_PATH];
97 char CurrentConsoleNameTmp[MAX_PATH];
99 GetConsoleTitle(CurrentConsoleName, MAX_PATH);
100 strncpy(CurrentConsoleNameTmp, CurrentConsoleName, strlen(NameConsole));
101 CurrentConsoleNameTmp[strlen(NameConsole)] = '\0';
103 if ( strcmp(CurrentConsoleNameTmp, NameConsole) != 0)
105 wsprintf(ScilexConsoleName, "%s %s", NameConsole, SCI_VERSION_STRING);
106 SetConsoleTitle(ScilexConsoleName);
109 hScilex = GetConsoleWindow();
112 HMENU hmenuConsole = NULL;
113 // Desactive croix dans la console
114 hmenuConsole = GetSystemMenu(hScilex, FALSE);
115 DeleteMenu(hmenuConsole, SC_CLOSE, MF_BYCOMMAND);
118 /*--------------------------------------------------------------------------*/
119 void RestoreExitButton(void)
122 hScilex = GetConsoleWindow();
125 HMENU hmenuConsole = NULL;
126 // Active croix dans la console
127 hmenuConsole = GetSystemMenu(hScilex, FALSE);
128 AppendMenu( hmenuConsole, MF_BYCOMMAND, SC_CLOSE, "&Close Alt+F4" );
131 /*--------------------------------------------------------------------------*/
132 void CreateScilabConsole(int ShowBanner)
136 SetConsoleState(0); /* Console DOS Cachée par défaut */
139 wsprintf(ScilexConsoleName, "%s %s (%d)", NameConsole, SCI_VERSION_STRING, getCurrentScilabId());
140 SetConsoleTitle(ScilexConsoleName);
142 CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
143 freopen("CONOUT$", "wb", stdout); /* redirect stdout --> CONOUT$*/
144 freopen("CONOUT$", "wb", stderr); /* redirect stderr --> CONOUT$*/
150 strcpy(line, " ___________________________________________\n");
152 wsprintf(line, " %s\n\n", SCI_VERSION_STRING);
154 strcpy(line, " ESI Group\n");
156 strcpy(line, " Copyright (c) 2017-2020 (ESI Group)\n");
158 strcpy(line, " Copyright (c) 2011-2017 (Scilab Enterprises)\n");
160 strcpy(line, " Copyright (c) 1989-2012 (INRIA)\n");
162 strcpy(line, " Copyright (c) 1989-2007 (ENPC)\n");
164 strcpy(line, " ___________________________________________\n\n");
168 hScilex = GetConsoleWindow();
171 HMENU hmenuConsole = NULL;
172 // Desactive croix dans la console
173 hmenuConsole = GetSystemMenu(hScilex, FALSE);
174 DeleteMenu(hmenuConsole, SC_CLOSE, MF_BYCOMMAND);
176 /* Cache la fenetre Console */
177 ShowWindow(hScilex, SW_HIDE);
180 /*--------------------------------------------------------------------------*/
181 void CloseScilabConsole(void)
187 /*--------------------------------------------------------------------------*/
188 char *getScilexConsoleName(void)
190 char *retName = NULL;
192 if (strlen(ScilexConsoleName) > 0)
194 retName = os_strdup(ScilexConsoleName);
198 /*--------------------------------------------------------------------------*/
199 int getXConsoleScreenSize(void)
201 return (csbiInfoSave.srWindow.Right - csbiInfoSave.srWindow.Left);
203 /*--------------------------------------------------------------------------*/
204 int getYConsoleScreenSize(void)
206 return (csbiInfoSave.srWindow.Bottom - csbiInfoSave.srWindow.Top);
208 /*--------------------------------------------------------------------------*/