本文共 2524 字,大约阅读时间需要 8 分钟。
MFC和Qt分别使用Qt生成的Dll。
1、2017年8月3日17:56:33。
#ifndef QTDLGDLL#define QTDLGDLL#ifdef QTDLGDLL_LIBRARY//#include//# define QTDLGDLL_API Q_DECL_EXPORT#define QTDLGDLL_API __declspec(dllexport)#else#define QTDLGDLL_API __declspec(dllimport)#endif#define WIND_TYPE_NO 0#define WIND_TYPE_QT 1#define WIND_TYPE_WINDOWS 2typedef unsigned __int64 paduint64; /* 64 bit unsigned */typedef struct CPadSolderSpec { //面积. paduint64 m_uArea; //高度. unsigned long m_uHeight;} CPadSolderSpec;//struct CPadSolderSpec;#ifdef __cplusplusextern "C" {#endif QTDLGDLL_API int __cdecl OpenPadSettingDialogByMFC(void * ParentWind, CPadSolderSpec * pSpec); QTDLGDLL_API int __cdecl OpenPadSettingDialogByQt(void * ParentWind,CPadSolderSpec * pSpec);#ifdef __cplusplus}#endif#endif
#include "QtDlgDll.h"#include "PadSettingDialog.h"#includeMFC:#include #include bool g_bRun = false;int OpenPadSettingDialogByMFC(void * ParentWind, CPadSolderSpec * pSpec){ if (g_bRun) { return 0; } g_bRun = true; if (NULL == ParentWind) { return 0; } HWND hParentWnd = (HWND)ParentWind; HWND hSaveParentWnd = hParentWnd; Qt::HANDLE ThreadIdBefore = QThread::currentThreadId(); int argc = 0; char *argv[1] = {NULL}; QApplication a(argc, argv); Qt::HANDLE ThreadIdAfter = QThread::currentThreadId(); //模态对话框. CPadSettingDialog aDlg(NULL, pSpec); aDlg.setModal(true); //disable掉父窗口 hParentWnd = hSaveParentWnd; while (hParentWnd != NULL) { EnableWindow(hParentWnd, FALSE); hParentWnd = GetParent(hParentWnd); } aDlg.show(); a.exec(); //aDlg.exec(); //恢复父窗口的enable状态 hParentWnd = hSaveParentWnd; while (hParentWnd != NULL) { EnableWindow(hParentWnd, TRUE); hParentWnd = GetParent(hParentWnd); } g_bRun = false; return 1;}int OpenPadSettingDialogByQt(void * ParentWind, CPadSolderSpec * pSpec){ QWidget *parent = (QWidget *)ParentWind; //模态对话框. CPadSettingDialog aDlg(parent, pSpec); aDlg.exec(); return 1;}
CPadSolderSpec aSpec;void CtestMFCDlg::OnBnClickedOk(){ DWORD id1 = ::GetCurrentThreadId(); _TCHAR sId1[100]; _i64tot_s(id1, sId1,100,16); this->MessageBox(sId1, sId1, MB_ICONINFORMATION); OpenPadSettingDialogByMFC(m_hWnd,&aSpec); DWORD id2 = ::GetCurrentThreadId(); _TCHAR sId2[100]; _i64tot_s(id2, sId2, 100, 16); this->MessageBox(sId2, sId2, MB_ICONINFORMATION); int a = 1; a++; // TODO: 在此添加控件通知处理程序代码 //CDialogEx::OnOK();}Qt:
CPadSolderSpec aSpec;void MainWindow::on_pushButton3_clicked(){ OpenPadSettingDialogByQt(NULL,&aSpec); //OpenPadSettingDialogByQt(this, &aSpec); return;
转载地址:http://dswci.baihongyu.com/