I have a problem about save Edit text to registy.
I did in main class save to registy text data and i did another registry class that call
CRegSettings so this class doing enum each time when i clicked button like
MyItem\0, MyItem\1.
my problem is i cant get that CString text into this CRegSettings class, this class doesnt have DoDataExchange so when i did it somehow its turn to error "CMySettingsItem::DoDataExchange' : recursive on all control paths" so it's doesnt work and i cant get CString from main class to this class, does anyone know how to do it ? Thanks.
Here is my codes.
Main.cpp
// CNewConnectionDlg dialog
IMPLEMENT_DYNAMIC(CNewConnectionDlg, CDialog)
CNewConnectionDlg::CNewConnectionDlg(CWnd* pParent /*=NULL*/)
: CDialog(CNewConnectionDlg::IDD, pParent)
, m_csIp(_T("localhost"))
, m_csPort(_T("22"))
, m_csUsername(_T("Username"))
, m_csPassword(_T("Password"))
{
}
class CMySettingsItem : public CRegSettings
{
public:
DWORD Id;
CString m_Password;
CString Password;
BEGIN_REG_MAP(CMySettingsItem)
REG_ITEM(Id, 1)
REG_ITEM(Password, m_Password)
END_REG_MAP()
protected:
virtual void DoDataExchange(CDataExchange* pDX);
};
// Sample application configuration
class CMySettings : public CRegSettings
{
public:
DWORD RootId; // DWORD option
CString RootName; // String option
std::string FullName;
// list of options (CMySettingsItem)
CSimpleArray<CMySettingsItem> Profile; // ATL CSimpleArray
//std::list<CMySettingsItem> ProfileList; // STL list
CMySettingsItem SubItem; // Subitem test
BEGIN_REG_MAP(CMySettings)
REG_ITEM(RootId, 1)
REG_ITEM(RootName, "Profile")
REG_ITEM_STL(FullName, "Profile")
REG_ITEM_SIMPLE_ARRAY(Profile)
//REG_ITEM_LIST(ProfileList)
END_REG_MAP()
};
void CMySettingsItem::DoDataExchange(CDataExchange* pDX)
{
CMySettingsItem::DoDataExchange(pDX);
DDX_Text(pDX, IDC_PASSWORD, m_Password);
}
CNewConnectionDlg::~CNewConnectionDlg()
{
AfxGetApp()->WriteProfileString("Settings", "UserName", m_csUsername);
AfxGetApp()->WriteProfileString("Settings", "IP", m_csIp);
AfxGetApp()->WriteProfileString("Settings", "Port", m_csPort);
AfxGetApp()->WriteProfileString("Settings", "Password", m_csPassword);
CMySettings configuration(HKEY_CURRENT_USER, "Software\\MyItem\\Item");
// Load configuration
if(configuration.Load() != ERROR_SUCCESS)
printf("failed to load\n");
// Use loaded configuration
configuration.RootId++;
CMySettingsItem item;
item.Id = configuration.RootId;
configuration.Profile.Add(item); // CSimpleArray
//configuration.ProfileList.push_back(item); // list
// Save new configuration
if(configuration.Save() != ERROR_SUCCESS)
printf("failed to save\n");
}
void CNewConnectionDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_IP, m_csIp);
DDV_MaxChars(pDX, m_csIp, 255);
DDX_Text(pDX, IDC_PORT, m_csPort);
DDV_MaxChars(pDX, m_csPort, 6);
DDX_Text(pDX, IDC_USERNAME, m_csUsername);
DDV_MaxChars(pDX, m_csUsername, 20);
DDX_Text(pDX, IDC_PASSWORD, m_csPassword);
DDV_MaxChars(pDX, m_csPassword, 255);
}
BEGIN_MESSAGE_MAP(CNewConnectionDlg, CDialog)
ON_EN_CHANGE(IDC_PASSWORD, &CNewConnectionDlg::OnEnChangePassword)
ON_EN_CHANGE(IDC_USERNAME, &CNewConnectionDlg::OnEnChangeUsername)
END_MESSAGE_MAP()
void CNewConnectionDlg::OnEnChangePassword()
{
}
void CNewConnectionDlg::OnEnChangeUsername()
{
}
And Header
Main.h
#pragma once
#include "InnerDlg.h"
#include <afxtempl.h>
class CNewConnectionDlg : public CDialog
{
DECLARE_DYNAMIC(CNewConnectionDlg)
public:
CNewConnectionDlg(CWnd* pParent = NULL); // standard constructor
virtual ~CNewConnectionDlg();
CNewConnectionDlg(const CString sSection, const CString sArrayName);
// Dialog Data
enum { IDD = IDD_NEWCONNECTION };
public:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
protected:
DECLARE_MESSAGE_MAP()
public:
// The server ip or name
CString m_csIp;
// The negotiating port on the server
CString m_csPort;
// Username for the server
CString m_csUsername;
// Password for the server
CString m_csPassword;
afx_msg void OnEnChangePassword();
afx_msg void OnEnChangeUsername();
};
DoDataExchange is only intended for user interface classes, such as your CDialog-based class. It is used to connect the user interface elements on screen with the member variables of that object. So your data is sitting in the m_csIp, m_csPort, m_csUsername, and m_csPassword members. You just need to assign it to the relevant member of your CMySettingsItem instance.
For example:
item.m_Password = m_csPassword;
Related
If I try in Visual Studio 2019 run class wizard for some dialog, the error "Failed retrieve controls of dialog 'IDD.....' is shown. But after it is class wizard opened and work properly.
But I am interesting, why it throw this error.
Dialog is inherited from my own class, not from CDialogEx. But My own class is inherited from CDialogEx.
My dialog class code:
#pragma once
#include "resource.h"
#include "CMjAcDialog.h"
// CMjcDlgVyberTrasu dialog
class CMjcDlgVyberTrasu : public CMjAcDialog
{
DECLARE_DYNAMIC(CMjcDlgVyberTrasu)
public:
CMjcDlgVyberTrasu(CWnd* pParent = nullptr); // standard constructor
virtual ~CMjcDlgVyberTrasu();
// Dialog Data
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_VYBER_TRASU };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
vector<CMajTrasa *> *m_pVecOfTrasy;
CListCtrl m_cList;
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedBtUkaz();
virtual BOOL OnInitDialog();
};
And part of my my Dialog Class CMjAcDialog code:
class CMjAcDialog : public CDialogEx
{
DECLARE_DYNAMIC(CMjAcDialog)
protected:
UINT m_IDD;
CMajCtrlMap m_majCtrlMap;
CFont m_Font_mid, m_Font_big;
CString m_csDlgTitle;
HICON m_hIcon;
private:
int m_idMainIcon;
float m_dCurDpiScale;
// konstruktor
public:
CMjAcDialog(UINT idd, CWnd* pParent = NULL, CString acsWinCaption = L"", int idMainIcon = 0);
~CMjAcDialog();
protected:
virtual BOOL OnInitDialog();
.....
....
I am doing a program in MFC and I have come up with an issue. I have a text box created by using the toolbars in Visual Studio.
My text box ID is IDC_TEXT1 and I need to get the value from the text box (float value not string). How do I do it?
You can get the value of by calling GetDlgItemText and std::stod like in this example:
class CAboutDlg : public CDialogEx
{
CString m_txt;
double m_num;
public:
CAboutDlg() noexcept;
// Dialog Data
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_ABOUTBOX };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedOk();
};
CAboutDlg::CAboutDlg() noexcept : CDialogEx(IDD_ABOUTBOX)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
ON_BN_CLICKED(IDOK, &CAboutDlg::OnBnClickedOk)
END_MESSAGE_MAP()
// App command to run the dialog
void CSO55114372App::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
// CSO55114372App customization load/save methods
void CSO55114372App::PreLoadState()
{
BOOL bNameValid;
CString strName;
bNameValid = strName.LoadString(IDS_EDIT_MENU);
ASSERT(bNameValid);
GetContextMenuManager()->AddMenu(strName, IDR_POPUP_EDIT);
bNameValid = strName.LoadString(IDS_EXPLORER);
ASSERT(bNameValid);
GetContextMenuManager()->AddMenu(strName, IDR_POPUP_EXPLORER);
}
void CSO55114372App::LoadCustomState()
{
}
void CSO55114372App::SaveCustomState()
{
}
// CSO55114372App message handlers
void CAboutDlg::OnBnClickedOk()
{
GetDlgItemText(IDC_EDIT2, m_txt);
std::wstring s((LPCTSTR)m_txt);
m_num = std::stod(s);
CDialogEx::OnOK();
}
I just wanted to show you a second way of mapping a edit control to a float value. This is by using the ClassWizard.
Right-click the control and choose Add Variable...:
Set the variable category as value, the access to private, specify the name and finally set the variable type to float.
Click Next (if required) and set the numeric range for input.
Click Finish
Look at the DoDataExchange method. It will look something like this:
void CMFCApplication2Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, m_fValue);
DDV_MinMaxFloat(pDX, m_fValue, 1, 100);
}
Whenever you need to work with the current value of the edit control, you type UpdataData(TRUE); This synchronises the variable with the contents of the edit control. An example with a break-point in debug mode:
I have a lot of CDialogEx derived classes that do something like this in OnInitDialog:
CMeetingScheduleAssistantApp::InitialiseResizeIcon(m_bmpResize, m_lblResize, this);
CMeetingScheduleAssistantApp::RestoreWindowPosition(_T("PublisherDB"), this, true);
Then, I have the following added to each derived dialog class:
int CPublishersDatabaseDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialogEx::OnCreate(lpCreateStruct) == -1)
return -1;
// Save Initial window size to m_rcInit
GetWindowRect(&m_rcInit);
return 0;
}
void CPublishersDatabaseDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
// Set the minimum window size to initial size.
lpMMI->ptMinTrackSize.x = m_rcInit.Width();
lpMMI->ptMinTrackSize.y = m_rcInit.Height();
CDialogEx::OnGetMinMaxInfo(lpMMI);
}
void CPublishersDatabaseDlg::OnClose()
{
CMeetingScheduleAssistantApp::SaveWindowPosition(_T("PublisherDB"), this);
CDialogEx::OnClose();
}
The only thing that is different for each dialog is the phrase that is used for saving the window position.
I want to have a based CDialogEx class that I can inherit from that will perform the above actions. I have looked on SO and seem some questions and creating a CDialog class and inheriting from another CDialog class. But this class I want to create is more generic. Effectively to be used as a base instead of CDialogEx.
Can this be done? Am I over-complicating this?
Problems
Why I try to create a new class, derived from CDialogEx:
I don't know if it is because it requires a dialog ID as stated here.
Classes such as CDialog, CFormView, or CPropertyPage, which require a dialog ID.
So I can't work out the correct way to create a base CDialogEx class for use in all my other dialog classes.
Update
I created this code and it tells me that CResizingDialog is not a class or a namespace:
#include "ResizingDialog.h"
#include "resource.h"
#include "stdafx.h"
IMPLEMENT_DYNAMIC(CResizingDialog, CDialogEx)
CResizingDialog::CResizingDialog(const CString& strWindowID, UINT nIDTemplate, CWnd* pParent = nullptr)
: m_strWindowID(strWindowID), CDialogEx(nIDTemplate, pParent)
{
}
CResizingDialog::~CResizingDialog()
{
}
void CResizingDialog::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CResizingDialog, CDialogEx)
ON_WM_CREATE()
ON_WM_GETMINMAXINFO()
ON_WM_CLOSE()
END_MESSAGE_MAP()
int CResizingDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialogEx::OnCreate(lpCreateStruct) == -1)
return -1;
// Save Initial window size to m_rcInit
GetWindowRect(&m_rcInit);
return 0;
}
void CResizingDialog::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
// Set the minimum window size to initial size.
lpMMI->ptMinTrackSize.x = m_rcInit.Width();
lpMMI->ptMinTrackSize.y = m_rcInit.Height();
CDialogEx::OnGetMinMaxInfo(lpMMI);
}
void CResizingDialog::OnClose()
{
SaveWindowPosition(m_strWindowID, this);
CDialogEx::OnClose();
}
Based on the comments encouraging me to try to create the class manually, I have it working:
#include "stdafx.h"
#include "resource.h"
#include "ResizingDialog.h"
IMPLEMENT_DYNAMIC(CResizingDialog, CDialogEx)
CResizingDialog::CResizingDialog(const CString& strWindowID, UINT nIDTemplate, CWnd* pParent /* nullptr */, bool bOnlyStorePosition /* false */)
: m_strWindowID(strWindowID),
m_bOnlyStorePosition(bOnlyStorePosition), CDialogEx(nIDTemplate, pParent)
{
}
CResizingDialog::~CResizingDialog()
{
}
void CResizingDialog::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CResizingDialog, CDialogEx)
ON_WM_CREATE()
ON_WM_GETMINMAXINFO()
ON_WM_CLOSE()
END_MESSAGE_MAP()
int CResizingDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialogEx::OnCreate(lpCreateStruct) == -1)
return -1;
// Save Initial window size to m_rcInit
GetWindowRect(&m_rcInit);
return 0;
}
void CResizingDialog::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
// Set the minimum window size to initial size.
lpMMI->ptMinTrackSize.x = m_rcInit.Width();
lpMMI->ptMinTrackSize.y = m_rcInit.Height();
CDialogEx::OnGetMinMaxInfo(lpMMI);
}
void CResizingDialog::OnClose()
{
SaveWindowPosition(m_strWindowID, this);
CDialogEx::OnClose();
}
void CResizingDialog::OnOK()
{
SaveWindowPosition();
CDialogEx::OnOK();
}
BOOL CResizingDialog::OnInitDialog()
{
CDialogEx::OnInitDialog();
if(!m_bOnlyStorePosition)
InitialiseResizeIcon(m_bmpResize, m_lblResize, this);
RestoreWindowPosition(m_strWindowID, this, true);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
I decided to duplicate the methods that were in the app class into this new dialog class instead. Eventually they can be removed from the app class. The only thing I also had to do was #include my resource file because the image needs to know the value of the resource ID.
This is the ResizingDialog.h header:
#pragma once
#include <afxwin.h>
class CResizingDialog : public CDialogEx
{
DECLARE_DYNAMIC(CResizingDialog)
public:
CResizingDialog(const CString& phrase, UINT nIDTemplate, CWnd* pParent = nullptr, bool bOnlyStorePosition = false); // Constructor
virtual ~CResizingDialog(); // Destructor
protected:
void OnOK() override;
virtual void DoDataExchange(CDataExchange* pDX) override; // DDX/DDV support
void SaveWindowPosition(void) { SaveWindowPosition(m_strWindowID, this); }
public:
BOOL OnInitDialog() override;
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI);
afx_msg void OnClose();
DECLARE_MESSAGE_MAP()
private:
CBitmap m_bmpResize;
CStatic m_lblResize;
CRect m_rcInit;
CString m_strWindowID;
bool m_bOnlyStorePosition;
void RestoreWindowPosition(CString strWindow, CWnd* pWindow, bool bOverrideState = false);
void SaveWindowPosition(CString strWindow, CWnd* pWindow);
void InitialiseResizeIcon(CBitmap& rBmpResize, CStatic& rLblResize, CWnd* pDialog);
};
The actual functions SaveWindowPosition, RestoreWindowPosition and InitialiseResizeIcon are not shown here as they don't directly relate to the issue.
I am trying to create CWnd derived class at runtime but CWnd::Create fails. I have no idea why. Here is minimal code that show the problem:
MFCTestApplicationDlg.h
#pragma once
class c_CustomButton : public CButton
{
protected:
DECLARE_MESSAGE_MAP()
virtual void PreSubclassWindow();
public:
c_CustomButton();
virtual ~c_CustomButton();
};
class TestWindow : public CWnd
{
public:
TestWindow();
virtual ~TestWindow();
protected:
DECLARE_MESSAGE_MAP()
DECLARE_DYNCREATE(TestWindow)
};
// CMFCTestApplicationDlg dialog
class CMFCTestApplicationDlg : public CDialogEx
{
...
}
MFCTestApplicationDlg.cpp
//
#include "stdafx.h"
#include "MFCTestApplication.h"
#include "MFCTestApplicationDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
/*==========================================================================*/
c_CustomButton::c_CustomButton()
{
}
/*==========================================================================*/
c_CustomButton::~c_CustomButton()
{
}
BEGIN_MESSAGE_MAP(c_CustomButton, CButton)
END_MESSAGE_MAP()
/*==========================================================================*/
void c_CustomButton::PreSubclassWindow()
{
CButton::PreSubclassWindow();
ModifyStyle(0, BS_OWNERDRAW);
}
IMPLEMENT_DYNAMIC(TestWindow, CWnd)
TestWindow::TestWindow()
{
}
TestWindow::~TestWindow()
{
}
BEGIN_MESSAGE_MAP(TestWindow, CWnd)
END_MESSAGE_MAP()
void CMFCTestApplicationDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
c_CustomButton* pColoredButton = new c_CustomButton;
pColoredButton->Create((LPCTSTR)"", 0, CRect(), this, 0);// successeded
pColoredButton->SetWindowTextW((LPCTSTR)"test");
TestWindow* pTestWindow = new TestWindow;
pTestWindow->Create((LPCTSTR)"TestWindow", (LPCTSTR)"TestWindowName", 0, CRect(), this, 0);// failed
pTestWindow->SetWindowText((LPCTSTR)"test");
}
In void CMFCTestApplicationDlg::DoDataExchange(CDataExchange* pDX) I tried to create a CButton derived class object and CWnd derived class object. The first one created successfully but CWnd derived class object fails to create. Whats wrong with this code?
I have a CStdDlg thats inherits from a CDialog class. In the CStdDlg dialog, I have a list box (m_lcList1), edit box (m_ceEdit1), a radio button(m_rbButton2) and buttons OK, Cancel and Button1.
I am trying to create another class named CDerivedDlg that inherits from CStdDlg. I want to use everything in CStdDlg but from the CDerivedDlg.
This is a silly test application here, but I need something exactly like this is a real application.
I'll show all the code below. PROBLEM: The problem keeps bombing whenever I try to add a column header to the list box. m_hWnd = NULL
Can anyone tell me what's wrong? I would truly appreciate it. Thank you.
// 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_)
===================================================================================
I'm guessing that since the DDX_Control() are on the base class, the derived class will not link the resource controls to their respective classes. You might want to try to change this:
void CDerivedDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
into this:
void CDerivedDlg::DoDataExchange(CDataExchange* pDX)
{
CStdDlg::DoDataExchange(pDX);
m_lcList1.InsertColumn(0,"This is a test"); *******THIS IS WHERE IT CRASHES*****
You have to create the control before you'll be able to use it.
See CListCtrl::Create and/or CListCtrl::CreateEx methods.
You must choose the LVS_REPORT style since you want to use the list as a report view control.