dsh-gufa-code 1.3.53 → 1.3.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,9 +10,13 @@
10
10
  * 本文件刻意写成单文件(少量小文件),方便在无法本地编译的机器上逐行核对;
11
11
  * WebView2 SDK 头/静态库由 CMake 的 WEBVIEW2_SDK_DIR 提供。
12
12
  *
13
- * 首版说明:窗口为「不透明」窗口(WebView2 windowed hosting 不支持真正的
14
- * 逐像素透明;透明需要 DirectComposition + CompositionController +
15
- * WS_EX_NOREDIRECTIONBITMAP 的 visual hosting,见 README-WIN.md 的 TODO)。
13
+ * 窗口托管两种模式:
14
+ * - composition(默认):DirectComposition + WebView2 CompositionController +
15
+ * WS_EX_NOREDIRECTIONBITMAP 视觉托管,窗口背景透明、可透出下层 App;鼠标输入
16
+ * 由本程序转发给 WebView2(SendMouseInput),顶部 22 DIP 命中 HTCAPTION 拖动。
17
+ * - windowed(回退/payload.opaque=true):ICoreWebView2Controller 窗口托管,
18
+ * 不透明但功能完整;初始化/运行期任一步失败都会自动回退到该模式并写日志
19
+ * transparent-mode=fallback reason=... / transparent-mode=windowed。
16
20
  */
17
21
 
18
22
  #ifndef WIN32_LEAN_AND_MEAN
@@ -24,6 +28,7 @@
24
28
 
25
29
  #include <windows.h>
26
30
  #include <windowsx.h>
31
+ #include <dcomp.h>
27
32
  #include <dwmapi.h>
28
33
  #include <objbase.h>
29
34
  #include <shellapi.h>
@@ -69,6 +74,7 @@ constexpr UINT_PTR kTimerProbeWatchdog = 5;
69
74
  constexpr UINT_PTR kTimerSelftest = 6;
70
75
  constexpr UINT_PTR kTimerPageProbe = 7;
71
76
  constexpr UINT_PTR kTimerRetry = 8;
77
+ constexpr UINT_PTR kTimerControllerWatchdog = 9;
72
78
 
73
79
  constexpr int kMenuExit = 1;
74
80
  constexpr int kMenuResetFrame = 2;
@@ -79,6 +85,7 @@ constexpr int kProbeTimeoutMs = 8000;
79
85
  constexpr int kProbeWatchdogMs = 20000;
80
86
  constexpr int kFollowIntervalMs = 250;
81
87
  constexpr int kControlIntervalMs = 300;
88
+ constexpr int kControllerWatchdogMs = 12000;
82
89
 
83
90
  /* 深色背景(与网页 --gufa-solid-bg 的底色一致) */
84
91
  const COLORREF kBackgroundColor = RGB(13, 15, 19);
@@ -638,6 +645,7 @@ struct FloatPayload {
638
645
  int alpha = 0;
639
646
  DWORD ownerPid = 0;
640
647
  bool ciProbe = false;
648
+ bool opaque = false; // true = 强制 windowed(不透明)模式,调试用
641
649
  };
642
650
 
