MFC和QT的消息循环机制不同,所以,要让QT写的DLL可以供MFC调用,要做一点特殊的处理
- #include <qmfcapp.h>
- #include <qwinwidget.h>
- #include <QtGui>
- #include <QtGui/QMessageBox>
- #include <windows.h>
- #include <QTextCodec>
- #include "widget.h"
- BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpvReserved*/ )
- {
- static bool ownApplication = FALSE;
- //加入本地语言支持
- QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
- QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
- if ( dwReason == DLL_PROCESS_ATTACH )
- {
- ownApplication = QMfcApp::pluginInstance( hInstance );
- }
- if ( dwReason == DLL_PROCESS_DETACH && ownApplication )
- {
- qApp->quit();
- delete qApp;
- }
- return TRUE;
- }
- extern "C" __declspec(dllexport) int ShowDialog( HWND parent)
- {
- QWinWidget win(parent, NULL, Qt::Window);
- win.showCentered();
- win.center();
- QHBoxLayout hbox(&win);
- Widget *widget = new Widget(&win);
- widget->setWindowFlags(Qt::Window);
- hbox.addWidget(widget);
- win.show();
- qApp->exec();
- }
http://blog.csdn.net/small_qch/article/details/6743803
https://github.com/qtproject/qt-solutions/tree/master/qtwinmigrate