如何在DLL中创建窗体(对话框和SDI/MDI) C+/VC
[
2008-7-30 22:33:00
| 发表者 :
zihe
]
这是一个老问题了。我对此简单地写了一个小结,有不足之处,还请指出,谢 谢。
调用dll中的dlg或sdi/mdi, 只是不能再使用app类了,因为它是从cwinthread继承过来,内部的线程机制导出了问题的出现。
(1)对于调用dll中的dialog,很简单,直接调用就是
如: extern "c"
void loaddialog()
{
ctestdlg dlg;
if (dlg.domodal == iodk)
{
//......
}
}
(2)对于调用dll中的sdi/mdi, 不那么直接。需要保证doc/view和mainframe之间的关联,因此得保留原来在app中用的cdoctempate类及对它的使用。为此,我们可以自己建一个类如csdimain来做接替原来app中的工作(当然不用类,就直接用问题也不大,毕竟都是创建工作都是在堆上进行的),
如:
bool csdimain::initinstance()
{
// 创建模板
if(m_ptemplate == null)
{
m_ptemplate = new cmultidoctemplate(
idr_mainframe,
runtime_class(csdifortestdoc),
runtime_class(cmainframe),
runtime_class(csdifortestview));
}
csdifortestdoc* pdocument = new csdifortestdoc;
// 创建新的frame
cframewnd* pframe = m_ptemplate->createnewframe(pdocument, null);
if (null == pframe)
{
afxmessagebox("create frame failed");
return false;
}
m_ptemplate->initialupdateframe(pframe, pdocument);
return true;
}
杨晓明 2002-5-11
e-mail: brierbird97@mails.tsinghua.edu.cn
上一篇:
让CListBox具有拖放功能 C+/VC 下一篇:
c+对象模型读书笔记一 C+/VC