#include "ax1.h"#include <windows.h>#include <QApplication>#include <QTextCodec>#include <QPushButton>extern "C" __declspec( dllexport ) HWND proc_set_widget(HWND parent_handle);QApplication *app = 0;AXTIV_WIDGET *w = 0;WNDPROC funcWindowPtr = 0;extern "C" LRESULT CALLBACK QtWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);LRESULT CALLBACK NewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ //if (funcWindowPtr) //CallWindowProc(funcWindowPtr, hWnd, message, wParam, lParam); CallWindowProc(QtWndProc, hWnd, message, wParam, lParam); return 0;}//parent_handle == TObject.HandleAXTIV_WIDGET::AXTIV_WIDGET(HWND parent_handle) :fill_color(Qt::red){ extern HINSTANCE appInst; extern HINSTANCE appPrevInst; appPrevInst = appInst; appInst = (HINSTANCE)GetWindowLong(parent_handle, GWL_HINSTANCE); SetWindowLong(winId(), GWL_HINSTANCE , (LONG)GetWindowLong(parent_handle, GWL_HINSTANCE)); SetWindowLong(winId(), GWL_HWNDPARENT, (LONG)parent_handle); funcWindowPtr = (WNDPROC)GetWindowLong(parent_handle, GWL_WNDPROC); SetWindowLong(winId(), GWL_WNDPROC, (LONG)NewWndProc); QWidget::create(parent_handle, true, true); setFillColor(QColor("Red")); b = new QPushButton(this); b->setGeometry(0,0, 20, 20); b->setText(tr("OK")); b->show(); show(); }HWND proc_set_widget(HWND parent_handle){ int argc = 0; char **argv = 0; if (app == 0) { app = new QApplication(argc, argv); QTextCodec *tCodec = QTextCodec::codecForName("CP1251"); QTextCodec::setCodecForTr(tCodec); } if (w != 0) delete w; extern HINSTANCE appInst; extern HINSTANCE appPrevInst; appPrevInst = appInst; appInst = (HINSTANCE)GetWindowLong(parent_handle, GWL_HINSTANCE); w = new AXTIV_WIDGET(parent_handle); w->setGeometry(0,0, 30, 30); w->show(); SetWindowPos(w->winId(), 0, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED); SetWindowLong(w->winId(), GWL_STYLE, WS_VISIBLE | WS_BORDER |WS_CHILD | WS_MAXIMIZEBOX); ShowWindow(w->winId(), SW_NORMAL); return w->winId();;}//это заголовочный файл#ifndef AX1_H#define AX1_H#include <QWidget>#include <QPainter>#include <windows.h>#include <QApplication>#include <QPushButton>//! [0]class AXTIV_WIDGET : public QWidget{ Q_OBJECT/* Q_CLASSINFO("ClassID", "{1D9928BD-4453-4bdd-903D-E525ED17FDE5}") Q_CLASSINFO("InterfaceID", "{99F6860E-2C5A-42ec-87F2-43396F4BE389}") Q_CLASSINFO("EventsID", "{0A3E9F27-E4F1-45bb-9E47-63099BCCD0E3}")*/ Q_PROPERTY(QColor fillColor READ fillColor WRITE setFillColor)public: QPushButton *b;AXTIV_WIDGET(HWND parent_handle); QColor fillColor() const { return fill_color; } void setFillColor(const QColor &fc) { fill_color = fc; repaint(); }protected: void paintEvent(QPaintEvent *e) { QPainter paint(this); QRect r = rect(); r.adjust(10, 10, -10, -10); paint.fillRect(r, fill_color); }private: QColor fill_color;};//! [0]#endif // AX1_H