123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- 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<ShowWindowC, ShowWindowDart>('ShowWindow');
- typedef GetConsoleWindowC = IntPtr Function();
- typedef GetConsoleWindowDart = int Function();
- final GetConsoleWindowDart GetConsoleWindow = kernel32
- .lookupFunction<GetConsoleWindowC, GetConsoleWindowDart>('GetConsoleWindow');
- typedef AllocConsoleC = Int32 Function();
- typedef AllocConsoleDart = int Function();
- final AllocConsoleDart AllocConsole = kernel32
- .lookupFunction<AllocConsoleC, AllocConsoleDart>('AllocConsole');
- typedef FreeConsoleC = Int32 Function();
- typedef FreeConsoleDart = int Function();
- final FreeConsoleDart FreeConsole = kernel32
- .lookupFunction<FreeConsoleC, FreeConsoleDart>('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();
- }
|