从HDC句柄创建QPaintDevice [英] Create a QPaintDevice from HDC handle
问题描述
我有一个来自外部库的Windows HDC句柄,我想使用QPainter功能来绘制。在Qt中有什么办法从HDC句柄创建QPaintDevice?
使用Windows API从HDC获取HWND。
HWND handle = WindowFromDC(hdc);
assert(handle!= NULL);
然后再子类化QWidget以访问受保护的成员convert。使用此,使用此成员如此解决方案中所述创建QWidget:如何创建一个带有hwnd作为父类的qwidget 。在这个例子中,我为QWidgetWrapper调用了子类。
QWidgetWrapper * w = new QWidgetWrapper
w-> create((Wld)main_window);
注意,Wld是平台相关窗口标识符的Qt中的typedef。
I have a Windows HDC handle from an external library that I'd like to use QPainter functionality to draw on. Is there any way in Qt to create a QPaintDevice from a HDC handle?
One way of doing this:
Using the Windows API, get the HWND from the HDC.
HWND handle = WindowFromDC(hdc);
assert(handle != NULL);
Then subclass QWidget to get access to the protected member convert. Using this, create the QWidget using this member as described in this solution: How to create a qwidget with a hwnd as parent. In this example, I've called the subclass for QWidgetWrapper.
QWidgetWrapper *w = new QWidgetWrapper();
w->create((Wld)main_window);
Note that Wld is a typedef in Qt for "Platform dependent window identifier".
这篇关于从HDC句柄创建QPaintDevice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!