私は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();
}
しかし、どのように同じpythonでですか?私のプログラムは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()) アウト' –
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