Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
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;
}


What I have tried:

I have tried this and many ways but in file view when iam clicking file it should display content in bottomview in dialog box iam not unable to get it resolve and give the correct code.
Posted
Updated 21-Apr-24 21:27pm
v2

1 solution

You called:
if (dlg.DoModal() == IDOK) 

after that call you set
pEditCtrl->SetWindowText(CString(pBuffer, nFileSize));

this must be done before (!) the dialog will be shown (DoModal).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900