把MDI当TAB用

 最近做某个垃圾软件,有些子窗口只想它实例化一个,所以就顺手弄了个垃圾。

原理就是在主窗体找到MDIClient,然后按标题找MDI窗体,不存在实例化一个,存在就顶置它。

 

  
  
  
  
  1. //只实例化一个MDI的代码 
  2.  if(!checkreg()) return
  3.  CString YourMdiTitle; 
  4.  #define YourMdiClass pcsvsall //后面替换为你的类 
  5.  YourMdiTitle=L"MDI标题可修改";//MDI标题可修改 
  6.  HWND parent = ::FindWindowEx(AfxGetMainWnd()-> m_hWnd,NULL, L"MDIClient",NULL);  
  7.  HWND child = ::FindWindowEx(parent,NULL,NULL, YourMdiTitle);  
  8.  if(NULL == child) 
  9.  { 
  10.  CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();  
  11.  CMDIChildWnd* pChildWnd = pMainWnd->CreateNewChild(RUNTIME_CLASS(CMDIChildWnd), IDR_MAINFRAME );  
  12.  pChildWnd->SetWindowTextW(YourMdiTitle);//pChildWnd->SetTitle(YourMdiTitle); 
  13.  pChildWnd->ShowWindow(SW_MAXIMIZE); 
  14.  CCreateContext context;  
  15.  context.m_pNewViewClass = RUNTIME_CLASS(YourMdiClass);  
  16.  //context.m_pCurrentDoc = this;  
  17.  YourMdiClass* pNewView = STATIC_DOWNCAST(YourMdiClass, pChildWnd->CreateView(&context));  
  18.  {//你的其他初始化代码 
  19.  // 
  20.  //pNewView->m_ppPcs=&m_pAll[2]; 
  21.  //pNewView->m_ppAll=&m_pAll[7]; 
  22.  } 
  23.  //pChildWnd->SetWindowTextW(YourMdiTitle); 
  24.  } 
  25.  else 
  26.  { 
  27.  ::BringWindowToTop(child);  
  28.  } 

 

你可能感兴趣的:(MDI)