Me parece que no puede agregar un encabezado de columna para un cuadro de lista en un diálogo MFC heredada. ¿Qué pasa?

StackOverflow https://stackoverflow.com/questions/1573880

  •  21-09-2019
  •  | 
  •  

Pregunta

Tengo hereda una CStdDlg eso es de una clase CDialog. En el cuadro de diálogo CStdDlg, tengo un cuadro de lista (m_lcList1), cuadro de edición (m_ceEdit1), un botón de radio (m_rbButton2) y los botones Aceptar, Cancelar y Button1.

Estoy intentando crear otra clase llamada CDerivedDlg que hereda de CStdDlg. Quiero usar todo en CStdDlg pero desde el CDerivedDlg. Esta es una aplicación de prueba tonto aquí, pero necesito algo exactamente como esta es una aplicación real.

Me voy a mostrar todo el código de abajo. PROBLEMA: El problema sigue bombardeando cada vez que intento añadir un encabezado de columna para el cuadro de lista. m_hWnd = NULL

Puede alguien decirme lo que está mal? Le agradeceria que verdaderamente. Gracias.

// CStdDlg.cpp file

#include "stdafx.h"  
#include "testdlg.h"
#include "StdDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CStdDlg dialog
CStdDlg::CStdDlg(UINT nIDTemplate, CWnd* pParent /*=NULL*/)
    : CDialog(CStdDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CStdDlg)
    //}}AFX_DATA_INIT
}
void CStdDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CStdDlg)
    DDX_Control(pDX, IDC_EDIT1, m_ceEdit1);
    DDX_Control(pDX, IDC_RADIO2, m_rbButton2);
    DDX_Control(pDX, IDC_LIST1, m_lcList1);
    //}}AFX_DATA_MAP
}
IMPLEMENT_DYNAMIC(CStdDlg, CDialog)
BEGIN_MESSAGE_MAP(CStdDlg, CDialog)
    //{{AFX_MSG_MAP(CStdDlg)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStdDlg message handlers
BOOL CStdDlg::OnInitDialog() 
{
    CDialog::OnInitDialog();

    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
}
===================================================================================

//CStdDlg.h file

#if !defined(AFX_STDDLG_H__CDAFF61F_91AB_4B47_9970_6B8BB5DE0003__INCLUDED_)
#define AFX_STDDLG_H__CDAFF61F_91AB_4B47_9970_6B8BB5DE0003__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// StdDlg.h : header file
//
#include <afxwin.h>

/////////////////////////////////////////////////////////////////////////////
// CStdDlg dialog

class CStdDlg : public CDialog
{
    DECLARE_DYNAMIC(CStdDlg)
// Construction
public:

    CStdDlg(UINT nIDTemplate,CWnd* pParent = NULL);   // standard constructor
    CString GetTitle() { 
        CString csTTL;
        GetWindowText(csTTL);
        return csTTL;
    }
// Dialog Data
    //{{AFX_DATA(CStdDlg)
    enum { IDD = IDD_STDDLG };
    CEdit   m_ceEdit1;
    CButton m_rbButton2;
    CListCtrl   m_lcList1;
    //}}AFX_DATA


// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CStdDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL

// Implementation
protected:
    void ShowMsg() { AfxMessageBox("ShowMsg from StdDlg"); }
    // Generated message map functions
    //{{AFX_MSG(CStdDlg)
    virtual BOOL OnInitDialog();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_STDDLG_H__CDAFF61F_91AB_4B47_9970_6B8BB5DE0003__INCLUDED_)

===================================================================================
//CDerivedDlg.cpp file

// StdDlg.cpp : implementation file
//

#include "stdafx.h"
#include "testdlg.h"
#include "CDerivedDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDerivedDlg dialog


CDerivedDlg::CDerivedDlg(CWnd* pParent /*=NULL*/)
    : CStdDlg(CDerivedDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CDerivedDlg)
    //}}AFX_DATA_INIT
}


void CDerivedDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CDerivedDlg)
    //}}AFX_DATA_MAP
}


IMPLEMENT_DYNAMIC(CDerivedDlg, CStdDlg)
BEGIN_MESSAGE_MAP(CDerivedDlg, CStdDlg)
    //{{AFX_MSG_MAP(CDerivedDlg)
    ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDerivedDlg message handlers


//void CDerivedDlg::OnOK() 
//{
//  // TODO: Add extra validation here
//  AfxMessageBox("CDerived Class OK button pressed");
//  CDialog::OnOK();
//}

BOOL CDerivedDlg::OnInitDialog() 
{
    CStdDlg::OnInitDialog();
    SetWindowText("Derived Test Window");
    m_lcList1.InsertColumn(0,"This is a test");    *******THIS IS WHERE IT CRASHES*****


    m_rbButton2.ShowWindow(SW_HIDE);
    m_ceEdit1.ShowWindow(SW_HIDE);



    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
}


void CDerivedDlg::OnButton1() 
{
//  // TODO: Add extra validation here
    AfxMessageBox("CDerived Button1 pressed");
    AfxMessageBox(GetTitle());

}

void CDerivedDlg::OnOK() 
{
    AfxMessageBox("CDerived Class OK button pressed");

}
===================================================================================
// CDerivedDlg.h file

#if !defined(AFX_CDerivedDlg_H__CDAFF61F_91AB_4B47_9970_6B8BB5DE0003__INCLUDED_)
#define AFX_CDerivedDlg_H__CDAFF61F_91AB_4B47_9970_6B8BB5DE0003__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// CDerivedDlg.h : header file
//
#include "StdDlg.h"

/////////////////////////////////////////////////////////////////////////////
// CDerivedDlg dialog

class CDerivedDlg : public CStdDlg
{
    DECLARE_DYNAMIC(CDerivedDlg)
// Construction
public:
    CDerivedDlg(CWnd* pParent = NULL);   // standard constructor
    virtual void SetTTL(CString csTitle) { this->SetWindowText(csTitle); }

// Dialog Data
    //{{AFX_DATA(CDerivedDlg)
    enum { IDD = IDD_STDDLG };
    //}}AFX_DATA


// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CDerivedDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL

// Implementation
protected:

    // Generated message map functions
    //{{AFX_MSG(CDerivedDlg)
    virtual BOOL OnInitDialog();
    afx_msg void OnButton1();
    virtual void OnOK();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_CDerivedDlg_H__CDAFF61F_91AB_4B47_9970_6B8BB5DE0003__INCLUDED_)
===================================================================================
¿Fue útil?

Solución

supongo que desde la DDX_Control () están en la clase base, la clase derivada no vincular los controles de recursos a sus respectivas clases. Es posible que desee para tratar de cambiar esto:

void CDerivedDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);

en esto:

void CDerivedDlg::DoDataExchange(CDataExchange* pDX)
{
    CStdDlg::DoDataExchange(pDX);

Otros consejos

m_lcList1.InsertColumn(0,"This is a test");    *******THIS IS WHERE IT CRASHES*****

Hay que Crear el control antes de que usted será capaz de utilizarlo.
Ver CListCtrl :: Crear y / o CListCtrl :: métodos CreateEx .
Usted debe elegir el estilo LVS_REPORT ya que desea utilizar la lista como un control de vista de informe.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top