나는 OpenGL을 사용하여 윈도우를 그리는 DLL을 가지고있다. Dll은 HWMD에 의해 윈도우를 얻는다.qwidget.winid를 Python의 DLL에 건네기
DLL :
extern "C" __declspec(dllexport) int Init(HWND hWnd);
extern "C" __declspec(dllexport) void Resize(HWND hWnd, int w, int h);
extern "C" __declspec(dllexport) void Paint(HWND hWnd);
는 C++ Qt는 응용 프로그램이 제대로 작동합니다.
#include "windows.h"
#include <QApplication>
#include <QWidget>
#include <QGLWidget>
#include <QMessageBox>
#include <QSplitter>
#include <QLibrary>
typedef void (*InitPrototype)(HWND);
typedef void (*PaintPrototype)(HWND);
typedef void (*ResizePrototype)(HWND, int, int);
InitPrototype c_Init;
PaintPrototype c_Paint;
ResizePrototype c_Resize;
bool load_opengl_library(){
QLibrary lib("engine3d");
lib.load();
c_Init = (InitPrototype)lib.resolve("Init");
c_Paint = (PaintPrototype)lib.resolve("Paint");
c_Resize = (ResizePrototype)lib.resolve("Resize");
return true;
}
class MyGlWidget: public QGLWidget {
public:
MyGlWidget(QWidget *parent = 0): QGLWidget(parent){}
void showEvent(QShowEvent* event){
c_Init((HWND)(this->winId()));
}
void paintEvent(QPaintEvent* event){
c_Paint((HWND)this->winId());
}
void resizeEvent(QResizeEvent* event){
c_Resize((HWND)this->winId(), this->width(), this->height());
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
load_opengl_library();
MyGlWidget w;
w.show();
return a.exec();
}
하지만 어떻게 파이썬에서 동일합니까? 내 프로그램은 widget.winId()를 보내는 것을 중단합니다.
# coding=utf-8
import ctypes
from PyQt5 import QtWidgets, QtOpenGL
app = QtWidgets.QApplication([])
e3d = ctypes.CDLL(r"engine3d.dll")
init = lambda hwnd: e3d.Init(hwnd)
paint = lambda hwnd: e3d.Paint(hwnd)
resize = lambda hwnd, w, h: e3d.Paint(hwnd, w, h)
class MyGLWidget(QtOpenGL.QGLWidget):
def __init__(self):
super().__init__()
def showEvent(self, ev):
init(self.winId())
def paintEvent(self, ev):
paint(self.winId())
def resizeEvent(self, ev):
resize(self.winId(), self.width(), self.height())
w = MyGLWidget()
w.show()
app.exec_()
인쇄 (self.winId는()) DLL을 가지고 확인하는 쉬운 것, 그래서 나는 파란색을 말하는 것이다
': 인쇄 (self.winId()) 아웃 <0x03463C38에서 sip.voidptr object>'않음 – den
'INIT = e3d.Init init.argtypes = ctypes.c_uint32] 페인트 = E3D. paint.argtypes = [ctypes.c_uint32] 크기를 조정 = e3d.Resize resize.argtypes = [ctypes.c_uint32, ctypes.c_int32, ctypes.c_int32]' – den