最近做某个垃圾软件,有些子窗口只想它实例化一个,所以就顺手弄了个垃圾。
原理就是在主窗体找到MDIClient,然后按标题找MDI窗体,不存在实例化一个,存在就顶置它。
- //只实例化一个MDI的代码
- if(!checkreg()) return;
- CString YourMdiTitle;
- #define YourMdiClass pcsvsall //后面替换为你的类
- YourMdiTitle=L"MDI标题可修改";//MDI标题可修改
- HWND parent = ::FindWindowEx(AfxGetMainWnd()-> m_hWnd,NULL, L"MDIClient",NULL);
- HWND child = ::FindWindowEx(parent,NULL,NULL, YourMdiTitle);
- if(NULL == child)
- {
- CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
- CMDIChildWnd* pChildWnd = pMainWnd->CreateNewChild(RUNTIME_CLASS(CMDIChildWnd), IDR_MAINFRAME );
- pChildWnd->SetWindowTextW(YourMdiTitle);//pChildWnd->SetTitle(YourMdiTitle);
- pChildWnd->ShowWindow(SW_MAXIMIZE);
- CCreateContext context;
- context.m_pNewViewClass = RUNTIME_CLASS(YourMdiClass);
- //context.m_pCurrentDoc = this;
- YourMdiClass* pNewView = STATIC_DOWNCAST(YourMdiClass, pChildWnd->CreateView(&context));
- {//你的其他初始化代码
- //
- //pNewView->m_ppPcs=&m_pAll[2];
- //pNewView->m_ppAll=&m_pAll[7];
- }
- //pChildWnd->SetWindowTextW(YourMdiTitle);
- }
- else
- {
- ::BringWindowToTop(child);
- }
转载于:https://blog.51cto.com/hagejid/1059323