2 qq 26242161 qq_26242161 于 2016.09.06 18:18 提问

vc6升级为vs10出现Debug

求大神解答,vc6升级为vs10,出现Debug Assersion Failed afxwin2.inl line752,查了可能是控件listbox的原因
ON_COMMAND(IDC_ADD_FILE,OnAddAllFiles)
ON_COMMAND(IDC_ADD,OnAddOneFile)
ON_COMMAND(IDC_DEL,OnDelOneFile)
ON_COMMAND(IDC_DEL_FILE,OnDelAllFiles)
ON_LBN_DBLCLK(IDC_SOURCE_FILE_LIST, OnDblclkSourceFileList)
ON_LBN_DBLCLK(IDC_AIM_FILE_LIST, OnDblclkAimFileList)
ON_BN_CLICKED(IDC_OK, OnFileOpen)
ON_BN_CLICKED(IDC_CANCEL,OnExit)
ON_WM_SIZE()
END_MESSAGE_MAP()

CMyOpenDlg::CMyOpenDlg() : CFileDialog(TRUE,
NULL, // no default extension
NULL, // ..or file name
OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT,
_T("原始数据 (*.TT)|*.TT|自动测桩文件 (*.ZT)|*.ZT|测桩结果文件(*.SP)|*.SP||"))
{
GetProfileString("Path","1","",cPath,100);

m_Path = cPath;
m_ofn.lpstrTitle = _T("请选择文件或文件夹");

strcpy_s(cPath,m_Path);
m_ofn.lpstrInitialDir=cPath;
char filter[10];
GetProfileString("FILTER","1","",filter,100);   
m_ofn.nFilterIndex = atoi(filter);
m_bPreVer=FALSE;

}
BOOL CMyOpenDlg::m_bFirst=TRUE;
BOOL CMyOpenDlg::OnInitDialog()
{
// subclass controls...
m_ListBox1.SubclassDlgItem(IDC_SOURCE_FILE_LIST, this);
m_ListBox2.SubclassDlgItem(IDC_AIM_FILE_LIST, this);
CWnd * pWnd = FindWindow(NULL,"请选择文件或文件夹");
CString sCtrlName;
CWnd pedit;
CWnd
pStatic;
CString filename;
TCHAR BUF[512];
CString sPath;
CString strText;
m_dlghelper.Init(this);
int count=0;
if(pWnd)
{
CWnd *pwnd=pWnd->GetWindow(GW_CHILD);//枚举保存对话框的所有子控件
char buf[512];
while(pwnd!=NULL)
{
::GetClassName(pwnd->GetSafeHwnd(),buf,512);//得到枚举的控件是什么类型的,
CString str=buf;

str.TrimRight();
if(str=="Edit")//如果枚举到保存文件名的EDIT
{
pedit=pwnd;//保存EDIT句柄用来发消息
pedit->ShowWindow(SW_HIDE);
filename=BUF;//完成第一步保存原始的文件名
}
if(str=="Static")
{
pStatic = pwnd;
pStatic->GetWindowText(strText);
if(strText=="文件名(&N):")
{
pStatic->ShowWindow(SW_HIDE);
}
if(strText=="文件类型(&T):")
{
pwnd->MoveWindow(10,185,100,30,TRUE);

           }
        }
        if(str=="ComboBox")
        {
            count++;
            if(count==2)
            {
                pwnd->MoveWindow(90,180,320,200,TRUE);
            }
        }           
        if(str=="Button")//枚举到按钮,有保存和取消按钮
        {
            pwnd->GetWindowText(strText);
            if(strText=="打开(&O)")//如果是保存按钮
            {   
                pwnd->ShowWindow(SW_HIDE);
            }
            if(strText=="取消")//如果是保存按钮
            {   
                pwnd->ShowWindow(SW_HIDE);
            }

        }
        if(str=="ListBox")
        {
    //      pwnd->SendMessage(WM_GETTEXT,sizeof(BUF)/sizeof(TCHAR),(LPARAM)(void*)BUF);
        }
        pwnd = pwnd->GetNextWindow();
    }

}
m_bOpen = FALSE;


if (m_bFirst)
{
    CButton* CheckPole = (CButton*)GetDlgItem(IDC_CHECK_POLE);
    CheckPole->SetCheck(1);
}
else
{
    CButton* CheckPole = (CButton*)GetDlgItem(IDC_CHECK_POLE);
    CheckPole->SetCheck(0);
}
UpdateData(FALSE);
return CFileDialog::OnInitDialog();

}
void CMyOpenDlg::OnTypeChange()
{
ShowFileInfo();
}

