版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/daoer_sofu/article/details/103257899
使用spy++获取窗口层级关系
使用C#代码调用windows api接口,调试模式下设置窗口parnet会失败
private void SetBackgroundWindowWorkerW()
{
Win32Methods.EnumWindows(new Win32Methods.EnumWindowsProc((h, l) => {
int winClassCount = 0;
IntPtr winClassPt = Marshal.AllocHGlobal(512);
if (Win32Methods.GetClassName(h, winClassPt, out winClassCount) != 0)
{
string winClass = Marshal.PtrToStringAnsi(winClassPt);
if (Win32Methods.IsWindowVisible(h) && winClass == "WorkerW")
{
//System.Windows.MessageBox.Show("ok");
long wStyle = Win32Methods.GetWindowLong(_mainHandle, -16);
Win32Methods.SetWindowLong(_mainHandle, -16, 0x40000000L | wStyle);
wStyle = Win32Methods.GetWindowLong(_mainHandle, -16);
Win32Methods.SetParent(_mainHandle, h);
Win32Methods.SetWindowPos(_mainHandle, new IntPtr(0), 0, 0, 0, 0, 0x0002 | 0x0001);
return false;
}
else
{
return true;
}
}
Marshal.FreeHGlobal(winClassPt);
return true;
}), 0);
}
shelldll_defview => syslistview32(FolderView)窗口 int count = (int)SendMessage(desktophwnd, LVM_GETITEMCOUNT, (WPARAM)0, (LPARAM)0);
GetShellWindow 获取shelldll_defview窗口
参考:https://blog.csdn.net/f919974096/article/details/89479630 https://zhuanlan.zhihu.com/p/37877070(过渡窗口workerw的讲解)
github:https://github.com/NoisyWinds/Wallpaper.git