import 'dart:ffi' as ffi;
import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart';
void main() {
ffi.Pointer<ffi.Uint32> pidPointer = calloc();
int hwnd = GetForegroundWindow();
GetWindowThreadProcessId(hwnd, pidPointer);
int pid = pidPointer.value;
print('Process ID of the active window: $pid');
free(pidPointer);
}
2条答案
按热度按时间kt06eoxx1#
平台精确的代码和访问本地API。在Windows的情况下,您可以使用Win32 API来获取有关活动窗口及其进程ID的统计信息。为此,您可以使用Dart的FFI(外部函数接口)来命名来自动态超链接库(DLL)的功能,如user32.Dll和psapi.Dll。
这里有一个例子
字符串
anhgbhbe2#
我终于找到了解决办法。
字符串