添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm 'casting' the screen of window1 to window2 using the WINAPI DwmRegisterThumbnail

but as soon I set the window2 child of another window the image disappears .

After reading the docs I found this mention:

Setting the destination window handle to anything other than a top-level window type will result in a return value of E_INVALIDARG.

    HWND dest = (HWND)this->winId();
    HWND source = ...
    hr = DwmRegisterThumbnail(dest, source, &thumbnail_id);
    DWORD err = GetLastError();
    qDebug() << "hr: " << hr;
    if (SUCCEEDED(hr) && NULL != thumbnail_id)
        prop.dwFlags = DWM_TNP_RECTDESTINATION | DWM_TNP_RECTSOURCE | DWM_TNP_OPACITY
            | DWM_TNP_VISIBLE | DWM_TNP_SOURCECLIENTAREAONLY;
        prop.rcSource = { 0, 0, 1200, 600 };
        prop.rcDestination = { 0, 0, 1200, 600 };
        prop.opacity = 255;
        prop.fVisible = TRUE;
        prop.fSourceClientAreaOnly = FALSE;
        hr = DwmUpdateThumbnailProperties(thumbnail_id, &prop);
        qDebug() << "hr: " << hr;

I also tried using a QDockWidget but the image is visible only when the widget is not docked to the MainWindow, as soon I dock the widget, the image disappears, sad.

There's something else I could try to be able to 'cast' the image to a child window?

or maybe another winapi I could use?

Not supported. You can use a top-level owned window so that it always appears above a given window. You have to update its position whenever the owner window moves. – Jonathan Potter Dec 15, 2022 at 6:48 NO such documented API. Even DwmRegisterThumbnail already states Setting the destination window handle to anything other than a top-level window type will result in a return value of E_INVALIDARG. – YangXiaoPo-MSFT Dec 15, 2022 at 7:41

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.