643
651
  DWORD ReadJsonPid(const gufa::JsonValue* value) {
@@ -698,6 +706,9 @@ bool ParsePayloadJson(const std::wstring& text, FloatPayload* payload, std::wstr
698
706
  const gufa::JsonValue* ciProbe = root.Find(L"ciProbe");
699
707
  if (ciProbe != nullptr && ciProbe->IsBool()) payload->ciProbe = ciProbe->boolean;
700
708
 
709
+ const gufa::JsonValue* opaque = root.Find(L"opaque");
710
+ if (opaque != nullptr && opaque->IsBool()) payload->opaque = opaque->boolean;
711
+
701
712
  return true;
702
713
  }
703
714
 
@@ -894,6 +905,24 @@ HWND FindFollowWindowForProcess(DWORD processId, const std::wstring& title) {
894
905
  return best;
895
906
  }
896
907
 
908
+ /* 悬浮层右键菜单:windowed 模式由拖动条子窗口触发;composition 模式由主窗口
909
+ * 顶部 22px 拖动区的 WM_NCRBUTTONUP 触发。命令统一 PostMessage 给主窗口处理。 */
910
+ void ShowFloatContextMenu(HWND owner) {
911
+ if (owner == nullptr) return;
912
+ HMENU menu = CreatePopupMenu();
913
+ if (menu == nullptr) return;
914
+ AppendMenuW(menu, MF_STRING, kMenuExit, L"退出摸鱼(恢复主窗口)");
915
+ AppendMenuW(menu, MF_STRING, kMenuResetFrame, L"重置窗口位置和大小");
916
+ POINT cursor;
917
+ GetCursorPos(&cursor);
918
+ const int command = static_cast<int>(TrackPopupMenu(
919
+ menu, TPM_RETURNCMD | TPM_RIGHTBUTTON, cursor.x, cursor.y, 0, owner, nullptr));
920
+ DestroyMenu(menu);
921
+ if (command != 0) {
922
+ PostMessageW(owner, kMsgStripMenu, static_cast<WPARAM>(command), 0);
923
+ }
924
+ }
925
+
897
926
  /* ────────────────────────────── 悬浮层窗口 ────────────────────────────── */
898
927
 
899
928
  class FloatApp {
@@ -918,6 +947,7 @@ class FloatApp {
918
947
 
919
948
  private:
920
949
  enum class Phase { Idle, Auth, App, Done };
950
+ enum class HostingMode { Windowed, Composition };
921
951
 
922
952
  static FloatApp* FromWindow(HWND hwnd);
923
953
  static FloatApp* FromStripWindow(HWND stripWindow);
@@ -927,6 +957,16 @@ class FloatApp {
927
957
  LRESULT HandleNcHitTest(HWND hwnd, LPARAM lparam);
928
958
  void HandleMinMaxInfo(MINMAXINFO* info);
929
959
 
960
+ bool CreateHostWindow(const RECT& rect, bool composition);
961
+ bool CreateStripChildWindow();
962
+ bool InitializeDCompDevice(std::wstring* error, HRESULT* errorCode);
963
+ bool CreateDCompVisualTree(std::wstring* error, HRESULT* errorCode);
964
+ void CleanupDCompVisualTree();
965
+ bool FallbackToWindowed(const std::wstring& reason, HRESULT errorCode);
966
+ void ArmRuntimeTimers();
967
+ bool IsDragStripPoint(POINT clientPoint);
968
+ bool OnCompositionMouseMessage(UINT message, WPARAM wparam, LPARAM lparam);
969
+
930
970
  void LayoutChildren();
931
971
  void RaiseStrip();
932
972
  void ResetWindowFrame();
@@ -948,7 +988,11 @@ class FloatApp {
948
988
 
949
989
  void CreateWebViewEnvironment();
950
990
  void OnEnvironmentCreated(HRESULT errorCode, ICoreWebView2Environment* environment);
951
- void OnControllerCreated(HRESULT errorCode, ICoreWebView2Controller* controller);
991
+ void CreateWindowedController();
992
+ void OnWindowedControllerCreated(HRESULT errorCode, ICoreWebView2Controller* controller);
993
+ void OnCompositionControllerCreated(HRESULT errorCode,
994
+ ICoreWebView2CompositionController* controller);
995
+ void FinishControllerSetup();
952
996
  void ConfigureWebView();
953
997
  void StartScriptInjection();
954
998
  void OnScriptRegistered(HRESULT errorCode, LPCWSTR scriptId);
@@ -971,6 +1015,13 @@ class FloatApp {
971
1015
  HWND hwnd_ = nullptr;
972
1016
  HWND strip_ = nullptr;
973
1017
  FloatPayload payload_;
1018
+ HostingMode hostingMode_ = HostingMode::Windowed;
1019
+ ComPtr<IDCompositionDevice> dcompDevice_;
1020
+ ComPtr<IDCompositionTarget> dcompTarget_;
1021
+ ComPtr<IDCompositionVisual> dcompRootVisual_;
1022
+ ComPtr<IDCompositionVisual> dcompWebViewVisual_;
1023
+ ComPtr<ICoreWebView2CompositionController> compositionController_;
1024
+ HCURSOR webViewCursor_ = nullptr;
974
1025
  bool started_ = false;
975
1026
  bool exiting_ = false;
976
1027
  bool controllerReady_ = false;
@@ -992,6 +1043,10 @@ class FloatApp {
992
1043
  RECT lastFollowRect_ = {};
993
1044
  bool hasLastFollowRect_ = false;
994
1045
  HANDLE hostProcess_ = nullptr;
1046
+ bool mouseLeaveTracked_ = false;
1047
+ bool mouseCaptured_ = false;
1048
+ bool suppressWindowDestroy_ = false;
1049
+ bool hideDshDone_ = false;
995
1050
  };
996
1051
 
997
1052
  FloatApp::~FloatApp() {
@@ -1086,22 +1141,9 @@ LRESULT CALLBACK FloatApp::StripWndProc(HWND hwnd, UINT message, WPARAM wparam,
1086
1141
  }
1087
1142
  return 0;
1088
1143
  }
1089
- case WM_RBUTTONUP: {
1090
- HMENU menu = CreatePopupMenu();
1091
- if (menu == nullptr) return 0;
1092
- AppendMenuW(menu, MF_STRING, kMenuExit, L"退出摸鱼(恢复主窗口)");
1093
- AppendMenuW(menu, MF_STRING, kMenuResetFrame, L"重置窗口位置和大小");
1094
- POINT cursor;
1095
- GetCursorPos(&cursor);
1096
- HWND parent = GetParent(hwnd);
1097
- const int command = static_cast<int>(TrackPopupMenu(
1098
- menu, TPM_RETURNCMD | TPM_RIGHTBUTTON, cursor.x, cursor.y, 0, parent, nullptr));
1099
- DestroyMenu(menu);
1100
- if (command != 0 && parent != nullptr) {
1101
- PostMessageW(parent, kMsgStripMenu, static_cast<WPARAM>(command), 0);
1102
- }
1144
+ case WM_RBUTTONUP:
1145
+ ShowFloatContextMenu(GetParent(hwnd));
1103
1146
  return 0;
1104
- }
1105
1147
  case WM_SETCURSOR:
1106
1148
  SetCursor(LoadCursorW(nullptr, IDC_ARROW));
1107
1149
  return TRUE;
@@ -1152,9 +1194,9 @@ bool FloatApp::ParseCommandLine(const std::wstring& jsonText) {
1152
1194
  LogFmt(L"payload-invalid %s", error.c_str());
1153
1195
  return false;
1154
1196
  }
1155
- LogFmt(L"payload-ok ciProbe=%d follow=%d followPid=%lu ownerPid=%lu cookie=%s authUrl=%s "
1156
- L"controlPath=%s build=%s alpha=%d hasState=%d",
1157
- payload_.ciProbe ? 1 : 0, payload_.hasFollow ? 1 : 0,
1197
+ LogFmt(L"payload-ok ciProbe=%d opaque=%d follow=%d followPid=%lu ownerPid=%lu cookie=%s "
1198
+ L"authUrl=%s controlPath=%s build=%s alpha=%d hasState=%d",
1199
+ payload_.ciProbe ? 1 : 0, payload_.opaque ? 1 : 0, payload_.hasFollow ? 1 : 0,
1158
1200
  static_cast<unsigned long>(payload_.followPid),
1159
1201
  static_cast<unsigned long>(payload_.ownerPid),
1160
1202
  payload_.cookie.empty() ? L"no" : L"yes",
@@ -1225,16 +1267,79 @@ bool FloatApp::CreateMainWindow() {
1225
1267
  ClampInitialRect(&initial);
1226
1268
  }
1227
1269
 
1228
- const DWORD extendedStyle = WS_EX_TOPMOST | WS_EX_TOOLWINDOW;
1270
+ // 模式选择:默认尝试 DirectComposition 透明视觉托管;payload.opaque 可强制 windowed。
1271
+ bool useComposition = !payload_.opaque;
1272
+ if (payload_.opaque) {
1273
+ Log(L"transparent-mode=windowed reason=payload-opaque");
1274
+ } else {
1275
+ std::wstring error;
1276
+ HRESULT errorCode = E_FAIL;
1277
+ if (!InitializeDCompDevice(&error, &errorCode)) {
1278
+ LogFmt(L"transparent-mode=fallback reason=%s hr=0x%08lX", error.c_str(),
1279
+ static_cast<unsigned long>(errorCode));
1280
+ Log(L"transparent-mode=windowed");
1281
+ useComposition = false;
1282
+ }
1283
+ }
1284
+
1285
+ if (!CreateHostWindow(initial, useComposition)) {
1286
+ if (!useComposition) return false;
1287
+ Log(L"transparent-mode=fallback reason=create-composition-window-failed");
1288
+ useComposition = false;
1289
+ Log(L"transparent-mode=windowed");
1290
+ if (!CreateHostWindow(initial, false)) return false;
1291
+ }
1292
+
1293
+ if (useComposition) {
1294
+ std::wstring error;
1295
+ HRESULT errorCode = E_FAIL;
1296
+ if (!CreateDCompVisualTree(&error, &errorCode)) {
1297
+ // 窗口已按 composition 样式创建:重建为不透明 windowed 窗口继续。
1298
+ if (!FallbackToWindowed(error, errorCode)) return false;
1299
+ } else {
1300
+ Log(L"transparent-mode=composition");
1301
+ }
1302
+ }
1303
+
1304
+ LayoutChildren();
1305
+
1306
+ if (payload_.ciProbe) {
1307
+ ShowWindow(hwnd_, SW_HIDE);
1308
+ } else {
1309
+ ShowWindow(hwnd_, SW_SHOWNOACTIVATE);
1310
+ UpdateWindow(hwnd_);
1311
+ }
1312
+
1313
+ LogFmt(L"main-window-ready rect=(%ld,%ld)-(%ld,%ld) dpi=%u ciProbe=%d composition=%d",
1314
+ static_cast<long>(initial.left), static_cast<long>(initial.top),
1315
+ static_cast<long>(initial.right), static_cast<long>(initial.bottom),
1316
+ WindowDpi(hwnd_), payload_.ciProbe ? 1 : 0,
1317
+ hostingMode_ == HostingMode::Composition ? 1 : 0);
1318
+ return true;
1319
+ }
1320
+
1321
+ bool FloatApp::CreateHostWindow(const RECT& rect, bool composition) {
1322
+ hostingMode_ = composition ? HostingMode::Composition : HostingMode::Windowed;
1323
+ DWORD extendedStyle = WS_EX_TOPMOST | WS_EX_TOOLWINDOW;
1324
+ if (composition) extendedStyle |= WS_EX_NOREDIRECTIONBITMAP;
1229
1325
  const DWORD style = WS_POPUP | WS_THICKFRAME | WS_CLIPCHILDREN;
1230
- hwnd_ = CreateWindowExW(extendedStyle, kMainWindowClass, kWindowTitle, style, initial.left,
1231
- initial.top, initial.right - initial.left,
1232
- initial.bottom - initial.top, nullptr, nullptr, g_instance, this);
1326
+ hwnd_ = CreateWindowExW(extendedStyle, kMainWindowClass, kWindowTitle, style, rect.left,
1327
+ rect.top, rect.right - rect.left, rect.bottom - rect.top, nullptr,
1328
+ nullptr, g_instance, this);
1233
1329
  if (hwnd_ == nullptr) {
1234
- LogFmt(L"create-main-window-failed err=%lu", static_cast<unsigned long>(GetLastError()));
1330
+ LogFmt(L"create-main-window-failed composition=%d err=%lu", composition ? 1 : 0,
1331
+ static_cast<unsigned long>(GetLastError()));
1235
1332
  return false;
1236
1333
  }
1334
+ LogFmt(L"main-window-created composition=%d rect=(%ld,%ld)-(%ld,%ld) dpi=%u",
1335
+ composition ? 1 : 0, static_cast<long>(rect.left), static_cast<long>(rect.top),
1336
+ static_cast<long>(rect.right), static_cast<long>(rect.bottom), WindowDpi(hwnd_));
1337
+ if (composition) return true;
1338
+ return CreateStripChildWindow();
1339
+ }
1237
1340
 
1341
+ bool FloatApp::CreateStripChildWindow() {
1342
+ if (hwnd_ == nullptr) return false;
1238
1343
  RECT client = {};
1239
1344
  GetClientRect(hwnd_, &client);
1240
1345
  const int stripHeight = DpiScale(hwnd_, kDragStripDip);
@@ -1243,23 +1348,121 @@ bool FloatApp::CreateMainWindow() {
1243
1348
  nullptr);
1244
1349
  if (strip_ == nullptr) {
1245
1350
  LogFmt(L"create-strip-window-failed err=%lu", static_cast<unsigned long>(GetLastError()));
1351
+ return false;
1246
1352
  }
1247
- LayoutChildren();
1353
+ return true;
1354
+ }
1248
1355
 
1249
- if (payload_.ciProbe) {
1250
- ShowWindow(hwnd_, SW_HIDE);
1251
- } else {
1356
+ bool FloatApp::InitializeDCompDevice(std::wstring* error, HRESULT* errorCode) {
1357
+ dcompDevice_.Reset();
1358
+ const HRESULT hr = DCompositionCreateDevice2(
1359
+ nullptr, IID_PPV_ARGS(dcompDevice_.ReleaseAndGetAddressOf()));
1360
+ if (FAILED(hr) || dcompDevice_.Get() == nullptr) {
1361
+ if (error != nullptr) *error = L"dcomp-device hr=0x" + HexHresult(hr);
1362
+ if (errorCode != nullptr) *errorCode = hr;
1363
+ dcompDevice_.Reset();
1364
+ return false;
1365
+ }
1366
+ Log(L"dcomp-device-ready");
1367
+ return true;
1368
+ }
1369
+
1370
+ bool FloatApp::CreateDCompVisualTree(std::wstring* error, HRESULT* errorCode) {
1371
+ auto fail = [error, errorCode](const wchar_t* step, HRESULT hr) {
1372
+ if (error != nullptr) *error = std::wstring(step) + L" hr=0x" + HexHresult(hr);
1373
+ if (errorCode != nullptr) *errorCode = hr;
1374
+ return false;
1375
+ };
1376
+ if (dcompDevice_.Get() == nullptr) return fail(L"dcomp-device-missing", E_FAIL);
1377
+ HRESULT hr = dcompDevice_->CreateTargetForHwnd(hwnd_, TRUE,
1378
+ dcompTarget_.ReleaseAndGetAddressOf());
1379
+ if (FAILED(hr) || dcompTarget_.Get() == nullptr) return fail(L"dcomp-target", hr);
1380
+ hr = dcompDevice_->CreateVisual(dcompRootVisual_.ReleaseAndGetAddressOf());
1381
+ if (FAILED(hr) || dcompRootVisual_.Get() == nullptr) return fail(L"dcomp-root-visual", hr);
1382
+ hr = dcompTarget_->SetRoot(dcompRootVisual_.Get());
1383
+ if (FAILED(hr)) return fail(L"dcomp-set-root", hr);
1384
+ hr = dcompDevice_->CreateVisual(dcompWebViewVisual_.ReleaseAndGetAddressOf());
1385
+ if (FAILED(hr) || dcompWebViewVisual_.Get() == nullptr) return fail(L"dcomp-webview-visual", hr);
1386
+ hr = dcompRootVisual_->AddVisual(dcompWebViewVisual_.Get(), TRUE, nullptr);
1387
+ if (FAILED(hr)) return fail(L"dcomp-add-visual", hr);
1388
+ hr = dcompDevice_->Commit();
1389
+ if (FAILED(hr)) return fail(L"dcomp-commit", hr);
1390
+ Log(L"dcomp-visual-tree-ready");
1391
+ return true;
1392
+ }
1393
+
1394
+ void FloatApp::CleanupDCompVisualTree() {
1395
+ if (compositionController_.Get() != nullptr) {
1396
+ compositionController_->put_RootVisualTarget(nullptr);
1397
+ }
1398
+ if (dcompWebViewVisual_.Get() != nullptr) dcompWebViewVisual_->RemoveAllVisuals();
1399
+ if (dcompRootVisual_.Get() != nullptr) dcompRootVisual_->RemoveAllVisuals();
1400
+ if (dcompTarget_.Get() != nullptr) dcompTarget_->SetRoot(nullptr);
1401
+ if (dcompDevice_.Get() != nullptr) dcompDevice_->Commit();
1402
+ dcompWebViewVisual_.Reset();
1403
+ dcompRootVisual_.Reset();
1404
+ dcompTarget_.Reset();
1405
+ dcompDevice_.Reset();
1406
+ }
1407
+
1408
+ bool FloatApp::FallbackToWindowed(const std::wstring& reason, HRESULT errorCode) {
1409
+ LogFmt(L"transparent-mode=fallback reason=%s hr=0x%08lX", reason.c_str(),
1410
+ static_cast<unsigned long>(errorCode));
1411
+ if (exiting_) return false;
1412
+ if (hostingMode_ == HostingMode::Windowed && hwnd_ != nullptr) return true;
1413
+
1414
+ CleanupDCompVisualTree();
1415
+ compositionController_.Reset();
1416
+ if (controller_.Get() != nullptr) {
1417
+ controller_->Close();
1418
+ controller_.Reset();
1419
+ }
1420
+ webView_.Reset();
1421
+ webViewCursor_ = nullptr;
1422
+
1423
+ RECT rect = {};
1424
+ if (hwnd_ != nullptr && !GetWindowRect(hwnd_, &rect)) {
1425
+ rect = {0, 0, 800, 600};
1426
+ }
1427
+ const bool wasVisible = hwnd_ != nullptr && IsWindowVisible(hwnd_) != FALSE;
1428
+ if (hwnd_ != nullptr) {
1429
+ HWND oldWindow = hwnd_;
1430
+ hwnd_ = nullptr;
1431
+ strip_ = nullptr;
1432
+ suppressWindowDestroy_ = true;
1433
+ DestroyWindow(oldWindow);
1434
+ }
1435
+ if (!CreateHostWindow(rect, false)) {
1436
+ Log(L"fallback-create-windowed-failed");
1437
+ return false;
1438
+ }
1439
+ LayoutChildren();
1440
+ ArmRuntimeTimers();
1441
+ if (wasVisible && !payload_.ciProbe) {
1252
1442
  ShowWindow(hwnd_, SW_SHOWNOACTIVATE);
1253
1443
  UpdateWindow(hwnd_);
1254
1444
  }
1255
-
1256
- LogFmt(L"main-window-created rect=(%ld,%ld)-(%ld,%ld) dpi=%u ciProbe=%d",
1257
- static_cast<long>(initial.left), static_cast<long>(initial.top),
1258
- static_cast<long>(initial.right), static_cast<long>(initial.bottom),
1259
- WindowDpi(hwnd_), payload_.ciProbe ? 1 : 0);
1445
+ Log(L"transparent-mode=windowed");
1260
1446
  return true;
1261
1447
  }
1262
1448
 
1449
+ void FloatApp::ArmRuntimeTimers() {
1450
+ if (hwnd_ == nullptr || !started_) return;
1451
+ if (payload_.ciProbe) {
1452
+ SetTimer(hwnd_, kTimerProbeWatchdog, kProbeWatchdogMs, nullptr);
1453
+ if (!controllerReady_) {
1454
+ SetTimer(hwnd_, kTimerControllerWatchdog, kControllerWatchdogMs, nullptr);
1455
+ }
1456
+ return;
1457
+ }
1458
+ if (!controllerReady_) {
1459
+ SetTimer(hwnd_, kTimerControllerWatchdog, kControllerWatchdogMs, nullptr);
1460
+ }
1461
+ if (payload_.hasFollow) SetTimer(hwnd_, kTimerFollow, kFollowIntervalMs, nullptr);
1462
+ if (!hideDshDone_) SetTimer(hwnd_, kTimerHideDsh, 450, nullptr);
1463
+ SetTimer(hwnd_, kTimerControl, kControlIntervalMs, nullptr);
1464
+ }
1465
+
1263
1466
  void FloatApp::Start() {
1264
1467
  if (started_) return;
1265
1468
  started_ = true;
@@ -1272,13 +1475,9 @@ void FloatApp::Start() {
1272
1475
  followWindow_ = FindFollowWindowForProcess(payload_.followPid, payload_.followTitle);
1273
1476
  }
1274
1477
  if (followWindow_ != nullptr) ForceForeground(followWindow_);
1275
- SetTimer(hwnd_, kTimerFollow, kFollowIntervalMs, nullptr);
1276
1478
  }
1277
- SetTimer(hwnd_, kTimerHideDsh, 450, nullptr);
1278
- SetTimer(hwnd_, kTimerControl, kControlIntervalMs, nullptr);
1279
- } else {
1280
- SetTimer(hwnd_, kTimerProbeWatchdog, kProbeWatchdogMs, nullptr);
1281
1479
  }
1480
+ ArmRuntimeTimers();
1282
1481
  CreateWebViewEnvironment();
1283
1482
  }
1284
1483
 
@@ -1317,6 +1516,19 @@ void FloatApp::LayoutChildren() {
1317
1516
  if (!GetClientRect(hwnd_, &client)) return;
1318
1517
  const int width = client.right - client.left;
1319
1518
  const int height = client.bottom - client.top;
1519
+ if (hostingMode_ == HostingMode::Composition) {
1520
+ // visual hosting:没有子窗口拖动条(拖动条由主窗口顶部 22px 命中 HTCAPTION 实现,
1521
+ // 视觉上由网页 CSS 的 .gufa-overlay-root::before 画半透明条),WebView 铺满客户区。
1522
+ if (strip_ != nullptr) {
1523
+ DestroyWindow(strip_);
1524
+ strip_ = nullptr;
1525
+ }
1526
+ if (controller_.Get() != nullptr) {
1527
+ RECT bounds = {0, 0, width, height};
1528
+ controller_->put_Bounds(bounds);
1529
+ }
1530
+ return;
1531
+ }
1320
1532
  const int border = DpiScale(hwnd_, kResizeBorderDip);
1321
1533
  const int stripHeight = DpiScale(hwnd_, kDragStripDip);
1322
1534
  if (strip_ != nullptr) {
@@ -1340,12 +1552,111 @@ void FloatApp::RaiseStrip() {
1340
1552
  SetWindowPos(strip_, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
1341
1553
  }
1342
1554
 
1555
+ bool FloatApp::IsDragStripPoint(POINT clientPoint) {
1556
+ if (hwnd_ == nullptr) return false;
1557
+ RECT client = {};
1558
+ if (!GetClientRect(hwnd_, &client)) return false;
1559
+ const int stripHeight = DpiScale(hwnd_, kDragStripDip);
1560
+ return clientPoint.y >= 0 && clientPoint.y < stripHeight;
1561
+ }
1562
+
1563
+ /* visual hosting 没有子 HWND:把主窗口收到的鼠标消息转发给 WebView2。 */
1564
+ bool FloatApp::OnCompositionMouseMessage(UINT message, WPARAM wparam, LPARAM lparam) {
1565
+ if (hostingMode_ != HostingMode::Composition || compositionController_.Get() == nullptr) {
1566
+ return false;
1567
+ }
1568
+ POINT point = {};
1569
+ bool hasPoint = true;
1570
+ switch (message) {
1571
+ case WM_MOUSEWHEEL:
1572
+ case WM_MOUSEHWHEEL:
1573
+ point.x = GET_X_LPARAM(lparam);
1574
+ point.y = GET_Y_LPARAM(lparam);
1575
+ ScreenToClient(hwnd_, &point);
1576
+ break;
1577
+ case WM_MOUSELEAVE:
1578
+ hasPoint = false;
1579
+ break;
1580
+ default:
1581
+ point.x = GET_X_LPARAM(lparam);
1582
+ point.y = GET_Y_LPARAM(lparam);
1583
+ break;
1584
+ }
1585
+ if (hasPoint && !mouseCaptured_) {
1586
+ RECT client = {};
1587
+ if (!GetClientRect(hwnd_, &client)) return false;
1588
+ if (!PtInRect(&client, point)) return false;
1589
+ if (IsDragStripPoint(point)) return false; // 顶部拖动条不转发给网页
1590
+ }
1591
+ if (message == WM_MOUSEMOVE) {
1592
+ if (!mouseLeaveTracked_) {
1593
+ TRACKMOUSEEVENT track = {};
1594
+ track.cbSize = sizeof(track);
1595
+ track.dwFlags = TME_LEAVE;
1596
+ track.hwndTrack = hwnd_;
1597
+ if (TrackMouseEvent(&track) != FALSE) mouseLeaveTracked_ = true;
1598
+ }
1599
+ } else if (message == WM_MOUSELEAVE) {
1600
+ mouseLeaveTracked_ = false;
1601
+ }
1602
+
1603
+ UINT32 mouseData = 0;
1604
+ switch (message) {
1605
+ case WM_MOUSEWHEEL:
1606
+ case WM_MOUSEHWHEEL:
1607
+ mouseData = static_cast<UINT32>(GET_WHEEL_DELTA_WPARAM(wparam));
1608
+ break;
1609
+ case WM_XBUTTONDOWN:
1610
+ case WM_XBUTTONUP:
1611
+ case WM_XBUTTONDBLCLK:
1612
+ mouseData = static_cast<UINT32>(GET_XBUTTON_WPARAM(wparam));
1613
+ break;
1614
+ default:
1615
+ break;
1616
+ }
1617
+
1618
+ if (message == WM_LBUTTONDOWN || message == WM_MBUTTONDOWN || message == WM_RBUTTONDOWN ||
1619
+ message == WM_XBUTTONDOWN) {
1620
+ if (!mouseCaptured_) {
1621
+ mouseCaptured_ = true;
1622
+ SetCapture(hwnd_);
1623
+ }
1624
+ } else if (message == WM_LBUTTONUP || message == WM_MBUTTONUP || message == WM_RBUTTONUP ||
1625
+ message == WM_XBUTTONUP) {
1626
+ if (mouseCaptured_) {
1627
+ mouseCaptured_ = false;
1628
+ ReleaseCapture();
1629
+ }
1630
+ }
1631
+
1632
+ const COREWEBVIEW2_MOUSE_EVENT_KIND kind =
1633
+ static_cast<COREWEBVIEW2_MOUSE_EVENT_KIND>(message);
1634
+ const COREWEBVIEW2_MOUSE_EVENT_VIRTUAL_KEYS keys =
1635
+ static_cast<COREWEBVIEW2_MOUSE_EVENT_VIRTUAL_KEYS>(GET_KEYSTATE_WPARAM(wparam));
1636
+ const HRESULT hr = compositionController_->SendMouseInput(kind, keys, mouseData, point);
1637
+ if (FAILED(hr)) {
1638
+ LogFmt(L"send-mouse-input-failed msg=0x%04X hr=0x%08lX", message,
1639
+ static_cast<unsigned long>(hr));
1640
+ return false;
1641
+ }
1642
+ return true;
1643
+ }
1644
+
1343
1645
  LRESULT FloatApp::HandleNcHitTest(HWND hwnd, LPARAM lparam) {
1344
1646
  POINT point;
1345
1647
  point.x = GET_X_LPARAM(lparam);
1346
1648
  point.y = GET_Y_LPARAM(lparam);
1347
1649
  RECT windowRect = {};
1348
1650
  if (!GetWindowRect(hwnd, &windowRect)) return HTCLIENT;
1651
+ if (hostingMode_ == HostingMode::Composition) {
1652
+ POINT clientPoint = point;
1653
+ ScreenToClient(hwnd, &clientPoint);
1654
+ const int stripHeight = DpiScale(hwnd, kDragStripDip);
1655
+ if (clientPoint.y >= 0 && clientPoint.y < stripHeight) {
1656
+ // composition 模式没有子窗口拖动条:顶部 22 DIP 直接作为系统拖动区。
1657
+ return HTCAPTION;
1658
+ }
1659
+ }
1349
1660
  const int border = DpiScale(hwnd, kResizeBorderDip);
1350
1661
  const bool left = point.x < windowRect.left + border;
1351
1662
  const bool right = point.x >= windowRect.right - border;
@@ -1449,8 +1760,21 @@ void FloatApp::OnTimer(UINT_PTR timerId) {
1449
1760
  break;
1450
1761
  case kTimerHideDsh:
1451
1762
  KillTimer(hwnd_, kTimerHideDsh);
1763
+ hideDshDone_ = true;
1452
1764
  OnHideDshTimer();
1453
1765
  break;
1766
+ case kTimerControllerWatchdog:
1767
+ KillTimer(hwnd_, kTimerControllerWatchdog);
1768
+ if (!exiting_ && !controllerReady_) {
1769
+ Log(L"controller-watchdog-timeout");
1770
+ if (hostingMode_ == HostingMode::Composition) {
1771
+ if (FallbackToWindowed(L"composition-controller-timeout",
1772
+ HRESULT_FROM_WIN32(ERROR_TIMEOUT))) {
1773
+ CreateWindowedController();
1774
+ }
1775
+ }
1776
+ }
1777
+ break;
1454
1778
  case kTimerProbeTimeout:
1455
1779
  KillTimer(hwnd_, kTimerProbeTimeout);
1456
1780
  Log(L"ciprobe-timeout");
@@ -1491,6 +1815,7 @@ void FloatApp::KillAllTimers() {
1491
1815
  KillTimer(hwnd_, kTimerSelftest);
1492
1816
  KillTimer(hwnd_, kTimerPageProbe);
1493
1817
  KillTimer(hwnd_, kTimerRetry);
1818
+ KillTimer(hwnd_, kTimerControllerWatchdog);
1494
1819
  }
1495
1820
 
1496
1821
  void FloatApp::OnFollowTimer() {
@@ -1626,8 +1951,9 @@ void FloatApp::CreateWebViewEnvironment() {
1626
1951
  // QueryInterface 降级;这样用户机器上的 Evergreen Runtime 稍旧也能启动,
1627
1952
  // 而不是直接创建失败(默认值等于 SDK 版本 129.x)。
1628
1953
  options->put_TargetCompatibleBrowserVersion(L"86.0.616.0");
1629
- if (payload_.ciProbe) {
1630
- // CI 的 runner 可能没有可用 GPU:强制软件渲染,避免 ciProbe 卡住。
1954
+ if (payload_.ciProbe && payload_.opaque) {
1955
+ // 仅 windowed 调试冒烟强制软件渲染;composition 路径保留默认,
1956
+ // WebView2 在无 GPU 的 runner 上会自行回退 WARP/SwiftShader。
1631
1957
  options->put_AdditionalBrowserArguments(L"--disable-gpu");
1632
1958
  }
1633
1959
  }
@@ -1666,11 +1992,45 @@ void FloatApp::OnEnvironmentCreated(HRESULT errorCode, ICoreWebView2Environment*
1666
1992
  environment_.Attach(environment);
1667
1993
  }
1668
1994
  Log(L"webview2-env-ready");
1995
+ if (hostingMode_ == HostingMode::Composition) {
1996
+ ComPtr<ICoreWebView2Environment3> environment3;
1997
+ const HRESULT queryResult = environment_->QueryInterface(
1998
+ IID_PPV_ARGS(environment3.ReleaseAndGetAddressOf()));
1999
+ if (FAILED(queryResult) || environment3.Get() == nullptr) {
2000
+ LogFmt(L"composition-unavailable hr=0x%08lX", static_cast<unsigned long>(queryResult));
2001
+ if (FallbackToWindowed(L"environment3-unavailable", queryResult)) {
2002
+ CreateWindowedController();
2003
+ }
2004
+ return;
2005
+ }
2006
+ const HRESULT createResult = environment3->CreateCoreWebView2CompositionController(
2007
+ hwnd_,
2008
+ Callback<ICoreWebView2CreateCoreWebView2CompositionControllerCompletedHandler>(
2009
+ [this](HRESULT result,
2010
+ ICoreWebView2CompositionController* compositionController) -> HRESULT {
2011
+ OnCompositionControllerCreated(result, compositionController);
2012
+ return S_OK;
2013
+ })
2014
+ .Get());
2015
+ if (FAILED(createResult)) {
2016
+ LogFmt(L"create-composition-controller-call-failed hr=0x%08lX",
2017
+ static_cast<unsigned long>(createResult));
2018
+ if (FallbackToWindowed(L"composition-controller-call", createResult)) {
2019
+ CreateWindowedController();
2020
+ }
2021
+ }
2022
+ return;
2023
+ }
2024
+ CreateWindowedController();
2025
+ }
2026
+
2027
+ void FloatApp::CreateWindowedController() {
2028
+ if (exiting_ || hwnd_ == nullptr || environment_.Get() == nullptr) return;
1669
2029
  const HRESULT hr = environment_->CreateCoreWebView2Controller(
1670
2030
  hwnd_,
1671
2031
  Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(
1672
2032
  [this](HRESULT controllerError, ICoreWebView2Controller* controller) -> HRESULT {
1673
- OnControllerCreated(controllerError, controller);
2033
+ OnWindowedControllerCreated(controllerError, controller);
1674
2034
  return S_OK;
1675
2035
  })
1676
2036
  .Get());
@@ -1680,8 +2040,13 @@ void FloatApp::OnEnvironmentCreated(HRESULT errorCode, ICoreWebView2Environment*
1680
2040
  }
1681
2041
  }
1682
2042
 
1683
- void FloatApp::OnControllerCreated(HRESULT errorCode, ICoreWebView2Controller* controller) {
2043
+ void FloatApp::OnWindowedControllerCreated(HRESULT errorCode,
2044
+ ICoreWebView2Controller* controller) {
1684
2045
  if (exiting_) return;
2046
+ if (hostingMode_ != HostingMode::Windowed) {
2047
+ Log(L"windowed-controller-late-ignored");
2048
+ return;
2049
+ }
1685
2050
  if (FAILED(errorCode) || controller == nullptr) {
1686
2051
  LogFmt(L"webview2-controller-failed hr=%08lX", static_cast<unsigned long>(errorCode));
1687
2052
  HandleWebViewEnvironmentFailure(errorCode);
@@ -1692,6 +2057,67 @@ void FloatApp::OnControllerCreated(HRESULT errorCode, ICoreWebView2Controller* c
1692
2057
  controller->AddRef();
1693
2058
  controller_.Attach(controller);
1694
2059
  }
2060
+ FinishControllerSetup();
2061
+ }
2062
+
2063
+ void FloatApp::OnCompositionControllerCreated(
2064
+ HRESULT errorCode, ICoreWebView2CompositionController* compositionController) {
2065
+ if (exiting_) return;
2066
+ if (hostingMode_ != HostingMode::Composition) {
2067
+ // 例如 controller 看门狗已回退到 windowed 后,这个迟到的异步回调必须忽略。
2068
+ Log(L"composition-controller-late-ignored");
2069
+ return;
2070
+ }
2071
+ if (FAILED(errorCode) || compositionController == nullptr) {
2072
+ LogFmt(L"webview2-composition-controller-failed hr=0x%08lX",
2073
+ static_cast<unsigned long>(errorCode));
2074
+ if (FallbackToWindowed(L"composition-controller", errorCode)) {
2075
+ CreateWindowedController();
2076
+ }
2077
+ return;
2078
+ }
2079
+ compositionController_.Reset();
2080
+ compositionController->AddRef();
2081
+ compositionController_.Attach(compositionController);
2082
+
2083
+ ComPtr<ICoreWebView2Controller> coreController;
2084
+ const HRESULT queryResult = compositionController_->QueryInterface(
2085
+ IID_PPV_ARGS(coreController.ReleaseAndGetAddressOf()));
2086
+ if (FAILED(queryResult) || coreController.Get() == nullptr) {
2087
+ LogFmt(L"composition-controller-query-failed hr=0x%08lX",
2088
+ static_cast<unsigned long>(queryResult));
2089
+ if (FallbackToWindowed(L"composition-controller-query", queryResult)) {
2090
+ CreateWindowedController();
2091
+ }
2092
+ return;
2093
+ }
2094
+ controller_.Reset();
2095
+ coreController->AddRef();
2096
+ controller_.Attach(coreController.Get());
2097
+
2098
+ if (dcompWebViewVisual_.Get() == nullptr) {
2099
+ Log(L"root-visual-target-missing-visual");
2100
+ if (FallbackToWindowed(L"root-visual-target-missing-visual", E_POINTER)) {
2101
+ CreateWindowedController();
2102
+ }
2103
+ return;
2104
+ }
2105
+ const HRESULT visualResult =
2106
+ compositionController_->put_RootVisualTarget(dcompWebViewVisual_.Get());
2107
+ if (FAILED(visualResult)) {
2108
+ LogFmt(L"root-visual-target-failed hr=0x%08lX", static_cast<unsigned long>(visualResult));
2109
+ if (FallbackToWindowed(L"root-visual-target", visualResult)) {
2110
+ CreateWindowedController();
2111
+ }
2112
+ return;
2113
+ }
2114
+ if (dcompDevice_.Get() != nullptr) dcompDevice_->Commit();
2115
+ Log(L"transparent-mode=composition");
2116
+ FinishControllerSetup();
2117
+ }
2118
+
2119
+ void FloatApp::FinishControllerSetup() {
2120
+ if (exiting_ || controller_.Get() == nullptr) return;
1695
2121
  const HRESULT hr = controller_->get_CoreWebView2(webView_.GetAddressOf());
1696
2122
  if (FAILED(hr) || webView_.Get() == nullptr) {
1697
2123
  LogFmt(L"get-core-webview-failed hr=%08lX", static_cast<unsigned long>(hr));
@@ -1718,14 +2144,52 @@ void FloatApp::ConfigureWebView() {
1718
2144
  if (SUCCEEDED(controller_->QueryInterface(IID_PPV_ARGS(controller2.GetAddressOf()))) &&
1719
2145
  controller2.Get() != nullptr) {
1720
2146
  COREWEBVIEW2_COLOR background;
1721
- background.A = 255;
1722
- background.R = 13;
1723
- background.G = 15;
1724
- background.B = 19;
2147
+ if (hostingMode_ == HostingMode::Composition) {
2148
+ // 视觉托管:WebView 背景全透明,才可能透出 DComp 目标后面的桌面/下层窗口。
2149
+ background.A = 0;
2150
+ background.R = 0;
2151
+ background.G = 0;
2152
+ background.B = 0;
2153
+ } else {
2154
+ // windowed hosting 不支持逐像素透明:用与网页一致的深色不透明底。
2155
+ background.A = 255;
2156
+ background.R = 13;
2157
+ background.G = 15;
2158
+ background.B = 19;
2159
+ }
1725
2160
  controller2->put_DefaultBackgroundColor(background);
1726
2161
  }
1727
2162
  controller_->put_IsVisible(TRUE);
1728
2163
 
2164
+ if (hostingMode_ == HostingMode::Composition) {
2165
+ if (webViewCursor_ == nullptr) webViewCursor_ = LoadCursorW(nullptr, IDC_ARROW);
2166
+ EventRegistrationToken cursorToken = {};
2167
+ if (compositionController_.Get() != nullptr) {
2168
+ compositionController_->add_CursorChanged(
2169
+ Callback<ICoreWebView2CursorChangedEventHandler>(
2170
+ [this](ICoreWebView2CompositionController* sender, IUnknown* args) -> HRESULT {
2171
+ (void)args;
2172
+ if (sender == nullptr || hwnd_ == nullptr) return S_OK;
2173
+ HCURSOR cursor = nullptr;
2174
+ if (SUCCEEDED(sender->get_Cursor(&cursor)) && cursor != nullptr) {
2175
+ webViewCursor_ = cursor;
2176
+ POINT point = {};
2177
+ if (GetCursorPos(&point)) {
2178
+ ScreenToClient(hwnd_, &point);
2179
+ RECT client = {};
2180
+ if (GetClientRect(hwnd_, &client) && PtInRect(&client, point) &&
2181
+ !IsDragStripPoint(point)) {
2182
+ SetCursor(cursor);
2183
+ }
2184
+ }
2185
+ }
2186
+ return S_OK;
2187
+ })
2188
+ .Get(),
2189
+ &cursorToken);
2190
+ }
2191
+ }
2192
+
1729
2193
  EventRegistrationToken token = {};
1730
2194
  webView_->add_NavigationCompleted(
1731
2195
  Callback<ICoreWebView2NavigationCompletedEventHandler>(
@@ -1996,6 +2460,9 @@ void FloatApp::HandleWebViewEnvironmentFailure(HRESULT errorCode) {
1996
2460
  }
1997
2461
 
1998
2462
  void FloatApp::CleanupWebView() {
2463
+ CleanupDCompVisualTree(); // 内含 compositionController_->put_RootVisualTarget(nullptr)
2464
+ compositionController_.Reset();
2465
+ webViewCursor_ = nullptr;
1999
2466
  if (webView_.Get() != nullptr) webView_.Reset();
2000
2467
  if (controller_.Get() != nullptr) {
2001
2468
  controller_->put_IsVisible(FALSE);
@@ -2028,6 +2495,10 @@ void FloatApp::DoGracefulExit() {
2028
2495
 
2029
2496
  void FloatApp::OnWindowDestroyed() {
2030
2497
  KillAllTimers();
2498
+ if (mouseCaptured_) {
2499
+ mouseCaptured_ = false;
2500
+ ReleaseCapture();
2501
+ }
2031
2502
  CleanupWebView();
2032
2503
  strip_ = nullptr; // 子窗口随父窗口一起销毁
2033
2504
  hwnd_ = nullptr;
@@ -2044,6 +2515,63 @@ LRESULT FloatApp::OnMainMessage(HWND hwnd, UINT message, WPARAM wparam, LPARAM l
2044
2515
  case WM_GETMINMAXINFO:
2045
2516
  HandleMinMaxInfo(reinterpret_cast<MINMAXINFO*>(lparam));
2046
2517
  return 0;
2518
+ case WM_ERASEBKGND:
2519
+ if (hostingMode_ == HostingMode::Composition) return 1; // 不画背景,透出下层
2520
+ return DefWindowProcW(hwnd, message, wparam, lparam);
2521
+ case WM_PAINT:
2522
+ if (hostingMode_ == HostingMode::Composition) {
2523
+ PAINTSTRUCT paint = {};
2524
+ BeginPaint(hwnd, &paint);
2525
+ EndPaint(hwnd, &paint);
2526
+ return 0;
2527
+ }
2528
+ return DefWindowProcW(hwnd, message, wparam, lparam);
2529
+ case WM_NCRBUTTONUP:
2530
+ if (hostingMode_ == HostingMode::Composition) {
2531
+ ShowFloatContextMenu(hwnd);
2532
+ return 0;
2533
+ }
2534
+ return DefWindowProcW(hwnd, message, wparam, lparam);
2535
+ case WM_SETCURSOR:
2536
+ if (hostingMode_ == HostingMode::Composition && LOWORD(lparam) == HTCLIENT) {
2537
+ SetCursor(webViewCursor_ != nullptr ? webViewCursor_ : LoadCursorW(nullptr, IDC_ARROW));
2538
+ return TRUE;
2539
+ }
2540
+ return DefWindowProcW(hwnd, message, wparam, lparam);
2541
+ case WM_ACTIVATE:
2542
+ if (hostingMode_ == HostingMode::Composition && LOWORD(wparam) != WA_INACTIVE &&
2543
+ controller_.Get() != nullptr) {
2544
+ controller_->MoveFocus(COREWEBVIEW2_MOVE_FOCUS_REASON_PROGRAMMATIC);
2545
+ }
2546
+ return DefWindowProcW(hwnd, message, wparam, lparam);
2547
+ case WM_SETFOCUS:
2548
+ if (hostingMode_ == HostingMode::Composition && controller_.Get() != nullptr) {
2549
+ controller_->MoveFocus(COREWEBVIEW2_MOVE_FOCUS_REASON_PROGRAMMATIC);
2550
+ }
2551
+ return DefWindowProcW(hwnd, message, wparam, lparam);
2552
+ case WM_CAPTURECHANGED:
2553
+ mouseCaptured_ = false;
2554
+ return DefWindowProcW(hwnd, message, wparam, lparam);
2555
+ case WM_MOUSEMOVE:
2556
+ case WM_LBUTTONDOWN:
2557
+ case WM_LBUTTONUP:
2558
+ case WM_LBUTTONDBLCLK:
2559
+ case WM_RBUTTONDOWN:
2560
+ case WM_RBUTTONUP:
2561
+ case WM_RBUTTONDBLCLK:
2562
+ case WM_MBUTTONDOWN:
2563
+ case WM_MBUTTONUP:
2564
+ case WM_MBUTTONDBLCLK:
2565
+ case WM_XBUTTONDOWN:
2566
+ case WM_XBUTTONUP:
2567
+ case WM_XBUTTONDBLCLK:
2568
+ case WM_MOUSEWHEEL:
2569
+ case WM_MOUSEHWHEEL:
2570
+ case WM_MOUSELEAVE:
2571
+ if (hostingMode_ == HostingMode::Composition) {
2572
+ if (OnCompositionMouseMessage(message, wparam, lparam)) return 0;
2573
+ }
2574
+ return DefWindowProcW(hwnd, message, wparam, lparam);
2047
2575
  case WM_SIZE:
2048
2576
  LayoutChildren();
2049
2577
  return 0;
@@ -2089,6 +2617,11 @@ LRESULT FloatApp::OnMainMessage(HWND hwnd, UINT message, WPARAM wparam, LPARAM l
2089
2617
  if (wparam != 0) RestoreDshWindows();
2090
2618
  return 0;
2091
2619
  case WM_DESTROY:
2620
+ if (suppressWindowDestroy_) {
2621
+ // 模式回退时重建窗口:旧窗口销毁不代表进程退出,不能 PostQuitMessage。
2622
+ suppressWindowDestroy_ = false;
2623
+ return 0;
2624
+ }
2092
2625
  OnWindowDestroyed();
2093
2626
  return 0;
2094
2627
  default: