// #include "screenwall_widget.h" // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include "qfileinfo.h" // #include // #include // #include // #pragma comment(lib, "dwmapi.lib") // #pragma comment(lib, "shell32.lib") // #pragma comment(lib, "psapi.lib") // // ============================================================================ // // ScreenWallWidget Implementation // // ============================================================================ // ScreenWallWidget::ScreenWallWidget(QWidget* parent) // : QWidget(parent) // , m_mainLayout(nullptr) // , m_desktopPreview(nullptr) // , m_windowList(nullptr) // , m_windowPreview(nullptr) // , m_updateTimer(new QTimer(this)) // , m_performanceTimer(new QTimer(this)) // , m_isRunning(false) // , m_selectedWindow(nullptr) // , m_activeCaptureCount(0) // { // setupUI(); // setupConnections(); // // 设置默认配置 // m_config = ScreenWallConfig(); // setMinimumSize(800, 600); // resize(1200, 900); // } // ScreenWallWidget::~ScreenWallWidget() // { // stopScreenWall(); // cleanupResources(); // } // void ScreenWallWidget::setupUI() // { // m_mainLayout = new QVBoxLayout(this); // m_mainLayout->setContentsMargins(5, 5, 5, 5); // m_mainLayout->setSpacing(5); // // 桌面预览区域 (30%) // m_desktopPreview = new DesktopPreviewWidget(this); // m_desktopPreview->setMinimumHeight(200); // m_desktopPreview->setStyleSheet("border: 2px solid #3498db; border-radius: 5px;"); // m_mainLayout->addWidget(m_desktopPreview, 3); // // 窗口图标列表 (20%) // m_windowList = new WindowIconListWidget(this); // m_windowList->setMaximumHeight(180); // m_windowList->setMinimumHeight(120); // m_windowList->setStyleSheet("border: 1px solid #bdc3c7; border-radius: 3px;"); // m_mainLayout->addWidget(m_windowList, 2); // // 窗口预览区域 (50%) // m_windowPreview = new WindowPreviewWidget(this); // m_windowPreview->setMinimumHeight(300); // m_windowPreview->setStyleSheet("border: 2px solid #e74c3c; border-radius: 5px;"); // m_mainLayout->addWidget(m_windowPreview, 5); // } // void ScreenWallWidget::setupConnections() // { // // 桌面预览点击 // connect(m_desktopPreview, &DesktopPreviewWidget::clicked, // this, &ScreenWallWidget::onDesktopClicked); // // 窗口选择 // connect(m_windowList, &WindowIconListWidget::windowSelected, // this, &ScreenWallWidget::onWindowSelected); // // 定时更新 // connect(m_updateTimer, &QTimer::timeout, // this, &ScreenWallWidget::updatePreviews); // // 性能优化定时器 // connect(m_performanceTimer, &QTimer::timeout, // this, &ScreenWallWidget::optimizePerformance); // } // void ScreenWallWidget::setConfig(const ScreenWallConfig& config) // { // m_config = config; // if (m_windowList) { // m_windowList->setThumbnailSize(config.thumbnailSize); // } // if (m_updateTimer) { // m_updateTimer->setInterval(config.updateInterval); // } // } // void ScreenWallWidget::startScreenWall() // { // if (m_isRunning) { // return; // } // qDebug() << "Starting ScreenWall..."; // // 启动桌面预览 // m_desktopPreview->startDesktopCapture(m_config.desktopFrameRate); // // 刷新窗口列表 // refreshWindowList(); // // 启动定时器 // m_updateTimer->start(m_config.updateInterval); // m_performanceTimer->start(5000); // 每5秒优化一次性能 // m_isRunning = true; // qDebug() << "ScreenWall started successfully"; // } // void ScreenWallWidget::stopScreenWall() // { // if (!m_isRunning) { // return; // } // qDebug() << "Stopping ScreenWall..."; // // 停止定时器 // m_updateTimer->stop(); // m_performanceTimer->stop(); // // 停止预览 // m_desktopPreview->stopDesktopCapture(); // m_windowPreview->stopPreview(); // // 清理资源 // ResourceManager::instance().cleanup(); // m_isRunning = false; // m_selectedWindow = nullptr; // qDebug() << "ScreenWall stopped"; // } // void ScreenWallWidget::refreshWindowList() // { // if (m_windowList) { // m_windowList->refreshWindowList(); // } // } // void ScreenWallWidget::onWindowSelected(HWND hwnd) // { // if (m_selectedWindow == hwnd) { // return; // } // // 停止之前的预览 // if (m_selectedWindow) { // m_windowPreview->stopPreview(); // ResourceManager::instance().removeCaptureSession(m_selectedWindow); // } // m_selectedWindow = hwnd; // if (hwnd && IsWindow(hwnd)) { // // 检查是否可以开始新的捕获 // if (ResourceManager::instance().canStartCapture()) { // m_windowPreview->setTargetWindow(hwnd); // m_windowPreview->startPreview(m_config.windowFrameRate); // ResourceManager::instance().addCaptureSession(hwnd); // // 获取窗口标题 // wchar_t title[256]; // GetWindowTextW(hwnd, title, 256); // QString windowTitle = QString::fromWCharArray(title); // emit windowSelected(hwnd, windowTitle); // } else { // QMessageBox::warning(this, "资源限制", // "已达到最大同时捕获数量限制,请先关闭其他预览。"); // } // } // } // void ScreenWallWidget::onDesktopClicked() // { // // 取消窗口选择,显示桌面 // if (m_selectedWindow) { // m_windowPreview->stopPreview(); // ResourceManager::instance().removeCaptureSession(m_selectedWindow); // m_selectedWindow = nullptr; // } // emit desktopSelected(); // } // void ScreenWallWidget::updatePreviews() // { // // 刷新窗口列表 // refreshWindowList(); // // 检查选中窗口是否仍然有效 // if (m_selectedWindow && !IsWindow(m_selectedWindow)) { // onWindowSelected(nullptr); // } // } // void ScreenWallWidget::optimizePerformance() // { // // 根据窗口状态调整帧率 // if (m_selectedWindow && IsWindow(m_selectedWindow)) { // bool isMinimized = IsIconic(m_selectedWindow); // bool isVisible = IsWindowVisible(m_selectedWindow); // int frameRate = m_config.windowFrameRate; // if (isMinimized) { // frameRate = 1; // 最小化窗口使用极低帧率 // } else if (!isVisible) { // frameRate = 5; // 不可见窗口使用低帧率 // } // // 这里可以调整捕获帧率(需要在VideoRecorder中实现) // // m_windowPreview->setFrameRate(frameRate); // } // } // void ScreenWallWidget::resizeEvent(QResizeEvent* event) // { // QWidget::resizeEvent(event); // // 调整窗口列表布局 // if (m_windowList) { // QTimer::singleShot(100, m_windowList, &WindowIconListWidget::refreshWindowList); // } // } // void ScreenWallWidget::showEvent(QShowEvent* event) // { // QWidget::showEvent(event); // if (!m_isRunning) { // QTimer::singleShot(500, this, &ScreenWallWidget::startScreenWall); // } // } // void ScreenWallWidget::hideEvent(QHideEvent* event) // { // QWidget::hideEvent(event); // if (m_isRunning) { // stopScreenWall(); // } // } // void ScreenWallWidget::cleanupResources() // { // ResourceManager::instance().cleanup(); // } // // ============================================================================ // // DesktopPreviewWidget Implementation // // ============================================================================ // DesktopPreviewWidget::DesktopPreviewWidget(QWidget* parent) // : OpenGLVideoWidget(parent) // , m_captureTimer(new QTimer(this)) // , m_isCapturing(false) // , m_monitorIndex(0) // { // // connect(m_captureTimer, &QTimer::timeout, // // this, &DesktopPreviewWidget::captureDesktop); // // setNoVideoTip("点击开始桌面预览"); // setCursor(Qt::PointingHandCursor); // } // DesktopPreviewWidget::~DesktopPreviewWidget() // { // stopDesktopCapture(); // } // void DesktopPreviewWidget::startDesktopCapture(int frameRate) // { // if (m_isCapturing) { // return; // } // qDebug() << "Starting desktop capture at" << frameRate << "fps"; // // 使用主显示器 // Encoder::Param videoParam; // videoParam.width = GetSystemMetrics(SM_CXSCREEN); // videoParam.height = GetSystemMetrics(SM_CYSCREEN); // videoParam.fps = frameRate; // if (m_desktopRecorder.Open(m_monitorIndex, videoParam, CaptureMethod::WGC)) { // m_captureTimer->start(1000 / frameRate); // m_isCapturing = true; // setNoVideoTip(""); // } else { // qWarning() << "Failed to start desktop capture"; // setNoVideoTip("桌面捕获失败"); // } // } // void ScreenWallWidget::onWindowStateChanged() // { // // 处理窗口状态变化 // updatePreviews(); // } // void DesktopPreviewWidget::stopDesktopCapture() // { // if (!m_isCapturing) { // return; // } // qDebug() << "Stopping desktop capture"; // m_captureTimer->stop(); // m_desktopRecorder.Close(); // m_isCapturing = false; // setNoVideoTip("桌面预览已停止"); // } // void DesktopPreviewWidget::captureDesktop() // { // if (!m_isCapturing) { // return; // } // AVFrame* frame = m_desktopRecorder.GetRenderFrame(); // if (frame) { // // 异步渲染帧 // QMetaObject::invokeMethod(this, "Render", Qt::QueuedConnection, // Q_ARG(AVFrame*, av_frame_clone(frame))); // } // } // void DesktopPreviewWidget::mousePressEvent(QMouseEvent* event) // { // if (event->button() == Qt::LeftButton) { // emit clicked(); // } // OpenGLVideoWidget::mousePressEvent(event); // } // void DesktopPreviewWidget::paintEvent(QPaintEvent* event) // { // OpenGLVideoWidget::paintEvent(event); // // 绘制边框和状态信息 // QPainter painter(this); // painter.setRenderHint(QPainter::Antialiasing); // if (m_isCapturing) { // // 绘制录制指示器 // painter.setPen(QPen(Qt::red, 2)); // painter.setBrush(Qt::red); // painter.drawEllipse(width() - 20, 10, 10, 10); // painter.setPen(Qt::white); // painter.drawText(width() - 60, 25, "LIVE"); // } // } // // ============================================================================ // // WindowIconListWidget Implementation // // ============================================================================ // WindowIconListWidget::WindowIconListWidget(QWidget* parent) // : QScrollArea(parent) // , m_contentWidget(new QWidget) // , m_layout(new QGridLayout(m_contentWidget)) // , m_thumbnailSize(120, 90) // , m_columnsCount(6) // { // setWidget(m_contentWidget); // setWidgetResizable(true); // setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); // setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); // m_layout->setSpacing(5); // m_layout->setContentsMargins(5, 5, 5, 5); // // 设置样式 // setStyleSheet( // "QScrollArea { background-color: #f8f9fa; }" // "QWidget { background-color: transparent; }" // ); // } // WindowIconListWidget::~WindowIconListWidget() // { // clearLayout(); // } // void WindowIconListWidget::refreshWindowList() // { // qDebug() << "Refreshing window list..."; // // 获取窗口列表 // auto newWindows = EnhancedWindowFinder::GetExtendedList(true); // // 检查是否有变化 // bool hasChanges = (newWindows.size() != m_windows.size()); // if (!hasChanges) { // for (int i = 0; i < newWindows.size(); ++i) { // if (newWindows[i].hwnd != m_windows[i].hwnd) { // hasChanges = true; // break; // } // } // } // if (hasChanges) { // m_windows = newWindows; // updateLayout(); // qDebug() << "Window list updated:" << m_windows.size() << "windows"; // } // } // void WindowIconListWidget::setThumbnailSize(const QSize& size) // { // if (m_thumbnailSize != size) { // m_thumbnailSize = size; // updateLayout(); // } // } // void WindowIconListWidget::updateLayout() // { // clearLayout(); // if (m_windows.isEmpty()) { // return; // } // // 计算列数 // int availableWidth = viewport()->width() - 20; // m_columnsCount = qMax(1, availableWidth / (m_thumbnailSize.width() + 10)); // int row = 0, col = 0; // for (const auto& window : m_windows) { // auto* iconWidget = createWindowIcon(window); // if (iconWidget) { // m_layout->addWidget(iconWidget, row, col); // col++; // if (col >= m_columnsCount) { // col = 0; // row++; // } // } // } // // 添加弹性空间 // m_layout->setRowStretch(row + 1, 1); // m_layout->setColumnStretch(m_columnsCount, 1); // } // QWidget* WindowIconListWidget::createWindowIcon(const WindowInfo& info) // { // auto* widget = new QWidget; // widget->setFixedSize(m_thumbnailSize + QSize(10, 30)); // widget->setCursor(Qt::PointingHandCursor); // auto* layout = new QVBoxLayout(widget); // layout->setContentsMargins(2, 2, 2, 2); // layout->setSpacing(2); // // 缩略图 // auto* thumbnailLabel = new QLabel; // thumbnailLabel->setFixedSize(m_thumbnailSize); // thumbnailLabel->setScaledContents(true); // thumbnailLabel->setStyleSheet( // "QLabel { " // " border: 1px solid #bdc3c7; " // " border-radius: 3px; " // " background-color: #ecf0f1; " // "}" // ); // // 设置缩略图 // if (!info.thumbnail.isNull()) { // thumbnailLabel->setPixmap(info.thumbnail.scaled(m_thumbnailSize, Qt::KeepAspectRatio, Qt::SmoothTransformation)); // } else { // // 使用图标作为占位符 // QPixmap iconPixmap = info.icon.pixmap(64, 64); // thumbnailLabel->setPixmap(iconPixmap); // } // layout->addWidget(thumbnailLabel); // // 标题 // auto* titleLabel = new QLabel(info.title); // titleLabel->setAlignment(Qt::AlignCenter); // titleLabel->setWordWrap(true); // titleLabel->setMaximumHeight(20); // titleLabel->setStyleSheet("font-size: 10px; color: #2c3e50;"); // // 截断过长的标题 // QString displayTitle = info.title; // if (displayTitle.length() > 20) { // displayTitle = displayTitle.left(17) + "..."; // } // titleLabel->setText(displayTitle); // titleLabel->setToolTip(info.title); // layout->addWidget(titleLabel); // // 存储窗口句柄 // widget->setProperty("hwnd", reinterpret_cast(info.hwnd)); // // 连接点击事件 // widget->installEventFilter(this); // // 最小化窗口的视觉提示 // if (info.isMinimized) { // widget->setStyleSheet("QWidget { opacity: 0.7; }"); // } // return widget; // } // void WindowIconListWidget::clearLayout() // { // while (QLayoutItem* item = m_layout->takeAt(0)) { // if (QWidget* widget = item->widget()) { // widget->deleteLater(); // } // delete item; // } // } // void WindowIconListWidget::resizeEvent(QResizeEvent* event) // { // QScrollArea::resizeEvent(event); // // 延迟更新布局,避免频繁重绘 // QTimer::singleShot(100, this, &WindowIconListWidget::updateLayout); // } // bool WindowIconListWidget::eventFilter(QObject* obj, QEvent* event) // { // if (auto* widget = qobject_cast(obj)) { // HWND hwnd = reinterpret_cast(widget->property("hwnd").value()); // if (event->type() == QEvent::MouseButtonPress) { // auto* mouseEvent = static_cast(event); // if (mouseEvent->button() == Qt::LeftButton) { // emit windowSelected(hwnd); // return true; // } // } else if (event->type() == QEvent::MouseButtonDblClick) { // emit windowDoubleClicked(hwnd); // return true; // } // } // return QScrollArea::eventFilter(obj, event); // } // // ============================================================================ // // WindowPreviewWidget Implementation // // ============================================================================ // WindowPreviewWidget::WindowPreviewWidget(QWidget* parent) // : OpenGLVideoWidget(parent) // , m_captureTimer(new QTimer(this)) // , m_stateTimer(new QTimer(this)) // , m_targetHwnd(nullptr) // , m_isPreviewActive(false) // , m_isWindowMinimized(false) // { // connect(m_captureTimer, &QTimer::timeout, // this, &WindowPreviewWidget::captureWindow); // connect(m_stateTimer, &QTimer::timeout, // this, &WindowPreviewWidget::checkWindowState); // setNoVideoTip("请选择要预览的窗口"); // } // WindowPreviewWidget::~WindowPreviewWidget() // { // stopPreview(); // } // void WindowPreviewWidget::setTargetWindow(HWND hwnd) // { // if (m_targetHwnd == hwnd) { // return; // } // stopPreview(); // m_targetHwnd = hwnd; // if (hwnd && IsWindow(hwnd)) { // // 获取窗口标题 // wchar_t title[256]; // GetWindowTextW(hwnd, title, 256); // m_windowTitle = QString::fromWCharArray(title); // setNoVideoTip(QString("准备预览: %1").arg(m_windowTitle)); // } else { // m_windowTitle.clear(); // setNoVideoTip("请选择要预览的窗口"); // } // } // void WindowPreviewWidget::startPreview(int frameRate) // { // if (!m_targetHwnd || !IsWindow(m_targetHwnd) || m_isPreviewActive) { // return; // } // qDebug() << "Starting window preview for" << m_windowTitle << "at" << frameRate << "fps"; // // 配置视频参数 // Encoder::Param videoParam; // RECT rect; // GetClientRect(m_targetHwnd, &rect); // videoParam.width = rect.right - rect.left; // videoParam.height = rect.bottom - rect.top; // videoParam.fps = frameRate; // if (videoParam.width <= 0 || videoParam.height <= 0) { // qWarning() << "Invalid window size for" << m_windowTitle; // setNoVideoTip("窗口尺寸无效"); // return; // } // if (m_windowRecorder.Open(m_targetHwnd, videoParam, CaptureMethod::WGC)) { // m_captureTimer->start(1000 / frameRate); // m_stateTimer->start(1000); // 每秒检查窗口状态 // m_isPreviewActive = true; // m_isWindowMinimized = IsIconic(m_targetHwnd); // setNoVideoTip(""); // qDebug() << "Window preview started successfully"; // } else { // qWarning() << "Failed to start window preview for" << m_windowTitle; // setNoVideoTip("预览启动失败"); // } // } // void WindowPreviewWidget::stopPreview() // { // if (!m_isPreviewActive) { // return; // } // qDebug() << "Stopping window preview"; // m_captureTimer->stop(); // m_stateTimer->stop(); // m_windowRecorder.Close(); // m_isPreviewActive = false; // if (!m_windowTitle.isEmpty()) { // setNoVideoTip(QString("预览已停止: %1").arg(m_windowTitle)); // } else { // setNoVideoTip("请选择要预览的窗口"); // } // } // void WindowPreviewWidget::captureWindow() // { // if (!m_isPreviewActive || !m_targetHwnd || !IsWindow(m_targetHwnd)) { // return; // } // AVFrame* frame = m_windowRecorder.GetRenderFrame(); // if (frame) { // // 如果窗口未最小化,保存最后一帧 // if (!m_isWindowMinimized) { // // 这里可以将AVFrame转换为QPixmap保存 // // m_lastFrame = convertAVFrameToPixmap(frame); // } // // 异步渲染帧 // QMetaObject::invokeMethod(this, "Render", Qt::QueuedConnection, // Q_ARG(AVFrame*, av_frame_clone(frame))); // } else if (m_isWindowMinimized && !m_lastFrame.isNull()) { // // 显示最后一帧 // handleMinimizedWindow(); // } // } // void WindowPreviewWidget::checkWindowState() // { // if (!m_targetHwnd || !IsWindow(m_targetHwnd)) { // stopPreview(); // return; // } // bool isMinimized = IsIconic(m_targetHwnd); // if (isMinimized != m_isWindowMinimized) { // m_isWindowMinimized = isMinimized; // if (isMinimized) { // handleMinimizedWindow(); // } else { // handleRestoredWindow(); // } // } // } // void WindowPreviewWidget::handleMinimizedWindow() // { // qDebug() << "Window minimized:" << m_windowTitle; // if (!m_lastFrame.isNull()) { // // 显示最后一帧的静态图像 // // 这里需要实现将QPixmap显示在OpenGL组件上的功能 // setNoVideoTip(QString("窗口已最小化: %1\n(显示最后画面)").arg(m_windowTitle)); // } else { // setNoVideoTip(QString("窗口已最小化: %1").arg(m_windowTitle)); // } // } // void WindowPreviewWidget::handleRestoredWindow() // { // qDebug() << "Window restored:" << m_windowTitle; // setNoVideoTip(""); // } // void WindowPreviewWidget::setLastFrame(const QPixmap& frame) // { // m_lastFrame = frame; // } // void WindowPreviewWidget::paintEvent(QPaintEvent* event) // { // OpenGLVideoWidget::paintEvent(event); // // 绘制窗口信息 // if (!m_windowTitle.isEmpty()) { // QPainter painter(this); // painter.setRenderHint(QPainter::Antialiasing); // // 绘制窗口标题 // painter.setPen(Qt::white); // painter.drawText(10, height() - 10, m_windowTitle); // // 绘制状态指示器 // if (m_isPreviewActive) { // painter.setPen(QPen(Qt::green, 2)); // painter.setBrush(Qt::green); // painter.drawEllipse(width() - 20, 10, 10, 10); // } // if (m_isWindowMinimized) { // painter.setPen(Qt::yellow); // painter.drawText(width() - 100, 25, "MINIMIZED"); // } // } // } // // ============================================================================ // // EnhancedWindowFinder Implementation // // ============================================================================ // QVector EnhancedWindowFinder::GetExtendedList(bool includeMinimized) // { // QVector result; // // 获取基本窗口列表 // const auto& basicList = WindowFinder::GetList(true); // for (const auto& basic : basicList) { // if (!IsWindow(basic.hwnd)) { // continue; // } // bool isMinimized = IsWindowMinimized(basic.hwnd); // if (!includeMinimized && isMinimized) { // continue; // } // ExtendedInfo info; // info.hwnd = basic.hwnd; // info.title = ""; // //basic.title; // info.isMinimized = isMinimized; // info.isVisible = IsWindowVisible(basic.hwnd); // info.rect = GetWindowRect(basic.hwnd); // info.processId = GetProcessId(basic.hwnd); // info.processName = GetProcessName(basic.hwnd); // info.icon = GetWindowIcon(basic.hwnd); // // 获取缩略图(可选,比较耗时) // if (!isMinimized && info.isVisible) { // info.thumbnail = ResourceManager::instance().getCachedThumbnail(basic.hwnd); // if (info.thumbnail.isNull()) { // info.thumbnail = GetWindowThumbnail(basic.hwnd); // if (!info.thumbnail.isNull()) { // ResourceManager::instance().cacheThumbnail(basic.hwnd, info.thumbnail); // } // } // } // result.append(info); // } // return result; // } // QIcon EnhancedWindowFinder::GetWindowIcon(HWND hwnd) // { // HICON hIcon = GetWindowIconHandle(hwnd); // if (hIcon) { // // Qt5兼容的HICON转换 // QPixmap pixmap; // ICONINFO iconInfo; // if (GetIconInfo(hIcon, &iconInfo)) { // // 获取位图信息 // BITMAP bmp; // if (GetObject(iconInfo.hbmColor, sizeof(BITMAP), &bmp)) { // // 创建设备上下文 // HDC hdc = CreateCompatibleDC(NULL); // if (hdc) { // // 准备位图信息头 // BITMAPINFOHEADER bih = {0}; // bih.biSize = sizeof(BITMAPINFOHEADER); // bih.biWidth = bmp.bmWidth; // bih.biHeight = -bmp.bmHeight; // bih.biPlanes = 1; // bih.biBitCount = 32; // bih.biCompression = BI_RGB; // // 分配内存 // int dataSize = bmp.bmWidth * bmp.bmHeight * 4; // uchar* data = new uchar[dataSize]; // // 获取位图数据 // BITMAPINFO bi = {0}; // bi.bmiHeader = bih; // if (GetDIBits(hdc, iconInfo.hbmColor, 0, bmp.bmHeight, data, &bi, DIB_RGB_COLORS)) { // // 创建QImage // QImage image(data, bmp.bmWidth, bmp.bmHeight, QImage::Format_ARGB32); // pixmap = QPixmap::fromImage(image.rgbSwapped()); // } // delete[] data; // DeleteDC(hdc); // } // } // // 清理资源 // if (iconInfo.hbmColor) DeleteObject(iconInfo.hbmColor); // if (iconInfo.hbmMask) DeleteObject(iconInfo.hbmMask); // } // DestroyIcon(hIcon); // if (!pixmap.isNull()) { // return QIcon(pixmap); // } // } // // 使用默认图标 // return QApplication::style()->standardIcon(QStyle::SP_ComputerIcon); // } // HICON EnhancedWindowFinder::GetWindowIconHandle(HWND hwnd) // { // // 尝试多种方式获取图标 // HICON hIcon = nullptr; // // 方法1: 发送消息获取大图标 // hIcon = reinterpret_cast(SendMessage(hwnd, WM_GETICON, ICON_BIG, 0)); // if (hIcon) return hIcon; // // 方法2: 发送消息获取小图标 // hIcon = reinterpret_cast(SendMessage(hwnd, WM_GETICON, ICON_SMALL, 0)); // if (hIcon) return hIcon; // // 方法3: 从窗口类获取图标 // hIcon = reinterpret_cast(GetClassLongPtr(hwnd, GCLP_HICON)); // if (hIcon) return hIcon; // // 方法4: 从窗口类获取小图标 // hIcon = reinterpret_cast(GetClassLongPtr(hwnd, GCLP_HICONSM)); // if (hIcon) return hIcon; // return nullptr; // } // QPixmap EnhancedWindowFinder::GetWindowThumbnail(HWND hwnd, const QSize& size) // { // return CaptureWindow(hwnd, size); // } // QPixmap EnhancedWindowFinder::CaptureWindow(HWND hwnd, const QSize& size) // { // if (!IsWindow(hwnd) || !IsWindowVisible(hwnd)) { // return QPixmap(); // } // RECT rect; // ::GetWindowRect(hwnd, &rect); // int width = rect.right - rect.left; // int height = rect.bottom - rect.top; // if (width <= 0 || height <= 0) { // return QPixmap(); // } // // 使用PrintWindow API捕获窗口 // HDC hdcWindow = GetDC(hwnd); // HDC hdcMemDC = CreateCompatibleDC(hdcWindow); // HBITMAP hbmScreen = CreateCompatibleBitmap(hdcWindow, width, height); // SelectObject(hdcMemDC, hbmScreen); // // 尝试使用PrintWindow // BOOL result = PrintWindow(hwnd, hdcMemDC, PW_CLIENTONLY); // if (!result) { // // 如果PrintWindow失败,尝试BitBlt // BitBlt(hdcMemDC, 0, 0, width, height, hdcWindow, 0, 0, SRCCOPY); // } // // 转换为QPixmap (Qt5兼容) // QPixmap pixmap; // // 获取位图信息 // BITMAP bmp; // if (GetObject(hbmScreen, sizeof(BITMAP), &bmp)) { // // 创建设备上下文 // HDC hdc = CreateCompatibleDC(NULL); // if (hdc) { // // 准备位图信息头 // BITMAPINFOHEADER bih = {0}; // bih.biSize = sizeof(BITMAPINFOHEADER); // bih.biWidth = bmp.bmWidth; // bih.biHeight = -bmp.bmHeight; // 负值表示自上而下 // bih.biPlanes = 1; // bih.biBitCount = 32; // bih.biCompression = BI_RGB; // // 分配内存 // int dataSize = bmp.bmWidth * bmp.bmHeight * 4; // uchar* data = new uchar[dataSize]; // // 获取位图数据 // BITMAPINFO bi = {0}; // bi.bmiHeader = bih; // if (GetDIBits(hdc, hbmScreen, 0, bmp.bmHeight, data, &bi, DIB_RGB_COLORS)) { // // 创建QImage // QImage image(data, bmp.bmWidth, bmp.bmHeight, QImage::Format_ARGB32); // pixmap = QPixmap::fromImage(image.rgbSwapped()); // } // delete[] data; // DeleteDC(hdc); // } // } // // 清理资源 // DeleteObject(hbmScreen); // DeleteDC(hdcMemDC); // ReleaseDC(hwnd, hdcWindow); // // 缩放到指定尺寸 // if (!pixmap.isNull() && !size.isEmpty()) { // pixmap = pixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation); // } // return pixmap; // } // bool EnhancedWindowFinder::IsWindowMinimized(HWND hwnd) // { // return IsIconic(hwnd); // } // QString EnhancedWindowFinder::GetProcessName(HWND hwnd) // { // DWORD processId = GetProcessId(hwnd); // HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId); // if (!hProcess) { // return QString(); // } // wchar_t processName[MAX_PATH]; // DWORD size = MAX_PATH; // if (QueryFullProcessImageNameW(hProcess, 0, processName, &size)) { // CloseHandle(hProcess); // QString fullPath = QString::fromWCharArray(processName); // return QFileInfo(fullPath).baseName(); // } // CloseHandle(hProcess); // return QString(); // } // DWORD EnhancedWindowFinder::GetProcessId(HWND hwnd) // { // DWORD processId = 0; // GetWindowThreadProcessId(hwnd, &processId); // return processId; // } // RECT EnhancedWindowFinder::GetWindowRect(HWND hwnd) // { // RECT rect = {0}; // ::GetWindowRect(hwnd, &rect); // return rect; // } // // ============================================================================ // // ResourceManager Implementation // // ============================================================================ // ResourceManager& ResourceManager::instance() // { // static ResourceManager instance; // return instance; // } // bool ResourceManager::canStartCapture() const // { // return m_activeSessions.size() < MAX_CONCURRENT_CAPTURES; // } // void ResourceManager::addCaptureSession(HWND hwnd) // { // m_activeSessions.insert(hwnd); // } // void ResourceManager::removeCaptureSession(HWND hwnd) // { // m_activeSessions.remove(hwnd); // } // void ResourceManager::cacheThumbnail(HWND hwnd, const QPixmap& thumbnail) // { // m_thumbnailCache.insert(hwnd, new QPixmap(thumbnail)); // } // QPixmap ResourceManager::getCachedThumbnail(HWND hwnd) const // { // QPixmap* cached = m_thumbnailCache.object(hwnd); // return cached ? *cached : QPixmap(); // } // void ResourceManager::cleanup() // { // m_activeSessions.clear(); // m_thumbnailCache.clear(); // }