I am new to MFC and in below code OnPaint() is not invoked.
//TestWnd.H
#ifndef TESTWND
#define TESTWND
#include<afxwin.h>
//window
class TestWnd:public CFrameWnd
{
public:
TestWnd();
protected:
afx_msg void onPaint();
DECLARE_MESSAGE_MAP()
};
#endif
//TestWnd.cpp
#include"TestWnd.h"
TestWnd::TestWnd()
{
Create (NULL, _T ("The Hello Application"),
WS_OVERLAPPEDWINDOW,
CRect(120, 100, 700, 480), NULL);
}
void TestWnd ::onPaint()
{
MessageBox(_T("The window has been PAINTED!!!"));
//CPaintDC dc(this);
//CRect crec;
//GetClientRect(&crec);
//dc.DrawText(_T("Hello"),-1, &crec, DT_SINGLELINE/* | DT_CENTER | DT_VCENTER*/);
}
BEGIN_MESSAGE_MAP(TestWnd,CFrameWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
//TestApp.h
#ifndef TESTAPP
#define TESTAPP
#include<afxwin.h>
class TestApp:public CWinApp
{
public:
virtual BOOL InitInstance();
};
#endif
//TestApp.cpp
#include "TestApp.h"
#include "TestWnd.h"
TestApp g_obj;
BOOL TestApp::InitInstance()
{
m_pMainWnd = new TestWnd;
m_pMainWnd->ShowWindow(m_nCmdShow);
//m_pMainWnd->UpdateWindow();
return TRUE;
}
The reason is very simple.
ON_WM_PAINT requires a handler named OnPaint. You implemented a handler named onPaint. Because there is a default implementation the default CFrameWnd::OnPaint is called.
Rename your handler to OnPaint.
Related
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 updating some old software that does not work on Win7 or later. so, I am rebuilding some MFC libraries that are using latest win32 updates.
Now I have two issues:
MessageBox appears behind the CFrameWnd so it can't be accessed sending the application to halt.
Open dialog box (whether is based on CFileDialog or IFileDilog) does not get refreshed when changing the file type.
However, both problems are solved if the CFrameWnd is hidden. or, in case of MessageBox, you will not need to hide the window if you write: PostMessage(0x118); which in fact I don't know why.
There must be something I am missing Here.
I also Have another problem when using the OpenFileDialog class that inherits from the IFileDialog. is when closing this dialog without picking up a file, the application Crashes.
//--targetver.h
#pragma once
#include <sdkddkver.h>
//--stdafx.h:
#ifndef CS_EXTRALEAN
#define CS_EXTRALEAN
#endif
#pragma once
#include "targetver.h"
#include<afxwin.h>
#include<afxext.h>
#include<afxcmn.h>
//--stdafx.cpp
#include "stdafx.h"
//--CMainWnd.h
#pragma once
class CMainWnd : public CFrameWnd
{
public:
CMainWnd();
~CMainWnd();
afx_msg void OnPaint();
afx_msg void OnLButtonDown(UINT, CPoint);
DECLARE_MESSAGE_MAP()
};
//--CMainWnd.cpp
#include "stdafx.h"
#include"CMainWnd.h"
BEGIN_MESSAGE_MAP(CMainWnd, CFrameWnd)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
CMainWnd::CMainWnd()
: CFrameWnd()
{
CString class_name = AfxRegisterWndClass(
CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS,
AfxGetApp()->LoadStandardCursor(IDC_ARROW),
(HBRUSH)::GetStockObject(BLACK_BRUSH),
AfxGetApp()->LoadStandardIcon(IDI_ASTERISK));
HRESULT hResult = this->Create(
class_name,
L"This is CMainWnd",
WS_OVERLAPPEDWINDOW,
this->rectDefault,
NULL,
NULL,
0,
NULL);
}
CMainWnd::~CMainWnd() { }
void CMainWnd::OnPaint()
{ }
void CMainWnd::OnLButtonDown(UINT, CPoint)
{
MessageBox(L"HELLO MFC", L"MFC", MB_OK);
}
//--CAppWnd.h
#pragma once
class CAppWnd : public CWinApp
{
public:
CAppWnd();
~CAppWnd();
BOOL InitInstance();
DECLARE_MESSAGE_MAP()
};
//--CAppWnd.cpp
#include "stdafx.h"
#include "CAppWnd.h"
#include "CMainWnd.h"
BEGIN_MESSAGE_MAP(CAppWnd, CWinApp)
END_MESSAGE_MAP()
CAppWnd::CAppWnd()
:CWinApp()
{ }
CAppWnd::~CAppWnd()
{ }
BOOL CAppWnd::InitInstance()
{
this->m_pMainWnd = new CMainWnd;
this->m_pMainWnd->ShowWindow(m_nCmdShow);
return CWinApp::InitInstance();
}
CAppWnd The_App;
There was a simple problem. You override OnPaint but didn't call the default procedure. OnPaint handles to WM_PAINT message, it doesn't forgive this error.
void CMainWnd::OnPaint()
{
CFrameWnd::OnPaint(); //<= this was missing
//custom paint...
//CClientDC dc(this);
//dc.TextOut(0, 0, L"test");
//dc is automatically released...
}
Or you can use CPaintDC which is a wrapper for BeginPaint/EndPaint API
void CMainWnd::OnPaint()
{
CPaintDC dc(this);
//custom paint...
//dc.TextOut(0, 0, L"test");
//dc is automatically released...
}
If you don't do any painting in this frame window then remove the whole CMainWnd::OnPaint() function and the correspoonding ON_WM_PAINT message.
Above change should fix your error. I would rewrite the rest of the code so it calls the default override first. Example:
#include "stdafx.h"
#include "resource.h"
class CMainWnd : public CFrameWnd
{
public:
CMainWnd();
~CMainWnd();
afx_msg void OnPaint();
afx_msg void OnLButtonDown(UINT, CPoint);
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CMainWnd, CFrameWnd)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
CMainWnd::CMainWnd() : CFrameWnd() {}
CMainWnd::~CMainWnd() {}
void CMainWnd::OnPaint()
{
CFrameWnd::OnPaint();
}
void CMainWnd::OnLButtonDown(UINT f, CPoint pt)
{
CFrameWnd::OnLButtonDown(f, pt);
CFileDialog dlg(TRUE, 0, 0, 0,
L"All files|*.*|"
L"Text files|*.txt;*.txt||" , this);
if (dlg.DoModal() == IDOK)
MessageBox(dlg.GetPathName(), L"MFC", MB_OK);
}
class CAppWnd : public CWinApp
{
public:
BOOL InitInstance();
};
BOOL CAppWnd::InitInstance()
{
CWinApp::InitInstance();
CMainWnd *frame = new CMainWnd;
CString class_name = AfxRegisterWndClass(
CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS,
AfxGetApp()->LoadStandardCursor(IDC_ARROW),
(HBRUSH)::GetStockObject(BLACK_BRUSH),
AfxGetApp()->LoadStandardIcon(IDI_ASTERISK));
frame->Create(class_name, L"This is CMainWnd",
WS_OVERLAPPEDWINDOW, CFrameWnd::rectDefault, NULL, NULL, 0, NULL);
frame->ShowWindow(m_nCmdShow);
m_pMainWnd = frame;
return TRUE;
}
CAppWnd The_App;
Note that you can call up static members directly, for example CFrameWnd::rectDefault, it doesn't cause an error either way but it makes the code more clear.
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 created new emty project. Then have added cpp and header hello world files taken from Jeff Prosise 'Programming Windows with MFC' book. Have set Use of MFC to Use MFC in a Shared DLL
Got error entry point must be defined
How to fix this problem?
CPP:
#include <afxwin.h>
#include "Hello.h"
CMyApp myApp;
/////////////////////////////////////////////////////////////////////////
// CMyApp member functions
BOOL CMyApp::InitInstance ()
{
m_pMainWnd = new CMainWindow;
m_pMainWnd->ShowWindow (m_nCmdShow);
m_pMainWnd->UpdateWindow ();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////
// CMainWindow message map and member functions
BEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd)
ON_WM_PAINT ()
END_MESSAGE_MAP ()
CMainWindow::CMainWindow ()
{
Create (NULL, _T ("The Hello Application"));
}
void CMainWindow::OnPaint ()
{
CPaintDC dc (this);
CRect rect;
GetClientRect (&rect);
dc.DrawText (_T ("Hello, MFC"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
H:
class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance ();
};
class CMainWindow : public CFrameWnd
{
public:
CMainWindow ();
protected:
afx_msg void OnPaint ();
DECLARE_MESSAGE_MAP ()
};
You need to tell compiler to use WinMain (which is provided by MFC: http://msdn.microsoft.com/en-us/library/akdx0603.aspx) instead of main as an entry point.
Right click project, select Properties, and navigate to Linker -> System -> SubSystem. Change SubSystem to Windows.
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.