提交工单
咨询集成、功能及报价等问题
Window thumbnails are mainly used to assist window sharing and screen sharing to select the corresponding window or screen. This article mainly describes how to set up window thumbnail sharing. For details, please refer to Sample Demo.
/*
Set log path and level
*/
zego_screencapture_set_log_level(kZegoLogLevelDebug, logDir);
/*
Initialization
*/
zego_screencapture_init();
/*
Set the window state change callback
*/
zego_windowthumbnail_window_status_change_notify(WindowChangeCallback,nullptr);
/*
Get the windows and screens that can create thumbnails
*/
ZegoThumbnailWindowInfo* pInfo = zego_windowthumbnail_find_windows(&iCount);
/*
Pass in the ID of the window or screen to display the thumbnail. The picture data will be returned in the window state change callback. Let the client draw
*/
zego_windowthumbnail_register((ZegoWindowHandle)this->winId(), info[i].thumbnail_id, &rect)
/*
The structure of the window information returned by zego_windowthumbnail_find_windows is as follows, the client draws the preview window title and the icon of the process where the window is located according to the preview information
*/
struct ZegoThumbnailIconBits
{
int width; ///< The width of the icon corresponding to the window (pixels)
int height; ///< Capture picture height (pixels)
int format; ///< (unused) default BGRA32
unsigned int len; ///< Window corresponding icon picture data size
unsigned char* bits; ///< window corresponding icon picture data
};
struct ZegoThumbnailWindowInfo
{
int thumbnail_id; ///< thumbnail ID
ZegoWindowHandle handle; ///< window handle
char window_title[ZEGO_MAX_TITLE]; ///< window title (windows when isScreen is true, the format is screen 1----\\\\.\\DISPLAY1)
ZegoThumbnailIconBits *icon_bits; ///< source window process icon data
#ifndef WIN32
ZegoThumbnailIconBits *image_bits; ///< Thumbnail data
#endif
bool isScreen; ///< Is it a screen
};
/*
When the client selects one of the windows to share, you can call the zego_windowthumbnail_show_source_window method to display the source window on top
*/
if (event->type() == QEvent::MouseButtonDblClick)
{
QPoint coursePoint;
coursePoint = QCursor::pos();//Get the current cursor position
coursePoint = QWidget::mapFromGlobal(coursePoint);
for (const auto& it : m_Infos)
{
if (it.rectThumbnail.contains(coursePoint))
{
//it.WinID can be used as a window handle for window sharing
m_CaptureWinID = it.WinID;
zego_windowthumbnail_show_source_window((ZegoWindowHandle)it.WinID, kZegoThumbnailShowWindowCmdShow);
this->hide();
break;
}
}
}
/*
For windows with registered thumbnails, when the window title changes or the window is closed, or a new window is created, a callback will be generated to update the thumbnail of the preview window
*/
void NotifyWindowChangeCallback(WindowStatus ChangeCode,int id,HWND hWnd, const char* szWindowName)
{
if (ChangeCode == WND_STATUS_DESTROY||ChangeCode == WND_STATUS_INVALID)
{
//Rearrangement of the client's previous display area
zego_windowthumbnail_unregister(thumbnail_id);
}
else if (ChangeCode == WND_STATUS_CREATE)
{
//Client assigns thumbnail display area
zego_windowthumbnail_register(/*...*/);
}
else if (ChangeCode == WND_STATUS_NAMECHANGE)
{
//Original thumbnail name change
}
}
The window state change callback returns the window is invalid or unregistered thumbnail when it is destroyed
Unregister all thumbnails when closed
if (event->type() == QEvent::Hide)
{
for (const auto& it : m_Infos)
{
zego_windowthumbnail_unregister(it.ThumbnailID);
}
m_Infos.clear();
}