我制作了一个简单的表单,可以在最后一个程序图标和第一个系统托盘图标之间的 Windows 任务栏上显示。 这在 Windows 10 中工作正常,但在 Windows 11 中不行
在 Windows 10 和 Windows 11 中可以很好地检索 Shell_TrayWnd 的句柄
知道有什么变化吗?
提前致谢
这是我的代码:
[DllImport("user32.dll")]
public static extern IntPtr GetDesktopWindow();
public FormTaskBar()
{
InitializeComponent();
// List all windows with extended information
List<WindowInformation> lWinExtended = cProcWinList.GetAllWindowsExtendedInfo();
// Search for the taskbar
WindowInformation oTaskInfo = lWinExtended.Find(w => w.Class == "Shell_TrayWnd");
_oTargetWnd = oTaskInfo.Handle;
// Search for the tray icon
_oTrayWnd = oTaskInfo.ChildWindows.Find(x => x.Class == "TrayNotifyWnd").Handle;
cGlobal.oDebug?.Log("Shell_TrayWnd : " + _oTargetWnd);
cGlobal.oDebug?.Log("TrayNotifyWnd : " + _oTrayWnd);
UpdatePositions();
// Attaches the control to the taskbar
SafeNativeMethods.SetParent(Handle, _oTargetWnd);
Show();
这里的问题是 SetParent 并没有按照你想象的那样做。
尝试使用
SetWindowLong(Handle, GWL_HWNDPARENT, _oTargetWnd);