Screen Sharing
  • Electron
  • Windows : C++
  • SDK Downloads
  • Sample Codes
  • Quick Starts
  • Best Practices
  • API Documents
  • Documentation
  • Screen Sharing
  • Quick Starts
  • Window Thumbnails

Window Thumbnails

Last updated:2022-03-22 13:06

1 Introduction

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.

2 Thumbnail Call Process

1. Initialization

/*
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);

2. Get the Window List

/*
Get the windows and screens that can create thumbnails
*/
ZegoThumbnailWindowInfo* pInfo = zego_windowthumbnail_find_windows(&iCount);

3. Register a Thumbnail

/*
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)

4. Draw Window Title and Window Icon

/*
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
};

5. Click to Show Source Window

/*
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;
        }
    }
}

6. Window State Change Callback (Including Thumbnail and Icon Callback)

/*
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
    }
}

7. De-register Thumbnail

  1. The window state change callback returns the window is invalid or unregistered thumbnail when it is destroyed

  2. Unregister all thumbnails when closed

    if (event->type() == QEvent::Hide)
    {
     for (const auto& it : m_Infos)
     {
         zego_windowthumbnail_unregister(it.ThumbnailID);
     }
     m_Infos.clear();
    }

3 Thumbnail Renderings

Page Directory