Skip to content

Commit c243222

Browse files
committed
[windows] Implement popUpWindowMenu metnod #141
1 parent 3e1a2dc commit c243222

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

example/lib/pages/home.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,12 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
763763
setState(() {});
764764
},
765765
),
766+
PreferenceListItem(
767+
title: Text('popUpWindowMenu'),
768+
onTap: () async {
769+
await windowManager.popUpWindowMenu();
770+
},
771+
),
766772
PreferenceListItem(
767773
title: Text('createSubWindow'),
768774
onTap: () async {

lib/src/window_manager.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,11 @@ class WindowManager {
646646
await _channel.invokeMethod('setIgnoreMouseEvents', arguments);
647647
}
648648

649+
Future<void> popUpWindowMenu() async {
650+
final Map<String, dynamic> arguments = {};
651+
await _channel.invokeMethod('popUpWindowMenu', arguments);
652+
}
653+
649654
/// Starts a window drag based on the specified mouse-down event.
650655
Future<void> startDragging() async {
651656
await _channel.invokeMethod('startDragging');

windows/window_manager.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class WindowManager {
102102
void WindowManager::SetOpacity(const flutter::EncodableMap& args);
103103
void WindowManager::SetBrightness(const flutter::EncodableMap& args);
104104
void WindowManager::SetIgnoreMouseEvents(const flutter::EncodableMap& args);
105+
void WindowManager::PopUpWindowMenu(const flutter::EncodableMap& args);
105106
void WindowManager::StartDragging();
106107
void WindowManager::StartResizing(const flutter::EncodableMap& args);
107108
flutter::EncodableMap WindowManager::GetPrimaryDisplay(
@@ -704,6 +705,26 @@ void WindowManager::SetIgnoreMouseEvents(const flutter::EncodableMap& args) {
704705
::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style);
705706
}
706707

708+
void WindowManager::PopUpWindowMenu(const flutter::EncodableMap& args) {
709+
HWND hWnd = GetMainWindow();
710+
HMENU hMenu = GetSystemMenu(hWnd, false);
711+
712+
double x, y;
713+
714+
POINT cursorPos;
715+
GetCursorPos(&cursorPos);
716+
x = cursorPos.x;
717+
y = cursorPos.y;
718+
719+
int cmd =
720+
TrackPopupMenu(hMenu, TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_RETURNCMD,
721+
static_cast<int>(x), static_cast<int>(y), 0, hWnd, NULL);
722+
723+
if (cmd) {
724+
PostMessage(hWnd, WM_SYSCOMMAND, cmd, 0);
725+
}
726+
}
727+
707728
void WindowManager::StartDragging() {
708729
ReleaseCapture();
709730
SendMessage(GetMainWindow(), WM_SYSCOMMAND, SC_MOVE | HTCAPTION, 0);

windows/window_manager_plugin.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,11 @@ void WindowManagerPlugin::HandleMethodCall(
496496
std::get<flutter::EncodableMap>(*method_call.arguments());
497497
window_manager->SetIgnoreMouseEvents(args);
498498
result->Success(flutter::EncodableValue(true));
499+
} else if (method_name.compare("popUpWindowMenu") == 0) {
500+
const flutter::EncodableMap& args =
501+
std::get<flutter::EncodableMap>(*method_call.arguments());
502+
window_manager->PopUpWindowMenu(args);
503+
result->Success(flutter::EncodableValue(true));
499504
} else if (method_name.compare("startDragging") == 0) {
500505
window_manager->StartDragging();
501506
result->Success(flutter::EncodableValue(true));

0 commit comments

Comments
 (0)