void CFileView::OnDoubleClick(NMHDR* pNMHDR, LRESULT* pResult) { NMITEMACTIVATE* pNMItem = (NMITEMACTIVATE*)pNMHDR; int nItem = pNMItem->iItem; if (nItem != -1) { ITEMINFO* pItem = (ITEMINFO*)GetListCtrl().GetItemData(nItem); CString strFullPath = m_strPath + "\\" + pItem->strFileName; CFile file; if (file.Open(strFullPath, CFile::modeRead | CFile::typeBinary)) { UINT nFileSize = (UINT)file.GetLength(); char* pBuffer = new (std::nothrow) char[nFileSize]; if (pBuffer) { if (file.Read(pBuffer, nFileSize) > 0) { file.Close(); // Create the dialog CDialog dlg(IDD_DIALOG1, this); // Ensure 'this' is the parent window // Show the dialog // Show the dialog if (dlg.DoModal() == IDOK) { // Handle OK button clicked } else { // Handle dialog closed CEdit* pEditCtrl = (CEdit*)dlg.GetDlgItem(IDC_EDIT1); if (pEditCtrl) { pEditCtrl->SetWindowText(CString(pBuffer, nFileSize)); } else { AfxMessageBox(_T("Failed to get edit control!")); } } } else { delete[] pBuffer; file.Close(); AfxMessageBox(_T("Failed to read file content!"), MB_ICONERROR); } } else { file.Close(); AfxMessageBox(_T("Failed to allocate memory for file content!"), MB_ICONERROR); } } else { AfxMessageBox(_T("Failed to open file!"), MB_ICONERROR); } } *pResult = 0; }
if (dlg.DoModal() == IDOK)
pEditCtrl->SetWindowText(CString(pBuffer, nFileSize));
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)