Skip to content

Commit

Permalink
[windows] Implement popUpWindowMenu metnod #141
Browse files Browse the repository at this point in the history
  • Loading branch information
lijy91 committed May 5, 2022
1 parent 3e1a2dc commit c243222
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions example/lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,12 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
setState(() {});
},
),
PreferenceListItem(
title: Text('popUpWindowMenu'),
onTap: () async {
await windowManager.popUpWindowMenu();
},
),
PreferenceListItem(
title: Text('createSubWindow'),
onTap: () async {
Expand Down
5 changes: 5 additions & 0 deletions lib/src/window_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,11 @@ class WindowManager {
await _channel.invokeMethod('setIgnoreMouseEvents', arguments);
}

Future<void> popUpWindowMenu() async {
final Map<String, dynamic> arguments = {};
await _channel.invokeMethod('popUpWindowMenu', arguments);
}

/// Starts a window drag based on the specified mouse-down event.
Future<void> startDragging() async {
await _channel.invokeMethod('startDragging');
Expand Down
21 changes: 21 additions & 0 deletions windows/window_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class WindowManager {
void WindowManager::SetOpacity(const flutter::EncodableMap& args);
void WindowManager::SetBrightness(const flutter::EncodableMap& args);
void WindowManager::SetIgnoreMouseEvents(const flutter::EncodableMap& args);
void WindowManager::PopUpWindowMenu(const flutter::EncodableMap& args);
void WindowManager::StartDragging();
void WindowManager::StartResizing(const flutter::EncodableMap& args);
flutter::EncodableMap WindowManager::GetPrimaryDisplay(
Expand Down Expand Up @@ -704,6 +705,26 @@ void WindowManager::SetIgnoreMouseEvents(const flutter::EncodableMap& args) {
::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style);
}

void WindowManager::PopUpWindowMenu(const flutter::EncodableMap& args) {
HWND hWnd = GetMainWindow();
HMENU hMenu = GetSystemMenu(hWnd, false);

double x, y;

POINT cursorPos;
GetCursorPos(&cursorPos);
x = cursorPos.x;
y = cursorPos.y;

int cmd =
TrackPopupMenu(hMenu, TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_RETURNCMD,
static_cast<int>(x), static_cast<int>(y), 0, hWnd, NULL);

if (cmd) {
PostMessage(hWnd, WM_SYSCOMMAND, cmd, 0);
}
}

void WindowManager::StartDragging() {
ReleaseCapture();
SendMessage(GetMainWindow(), WM_SYSCOMMAND, SC_MOVE | HTCAPTION, 0);
Expand Down
5 changes: 5 additions & 0 deletions windows/window_manager_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,11 @@ void WindowManagerPlugin::HandleMethodCall(
std::get<flutter::EncodableMap>(*method_call.arguments());
window_manager->SetIgnoreMouseEvents(args);
result->Success(flutter::EncodableValue(true));
} else if (method_name.compare("popUpWindowMenu") == 0) {
const flutter::EncodableMap& args =
std::get<flutter::EncodableMap>(*method_call.arguments());
window_manager->PopUpWindowMenu(args);
result->Success(flutter::EncodableValue(true));
} else if (method_name.compare("startDragging") == 0) {
window_manager->StartDragging();
result->Success(flutter::EncodableValue(true));
Expand Down

0 comments on commit c243222

Please sign in to comment.