// #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #pragma comment(lib, "dwmapi.lib") // #pragma comment(lib, "user32.lib") // class ThumbnailWidget : public QOpenGLWidget, protected QOpenGLFunctions // { // Q_OBJECT // public: // ThumbnailWidget(QWidget *parent = nullptr) // : QOpenGLWidget(parent) // { // setFixedSize(800, 600); // 固定预览区域大小 // updateTimer = new QTimer(this); // connect(updateTimer, &QTimer::timeout, this, &ThumbnailWidget::updateThumbnails); // updateTimer->start(200); // 每200ms更新一次 // } // ~ThumbnailWidget() // { // makeCurrent(); // for (auto texture : textures) { // delete texture; // } // textures.clear(); // doneCurrent(); // } // protected: // void initializeGL() override // { // initializeOpenGLFunctions(); // glClearColor(0.1f, 0.1f, 0.1f, 1.0f); // } // void resizeGL(int w, int h) override { glViewport(0, 0, w, h); } // void paintGL() override // { // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // glEnable(GL_TEXTURE_2D); // glEnable(GL_BLEND); // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // int cols = 4; // 每行4个缩略图 // int thumbSize = width() / cols; // 保持1:1比例 // int row = 0, col = 0; // for (auto texture : textures) { // if (!texture) // continue; // texture->bind(); // glBegin(GL_QUADS); // int x = col * thumbSize; // int y = row * thumbSize; // glTexCoord2f(0, 0); // glVertex2f(x, y); // glTexCoord2f(1, 0); // glVertex2f(x + thumbSize, y); // glTexCoord2f(1, 1); // glVertex2f(x + thumbSize, y + thumbSize); // glTexCoord2f(0, 1); // glVertex2f(x, y + thumbSize); // glEnd(); // if (++col >= cols) { // col = 0; // row++; // } // } // } // private slots: // void updateThumbnails() // { // // 清理旧纹理 // makeCurrent(); // for (auto texture : textures) { // delete texture; // } // textures.clear(); // // 获取所有窗口 // EnumWindows(enumWindowsProc, reinterpret_cast(this)); // // 添加桌面预览 // addDesktopThumbnail(); // update(); // } // private: // QTimer *updateTimer; // QVector textures; // static BOOL CALLBACK enumWindowsProc(HWND hwnd, LPARAM lParam) // { // if (!IsWindowVisible(hwnd)) // return TRUE; // ThumbnailWidget *widget = reinterpret_cast(lParam); // widget->addWindowThumbnail(hwnd); // return TRUE; // } // void addWindowThumbnail(HWND hwnd) // { // RECT rect; // GetClientRect(hwnd, &rect); // int width = rect.right - rect.left; // int height = rect.bottom - rect.top; // if (width == 0 || height == 0) // return; // // 创建临时纹理 // QImage image(width, height, QImage::Format_ARGB32); // HDC hdcScreen = GetDC(NULL); // HDC hdcMem = CreateCompatibleDC(hdcScreen); // HBITMAP hbm = CreateCompatibleBitmap(hdcScreen, width, height); // SelectObject(hdcMem, hbm); // // 打印窗口内容到内存DC // PrintWindow(hwnd, hdcMem, PW_CLIENTONLY); // // 从HBITMAP获取数据 // BITMAPINFO bmi = {0}; // bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); // bmi.bmiHeader.biWidth = width; // bmi.bmiHeader.biHeight = -height; // 从上到下 // bmi.bmiHeader.biPlanes = 1; // bmi.bmiHeader.biBitCount = 32; // bmi.bmiHeader.biCompression = BI_RGB; // GetDIBits(hdcMem, hbm, 0, height, image.bits(), &bmi, DIB_RGB_COLORS); // // 创建OpenGL纹理 // makeCurrent(); // QOpenGLTexture *texture = new QOpenGLTexture(image.mirrored()); // texture->setMinificationFilter(QOpenGLTexture::Linear); // texture->setMagnificationFilter(QOpenGLTexture::Linear); // textures.append(texture); // // 清理资源 // DeleteObject(hbm); // DeleteDC(hdcMem); // ReleaseDC(NULL, hdcScreen); // } // void addDesktopThumbnail() // { // QScreen *screen = QApplication::primaryScreen(); // QPixmap desktopPix = screen->grabWindow(0); // QImage image = desktopPix.toImage(); // makeCurrent(); // QOpenGLTexture *texture = new QOpenGLTexture(image); // texture->setMinificationFilter(QOpenGLTexture::Linear); // texture->setMagnificationFilter(QOpenGLTexture::Linear); // textures.prepend(texture); // 桌面放在第一个 // } // }; // int main(int argc, char *argv[]) // { // QApplication app(argc, argv); // ThumbnailWidget widget; // widget.setWindowTitle("Window Thumbnail Preview"); // widget.show(); // return app.exec(); // } // #include "main_simple.moc"