Skip to content

Commit bc893bf

Browse files
copywith9copywith9
and
copywith9
authored
Add getWindowHandle (#548)
Co-authored-by: copywith9 <copywith9@example.com>
1 parent db19195 commit bc893bf

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

packages/window_manager/example/lib/pages/home.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
180180
print('isFocused: ${await windowManager.isFocused()}');
181181
},
182182
),
183+
if(Platform.isWindows)
184+
PreferenceListItem(
185+
title: const Text('getWindowHandle'),
186+
onTap: () async {
187+
final result = await windowManager.getWindowHandle();
188+
print('HWND:$result');
189+
},
190+
),
183191
PreferenceListItem(
184192
title: const Text('show / hide'),
185193
onTap: () async {

packages/window_manager/lib/src/window_manager.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ class WindowManager {
104104
await _channel.invokeMethod('ensureInitialized');
105105
}
106106

107+
Future<int> getWindowHandle()async{
108+
return await _channel.invokeMethod('getWindowHandle') as int;
109+
}
110+
107111
/// 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.
108112
Future<void> setAsFrameless() async {
109113
await _channel.invokeMethod('setAsFrameless');

packages/window_manager/windows/window_manager_plugin.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,11 @@ void WindowManagerPlugin::HandleMethodCall(
350350
window_manager->native_window =
351351
::GetAncestor(registrar->GetView()->GetNativeWindow(), GA_ROOT);
352352
result->Success(flutter::EncodableValue(true));
353-
} else if (method_name.compare("waitUntilReadyToShow") == 0) {
353+
}
354+
else if (method_name.compare("getWindowHandle") == 0) {
355+
result->Success(flutter::EncodableValue(reinterpret_cast<__int64>(window_manager->GetMainWindow())));
356+
}
357+
else if (method_name.compare("waitUntilReadyToShow") == 0) {
354358
window_manager->WaitUntilReadyToShow();
355359
result->Success(flutter::EncodableValue(true));
356360
} else if (method_name.compare("setAsFrameless") == 0) {

0 commit comments

Comments
 (0)