////////////////// CDM_GETFILEPATH
// Common helper: show information in the preview and debug panes
//
void CMyOpenDlg::ShowFileInfo()
{
CFileDlgHelper& fdh = m_dlghelper;
// m_ofn.lpstrInitialDir = cPath;
CString path = GetPathName();
CString fldr = GetFolderPath();
CString flext = GetFileExt();
int nFilterIndex = m_ofn.nFilterIndex;
int nSelected = 0;
int ncount=m_ListBox1.GetCount();
int i=0;
for(i=0;i<ncount;i++)
{
m_ListBox1.DeleteString(0);
}
path = fldr+"\";
m_Path = path;
CString strFilePath;
switch(nFilterIndex)
{
case 1:
{
strFilePath = "*.TT";
strFilePath=path+strFilePath;
CFileFind m_strFile;
CString strShowFiles;
i=0;
BOOL bFinished=m_strFile.FindFile(strFilePath);
while(bFinished)

{
bFinished=m_strFile.FindNextFile();
strShowFiles=m_strFile.GetFileName();
m_ListBox1.InsertString(i,strShowFiles);
i++;
}
break;
}
case 2:
{
strFilePath = "*.ZT";
strFilePath=path+strFilePath;
CFileFind m_strFile;
CString strShowFiles;
i=0;
BOOL bFinished=m_strFile.FindFile(strFilePath);
while(bFinished)

{
bFinished=m_strFile.FindNextFile();
strShowFiles=m_strFile.GetFileName();
m_ListBox1.InsertString(i,strShowFiles);
i++;
}
break;
}
case 3:
{
strFilePath = "*.SP";
strFilePath=path+strFilePath;
CFileFind m_strFile;
CString strShowFiles;
i=0;
BOOL bFinished=m_strFile.FindFile(strFilePath);
while(bFinished)

{
bFinished=m_strFile.FindNextFile();
strShowFiles=m_strFile.GetFileName();
m_ListBox1.InsertString(i,strShowFiles);
i++;
}
break;
}
}
}

//////////////////
// Preview: Read first 256 characters of text file
//
CString CMyOpenDlg::GetTextPreview(LPCTSTR pszPath)
{
CString buf;
CFile f;
if (f.Open(pszPath,CFile::modeRead)) {
int len = f.Read(buf.GetBuffer(256),256);
buf.ReleaseBuffer();
if (len==256)
buf += "...";
}
return buf;
}

//////////////////
// Helper adds text to an edit control that I've added to the open dialog
//
void CMyOpenDlg::AddText(CEdit& wndEdit, LPCTSTR lpText, BOOL bClear)
{
if (wndEdit) {
// Convert \n to \n\r for Windows brain-damaged edit control !&#%!
// It's 2001, and I'm still writing code like this!
//
LPCTSTR src = lpText;

    TCHAR buf[1024];
    TCHAR* dst = buf;
    TCHAR* endbuf = buf + sizeof(buf) - 1;

    while (*src && dst < endbuf) {
        if (*src == '\n')
            *dst++ = '\r';
        *dst++ = *src++;
    }
    *dst = 0;

    wndEdit.SetSel(bClear ? 0 : -1, -1); // end of edit text
    wndEdit.ReplaceSel(buf);                    // append string..
    wndEdit.SendMessage(EM_SCROLLCARET);    // ..and show caret
}

}

//////////////////
// Dialog was sized: reposition my controls. Zzzzz.
//

