1.效果
当按下Win+D是,桌面干净了,只剩下了这个贴在桌面的。。。
2.用法
#ifdef Q_OS_WIN#include "CWindows.h"#endif伪代码{QLabel *pLabel = new QLabel();pLabel->setText("hello desktop");pLabel->setGeometry(20,20,200,30);setParentDesktop(pLabel);}
2.代码
头文件
#ifndef CWINDOWS_H#define CWINDOWS_H#include <QWidget>#ifdef Q_OS_WIN#include "windows.h"bool enumUserWindowsCB(HWND hwnd, LPARAM lParam);void setParentDesktop(QWidget *pWidget);#endif //Q_OS_WIN#endif // CWINDOWS_H
源文件
#include "CWindows.h"#ifdef Q_OS_WIN//#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;}void setParentDesktop(QWidget *pWidget){HWND resultHwnd = NULL;EnumWindows((WNDENUMPROC)enumUserWindowsCB, (LPARAM)&resultHwnd);// 设置桌面为父窗口if (resultHwnd) {SetParent((HWND)pWidget->winId(), resultHwnd);}}#endif