Skip to content

Add getWindowHandle #548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/window_manager/example/lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
print('isFocused: ${await windowManager.isFocused()}');
},
),
if(Platform.isWindows)
PreferenceListItem(
title: const Text('getWindowHandle'),
onTap: () async {
final result = await windowManager.getWindowHandle();
print('HWND:$result');
},
),
PreferenceListItem(
title: const Text('show / hide'),
onTap: () async {
Expand Down
4 changes: 4 additions & 0 deletions packages/window_manager/lib/src/window_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ class WindowManager {
await _channel.invokeMethod('ensureInitialized');
}

Future<int> getWindowHandle()async{
return await _channel.invokeMethod('getWindowHandle') as int;
}

/// You can call this to remove the window frame (title bar, outline border, etc), which is basically everything except the Flutter view, also can call setTitleBarStyle(TitleBarStyle.normal) or setTitleBarStyle(TitleBarStyle.hidden) to restore it.
Future<void> setAsFrameless() async {
await _channel.invokeMethod('setAsFrameless');
Expand Down
6 changes: 5 additions & 1 deletion packages/window_manager/windows/window_manager_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,11 @@ void WindowManagerPlugin::HandleMethodCall(
window_manager->native_window =
::GetAncestor(registrar->GetView()->GetNativeWindow(), GA_ROOT);
result->Success(flutter::EncodableValue(true));
} else if (method_name.compare("waitUntilReadyToShow") == 0) {
}
else if (method_name.compare("getWindowHandle") == 0) {
result->Success(flutter::EncodableValue(reinterpret_cast<__int64>(window_manager->GetMainWindow())));
}
else if (method_name.compare("waitUntilReadyToShow") == 0) {
window_manager->WaitUntilReadyToShow();
result->Success(flutter::EncodableValue(true));
} else if (method_name.compare("setAsFrameless") == 0) {
Expand Down