PDA

View Full Version : Native parent window for QWidget (IPreviewHandler)



Kevsoft
19th July 2015, 08:25
Hi there!

I am currently trying to make a shell extension preview handler with Qt. The code I work with is based on the Recipe Preview Handler (https://msdn.microsoft.com/en-us/library/windows/desktop/dd940374%28v=vs.85%29.aspx) + ActiveQt. Everything works fine except the creation of the preview window.

I need to create a widget which has a native window (HWND/WId) parent. I have looked in the QWidget documentation but I didn't found anything.

My Question is: Is it possible to create a widget which has a native window as parent?

wysota
19th July 2015, 10:31
A top level window is always a native window. You can get a handle to it by calling winId().

Kevsoft
19th July 2015, 12:13
Okay I am one step futher, but the widget is showed in a own window rather than in the preview frame.

This is the code I have:


HRESULT PreviewHandler::DoPreview()
{
HRESULT hr = E_FAIL;
if (previewWidget.isNull() && _pStream) // cannot call more than once (Unload should be called before another DoPreview)
{
previewWidget.reset(new PreviewWidget());
::SetParent((HWND)previewWidget->winId(), _hwndParent);
ShowWindow((HWND)previewWidget->winId(), SW_SHOW);
//previewWidget->show(); //Same effect
}
return hr;
}


So how can I show the widget as child rather than in a own window?

wysota
19th July 2015, 13:24
I don't think you can do that without some special tricks. The best that comes to my mind is to render the widget to an image and then draw that image to the preview window using WinAPI calls.