首页 新闻 会员 周边

求助,内存泄露

0
悬赏园豆:10 [已解决问题] 解决于 2013-03-01 09:20

刚刚装上boundschecker,运行之后出现了

错误信息

 

整个工作就写了一段代码,

void CMDlg::OnButton1()
{
 // TODO: Add your control notification handler code here
 string stringContentLine;//配置文件中的某一行内容
 char key[30]={0},value[30]={0},title[30]={0},classname[30]={0},context[30]={0};
 int x=0,y=0,width=0,heigh=0;
 int nWid=0,nBtnNum=0;
 int nWidNum=0;
 TCHAR szname[30]={0};
 HWND hwnd=NULL;
 WNDCLASS wndclass;
 unsigned long error=0;

 fstream streamSetting;//配置文件的文件流
 streamSetting.open("config.ini",ios::out|ios::binary|ios::in);
 while(getline(streamSetting, stringContentLine, '\n'))//读取一行数据
 {
  sscanf(stringContentLine.c_str(),"%[^=]=%s",key,value);
  if(strcmp(key,"winnum")==0)
  {
   int n=atoi(value);//循环次数, 窗体数量
   for(int i=0;i<n;i++)
   {
    //读取第一个窗体的属性信息
    //这里也要逐行读取
    while(getline(streamSetting, stringContentLine, '\n'))//读取一行数据
    {
     sscanf(stringContentLine.c_str(),"%[^=]=%s",key,value); 
     if(strcmp(key,value)==0 && strcmp(key,"winstart")==0)
     {
      //开始读取窗体信息
      while(getline(streamSetting, stringContentLine, '\n'))
      {
       sscanf(stringContentLine.c_str(),"%[^=]=%s",key,value); 
       if(strcmp(key,value)==0 && strcmp(key,"winstart")==0)
        continue;
       else if(strcmp(key,value)==0 && strcmp(key,"winend")==0)
        break;
       else if(strcmp(key,"x")==0)
        x=atoi(value);//横坐标
       else if(strcmp(key,"y")==0)
        y=atoi(value);
       else if(strcmp(key,"cx")==0)
        width=atoi(value);
       else if(strcmp(key,"cy")==0)
        heigh=atoi(value);
       else if(strcmp(key,"title")==0)
        strcpy(title,value);
       else if(strcmp(key,"widgetnum")==0)
        nWidNum=atoi(value);
       else if(strcmp(key,"classname")==0)
       {
        //wndclass.lpszClassName=(WCHAR *)_T(value);
        strcpy(classname,value);
       }
      }
      
      CBitmap   bitmap;
      bitmap.LoadBitmap(IDB_BITMAP1);    //这个IDB_BITMAP1要自己添加

      CBrush   brush;
      brush.CreatePatternBrush(&bitmap);

      USES_CONVERSION;
      wndclass.cbClsExtra=0;
      wndclass.cbWndExtra=0;
      wndclass.hbrBackground=brush;
      wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
      wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
      wndclass.hInstance=AfxGetInstanceHandle();
      wndclass.lpfnWndProc=::DefWindowProc;
      wndclass.lpszMenuName=NULL;
      wndclass.style=0;//CS_HREDRAW|CS_VREDRAW
      wndclass.lpszClassName=(LPCTSTR)(LPTSTR)classname;
      RegisterClass(&wndclass);
      //cout<<x<<" "<<y<<" "<<width<<" "<<heigh<<" "<<nWidNum<<endl;
      //跳出循环说明窗体信息已经读取
      //现在就可以直接创建窗体
      //hwnd=::CreateWindow(wndclass.lpszClassName,(WCHAR *)_T(title), WS_OVERLAPPEDWINDOW,x,y,width,this->GetSafeHwnd(),NULL,NULL,NULL);
      hwnd=CreateWindow((LPCSTR)(LPTSTR)classname,(LPCSTR)(LPTSTR)title,WS_OVERLAPPEDWINDOW,x,y,width,heigh,this->GetSafeHwnd(),NULL,NULL,NULL);
      //WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_POPUP
      if(hwnd==NULL)
      {
       error=GetLastError();
      // this->MessageBox((char *)error,NULL,MB_OK);
       
      }
      else
      {
       CRect rect;
       GetWindowRect(&rect);
       ::SetWindowPos(hwnd,this->GetSafeHwnd(),rect.left+3,rect.top+60,rect.Width()-6,rect.Height()-100,SWP_SHOWWINDOW );
   
       
        ::ShowWindow(hwnd,SW_SHOW);
        ::UpdateWindow(hwnd);
       
      }
      //读取控件信息
      CWnd *cwnd=CWnd::FindWindow((LPCSTR)(LPTSTR)classname,(LPCSTR)(LPTSTR)title);
      for(int j=0;j<nWidNum;j++)
      {
       while(getline(streamSetting, stringContentLine, '\n'))//读取一行数据
       {
        sscanf(stringContentLine.c_str(),"%[^=]=%s",key,value);
        if(strcmp(key,"widgetstart")==0 && strcmp(key,value)==0)
         continue;
        else if(strcmp(key,"widgetend")==0 && strcmp(key,value)==0)
         break;
        else if(strcmp(key,"wid")==0)
         nWid=atoi(value);
        else if(strcmp(key,"x")==0)
         x=atoi(value);
        else if(strcmp(key,"y")==0)
         y=atoi(value);
        else if(strcmp(key,"cx")==0)
         width=atoi(value);
        else if(strcmp(key,"cy")==0)
         heigh=atoi(value);
        else if(strcmp(key,"context")==0)
         continue;
       }
       //显示信息
       //cout<<nWid<<" "<<x<<" "<<y<<" "<<width<<" "<<heigh<<" "<<endl;
       if(nBtnNum==0)
        pButton[nBtnNum]->Create(_T("kk"),WS_CHILD|WS_VISIBLE|BS_FLAT|BS_PUSHBUTTON,CRect(x,y,width,heigh),cwnd,nWid);
       else
        pButton[nBtnNum]->Create(_T("ll"),WS_CHILD|WS_VISIBLE|BS_FLAT|BS_PUSHBUTTON,CRect(x,y,width,heigh),cwnd,nWid);
       nBtnNum++;
      }
     }
    }
   }
  }
  //cout<<key<<value<<endl;
  //m[key]=value;
  memset(key,0,30);
  memset(value,0,30);
 }
 streamSetting.close();
}我现在不知道该如何下手,请高手指点。

一枚程序的主页 一枚程序 | 初学一级 | 园豆:108
提问于:2013-02-27 11:09
< >
分享
最佳答案
0

图片是csdn的,是不是不允许盗链?

收获园豆:10
飞来飞去 | 老鸟四级 |园豆:2057 | 2013-02-27 12:12
其他回答(2)
0

看不到图

jerry-Tom | 园豆:4077 (老鸟四级) | 2013-02-27 11:31

重传了,右键显示图片可以看到。

支持(0) 反对(0) 一枚程序 | 园豆:108 (初学一级) | 2013-02-27 11:46
0

这是MFC的框架问题,属于正常现象。

一枚程序 | 园豆:108 (初学一级) | 2013-03-01 09:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册