//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Main.h"
#include "About.h"
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
TMainForm *MainForm;
/*
extern "C"
{
__declspec(dllimport) void __stdcall ShowForm(TApplication *CallingApp);
//extern "C" void _stdcall ShowForm(TApplication *CallingApp);
__declspec(dllimport) TForm* __stdcall NewForm(TComponent *App);
__declspec(dllimport) TForm* __stdcall CreateForm(TApplication *CallingApp);
};
*/
typedef void __declspec(dllimport) ShowMDIFormType(TApplication *);
typedef void __declspec(dllimport) GetDescribeType(char *, int);
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent *Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::CreateMDIChild(String Name)
{
TMDIChild *Child;
//--- create a new MDI child window ----
Child = new TMDIChild(Application);
Child->Caption = Name;
if (FileExists (Name))
Child->Memo1->Lines->LoadFromFile(Name);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FileNew1Execute(TObject *Sender)
{
CreateMDIChild("NONAME" + IntToStr(MDIChildCount + 1));
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FileOpen1Execute(TObject *Sender)
{
if (OpenDialog->Execute())
CreateMDIChild(OpenDialog->FileName);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::HelpAbout1Execute(TObject *Sender)
{
AboutBox->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FileExit1Execute(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Button1Click(TObject *Sender)
{
CreateDllForm("Form1.dll", false); //建立唯一子窗口
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Button2Click(TObject *Sender)
{
CreateDllForm("Form1.dll", true); //建立多个子窗口
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action)
{
// Make sure all the children forms are closed
while (MDIChildCount)
MDIChildren[0]->Free();
for (map<AnsiString, HINSTANCE>::iterator it = map_dll_inst.begin();
it != map_dll_inst.end(); it++)
{
//DWORD dwError;
//HINSTANCE hInst = it->second;
if (FreeLibrary(it->second) == 0)
{
//dwError = GetLastError();
}
}
map_dll_inst.clear();
}
//---------------------------------------------------------------------------
bool __fastcall TMainForm::IsMDIChildCreate(const String Name, TForm **Child)
{
String TmpStr = "";
for (int i=0; i<MDIChildCount; i++)
{
TmpStr = MDIChildren[i]->ClassName();
if ( TmpStr == Name) {
if (Child != NULL)
*Child = MDIChildren[i];
//return i;
return true;
}
}
return false;
//return -1;
}
//---------------------------------------------------------------------------
bool __fastcall TMainForm::CreateDllForm(AnsiString DllName, bool MutilCreate/*是否创建多个窗体*/) //通过 DLL 创建 Form
{
if (DllName.IsEmpty()) return false;
HINSTANCE hInst;
if (map_dll_inst[DllName] == NULL)
{
hInst = LoadLibrary(DllName.c_str());
//if (hInst == NULL) return false;
}
else {
hInst = map_dll_inst[DllName];
}
if (hInst == NULL) return false;
else
{
ShowMDIFormType *ShowMDIForm = (ShowMDIFormType *)GetProcAddress(hInst, "ShowMDIForm");
GetDescribeType *GetDescribe = (GetDescribeType *)GetProcAddress(hInst, "GetDescribe");
if (ShowMDIForm != NULL && GetDescribe != NULL)
{
char szBuf[100] = {0};
TForm *frm;
GetDescribe(szBuf, 99);
String DllFormTypeName = szBuf;
if (!MutilCreate && IsMDIChildCreate(DllFormTypeName, &frm))
frm->BringToFront();
else
ShowMDIForm(Application);
map_dll_inst[DllName] = hInst;
} // 获取地址完成
else {
//清除 队列 卸载 DLL
FreeLibrary(hInst);
map_dll_inst.erase(DllName);
} // 获取地址不成功
}
}
//---------------------------------------------------------------------------
C++ Builder MDI 调用 DLL 子窗体(基于 BCB2010)
5星 · 超过95%的资源 需积分: 0 171 浏览量
2014-11-13
15:33:02
上传
评论 1
收藏 26KB RAR 举报
artsmart
- 粉丝: 3
- 资源: 2
最新资源
- STM32单片机FPGA毕设电路原理论文报告一种基于单片机的节能断电保护电路设计
- STM32单片机FPGA毕设电路原理论文报告一种基于单片机的机床位移检测系统
- unity3D翻书插件
- STM32单片机FPGA毕设电路原理论文报告一种基于单片机的红外测控系统
- Date(1).cpp
- java基于ssm珠宝商城购物网站案例设计
- STM32单片机FPGA毕设电路原理论文报告一种基于单片机的灯光调光控制系统开发
- STM32单片机FPGA毕设电路原理论文报告一种基于单片机的超声测距系统的设计
- Visual Basic快速入门.md
- STM32单片机FPGA毕设电路原理论文报告一种基于单片机的半导体激光器电源控制系统的设计
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