#include <qwinwidget.h>
#include <QHBoxLayout>
#include <windows.h>
#include "widget.h"
BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpvReserved*/ )
{
static bool ownApplication = FALSE;
if ( dwReason == DLL_PROCESS_ATTACH ){
ownApplication = QMfcApp::pluginInstance( hInstance );
}
else if ( dwReason == DLL_PROCESS_DETACH && ownApplication ){
qApp->quit();
delete qApp;
}
return TRUE;
}
extern "C" __declspec(dllexport) int ShowDialog(HWND parent)
{
QWinWidget win( parent );
win.showCentered();
win.center();
QHBoxLayout hbox(&win);
Widget *w = new Widget(&win);
w->setWindowFlag(Qt::Window);
hbox.addWidget(w);
win.show();
return qApp->exec();
}
调用:
typedef int(*FUNC)(HWND);
HMODULE hDll = LoadLibrary(L"qtdialog.dll");
if (hDll!=NULL) {
FUNC displayQML = (FUNC)GetProcAddress(hDll, "ShowDialog");
if (displayQML != NULL) {
displayQML(hWnd);
}
else {
MessageBox(NULL, L"can't found function", L"tips", MB_OK);
}
FreeLibrary(hDll);
}
else {
MessageBox(NULL, L"can't found dll.", L"tips", MB_OK);
}
模态:this->setWindowModality(Qt::WindowModal);