https://blog.csdn.net/qq_41673920/article/details/108121387
https://blog.51cto.com/mypyg/263349
先 LIBS+=-luser32
#include <Windows.h>
bool enumUserWindowsCB(HWND hwnd, LPARAM lParam)
{
long wflags = GetWindowLong(hwnd, GWL_STYLE);
if (!(wflags & WS_VISIBLE)) {
return TRUE;
};
HWND sndWnd;
if (!(sndWnd=FindWindowEx(hwnd, NULL, L"SHELLDLL_DefView", NULL))) {
return TRUE;
}
HWND targetWnd;
if (!(targetWnd=FindWindowEx(sndWnd, NULL, L"SysListView32", L"FolderView"))) {
return TRUE;
}
HWND* resultHwnd = (HWND*)lParam;
*resultHwnd = targetWnd;
return FALSE;
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
HWND resultHwnd = NULL;
EnumWindows((WNDENUMPROC)enumUserWindowsCB, (LPARAM)&resultHwnd);
HWND desktopHwnd = resultHwnd; //findDesktopIconWnd();
if(desktopHwnd)
SetParent((HWND)this->winId(), desktopHwnd);
}