import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'dart:io' show Platform; final DynamicLibrary user32 = DynamicLibrary.open('user32.dll'); final DynamicLibrary kernel32 = DynamicLibrary.open('kernel32.dll'); typedef ShowWindowC = Int32 Function(IntPtr hWnd, Int32 nCmdShow); typedef ShowWindowDart = int Function(int hWnd, int nCmdShow); final ShowWindowDart ShowWindow = user32 .lookupFunction('ShowWindow'); typedef GetConsoleWindowC = IntPtr Function(); typedef GetConsoleWindowDart = int Function(); final GetConsoleWindowDart GetConsoleWindow = kernel32 .lookupFunction('GetConsoleWindow'); typedef AllocConsoleC = Int32 Function(); typedef AllocConsoleDart = int Function(); final AllocConsoleDart AllocConsole = kernel32 .lookupFunction('AllocConsole'); typedef FreeConsoleC = Int32 Function(); typedef FreeConsoleDart = int Function(); final FreeConsoleDart FreeConsole = kernel32 .lookupFunction('FreeConsole'); const int SW_HIDE = 0; const int SW_SHOW = 5; void createConsole() { AllocConsole(); // Now the console is created, you can show or hide it using the ShowWindow function } void hideConsole() { var consoleWnd = GetConsoleWindow(); ShowWindow(consoleWnd, SW_HIDE); } void showConsole() { var consoleWnd = GetConsoleWindow(); ShowWindow(consoleWnd, SW_SHOW); } void freeConsole() { FreeConsole(); }