跳至主要內容

FlutterEngine::ProcessExternalWindowMessage 介紹

摘要

#

當您將任何外部視窗新增至 Flutter 應用程式時,您需要將它們包含在視窗的應用程式生命週期邏輯中。若要包含視窗,其 WndProc 函式應調用 FlutterEngine::ProcessExternalWindowMessage

受影響的對象

#

針對 Flutter 3.13 或更新版本建置且開啟非 Flutter 視窗的 Windows 應用程式。

變更說明

#

在 Windows 上實作應用程式生命週期,需要監聽視窗訊息以更新生命週期狀態。為了讓額外的非 Flutter 視窗影響生命週期狀態,它們必須從其 WndProc 函數將視窗訊息轉發至 FlutterEngine::ProcessExternalWindowMessage。此函數會回傳一個 std::optional<LRESULT>,當訊息被接收但未被消耗時,該值為 std::nullopt。當回傳的結果有值時,表示訊息已被消耗,WndProc 中的後續處理應該停止。

移轉指南

#

以下範例 WndProc 程序會調用 FlutterEngine::ProcessExternalWindowMessage

cpp
LRESULT Window::Messagehandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
    std::optional<LRESULT> result = flutter_controller_->engine()->ProcessExternalWindowMessage(hwnd, msg, wparam, lparam);
    if (result.has_value()) {
        return *result;
    }
    // Original contents of WndProc...
}

時程表

#

在版本中引入:3.14.0-3.0.pre
在穩定版本中:3.16

參考

#

相關 PRs