void CMyOpenDlg::OnAddAllFiles()
{
CString FileName;
int iNum = m_ListBox1.GetCount();
for(int i = 0; i < iNum; i++)
{
m_ListBox1.GetText(i,FileName);
m_ListBox2.AddString(FileName);
}

}
void CMyOpenDlg::OnAddOneFile()
{
if(!m_ListBox1.GetSelCount())
{
MessageBox("您还没选择要添加的文件,请选择......","提示",MB_OK | MB_ICONEXCLAMATION | MB_ICONWARNING);
return;
}

int iNum = m_ListBox1.GetCurSel();
CString FileName;
if(iNum>=0)
{
    m_ListBox1.GetText(iNum,FileName);
    m_ListBox2.AddString(FileName);
}

//相同桩号文件打开
CButton* CheckPole = (CButton*)GetDlgItem(IDC_CHECK_POLE);
if (CheckPole->GetCheck())
{
    if (m_ofn.nFilterIndex==3)
    {
        return;
    }
    OnDelAllFiles();
    CString filename,filename1;
    int currentnum = m_ListBox1.GetCurSel();
    if (currentnum>=0)
    {
        m_ListBox1.GetText(currentnum,filename1);
        CString pathname;
        pathname=m_Path+filename1;
        TestDataBody* head=new TestDataBody;
        if (m_ofn.nFilterIndex==1)
        {
            CFile hFile(pathname, CFile::modeRead);
            TT_FILE_HEAD m_TtFileHead;
            ReadTTFile(&m_TtFileHead, &hFile);
        }
        if (m_ofn.nFilterIndex==2)
        {
            ReadFromZtFile(head,pathname);
        }

        filename=m_Filename;
    }
    int num = m_ListBox1.GetCount();
    for(int i=0;i<num;i++)
    {
        m_ListBox1.GetText(i,filename1);
        CString pathname;
        pathname=m_Path+filename1;
        TestDataBody* head=new TestDataBody;
        if (m_ofn.nFilterIndex==1)
        {
            CFile hFile(pathname, CFile::modeRead);
            TT_FILE_HEAD m_TtFileHead;
            ReadTTFile(&m_TtFileHead, &hFile);
        }
        if (m_ofn.nFilterIndex==2)
        {
            ReadFromZtFile(head,pathname);
        }

        if (filename==m_Filename)
        {
            if (m_bPreVer&&m_ofn.nFilterIndex==1)
            {
                m_ListBox1.GetText(currentnum,filename1);
                m_ListBox2.AddString(filename1);
                break;
            }
            m_ListBox2.AddString(filename1);
        }
    }
}

}
}
void CMyOpenDlg::AddFiles(CString FilePath)
{
}
void CMyOpenDlg::OnDblclkSourceFileList()
{
if(!m_ListBox1.GetSelCount())
{
MessageBox("您还没选择要添加的文件,请选择......","提示",MB_OK | MB_ICONEXCLAMATION | MB_ICONWARNING);
return;
}

int iNum = m_ListBox1.GetCount();
CString FileName;
CString FileFullName;
CString CurDir;
CButton* CheckPole = (CButton*)GetDlgItem(IDC_CHECK_POLE);
for(int i = 0; i < iNum; i++)
{
    if(m_ListBox1.GetSel(i))
    {
        m_ListBox1.GetText(i,FileName);
        m_ListBox2.AddString(FileName);
        if (CheckPole->GetCheck())
        {
            if (m_ofn.nFilterIndex==3)
            {
                OnDelAllFiles();
            }
            OnAddOneFile();
        }
    }
}   

}

void CMyOpenDlg::OnDblclkAimFileList()
{
int iNum = 0;
int iFileNum =m_ListBox2.GetCount();
if(!iFileNum)
return;
iNum=m_ListBox2.GetCurSel();
if( iNum < 0)
{
MessageBox("您没有选择要删除的文件,请选择......","提示",MB_OK | MB_ICONEXCLAMATION | MB_ICONWARNING);
return;
}
m_ListBox2.DeleteString(iNum);

}

void CMyOpenDlg::OnFileOpen()
{
CString strFileName;
if(m_ListBox2.GetCount()<=6&&m_ListBox2.GetCount()>0)
{
for(int i=0;i<10;i++)
{
m_OpenFilePath[i]="";
}
for(int i=0;i<m_ListBox2.GetCount();i++)
{
m_ListBox2.GetText(i,strFileName);
m_OpenFilePath[i]=m_Path+strFileName;
}
SavePath();
m_bOpen = TRUE;

    if (IsDlgButtonChecked(IDC_CHECK_POLE))//判断是否选择相同桩号 2009.12.15
    {
        m_bFirst=TRUE;
    }
    else
    {
        m_bFirst=FALSE;
    }

    this->GetParent()->PostMessage(WM_CLOSE,0,0);
}
else
{
    AfxMessageBox("请确认在[打开文件列表]中的文件个数在1~6个!");
}

}
INT_PTR CMyOpenDlg::DoModal()
{
// TODO: 在此添加专用代码和/或调用基类
m_ofn.lpTemplateName = MAKEINTRESOURCE(IDD_FILEOPEN);
m_ofn.Flags |= OFN_ENABLETEMPLATE;
return CFileDialog::DoModal();
}

1个回答

dabocaiqq
dabocaiqq   2017.02.13 23:55
Csdn user default icon
上传中...
上传图片
插入图片