How to override CWinDataExchange
-
I tried this:
template class CWinDataExchangeEx :
public CWinDataExchange
{
public:
// my new DDX functions here...Then I have the dialog class is derived from CWinDataExchangeEx. But now none of the base class DDX routines get called anymore, only my new one's in the Ex class?!
-
I tried this:
template class CWinDataExchangeEx :
public CWinDataExchange
{
public:
// my new DDX functions here...Then I have the dialog class is derived from CWinDataExchangeEx. But now none of the base class DDX routines get called anymore, only my new one's in the Ex class?!
An example of the code that doesn't work as you expect would help...as well as a clear statement of exactly what you expected. If you (for example) added a new overload of
DDX_Text
, then the definition ofDDX_Text
in your class will hide the definitions in the base class. To fix this, you'd add the following line to your CWinDataExchangeEx class:using CWinDataExchange<T>::DDX_Text;
-
An example of the code that doesn't work as you expect would help...as well as a clear statement of exactly what you expected. If you (for example) added a new overload of
DDX_Text
, then the definition ofDDX_Text
in your class will hide the definitions in the base class. To fix this, you'd add the following line to your CWinDataExchangeEx class:using CWinDataExchange<T>::DDX_Text;
this is my added code (I am trying to implement a DDX_CBSTRING function ala MFC): (in my atlddx2.h)
namespace WTL
{#define DDX_CBSTRING(nID, var) \
if(nCtlID == (UINT)-1 || nCtlID == nID) \
{ \
if(!DDX_CBString(nID, var, sizeof(var), bSaveAndValidate)) \
return FALSE; \
}template <class T>
class CWinDataExchangeEx : public CWinDataExchange<T>BOOL DDX\_CBString(UINT nID, \_CSTRING\_NS::CString& value, int /\*cbSize\*/, BOOL bSave /\*, BOOL bValidate = FALSE\*, int nLength = 0\*/) { // implementation here..... }
};
}; // namespace WTL
then on the dialog class:
#include "atlddx2.h"
class CScaleEditDlg :
public CDialogImpl<CScaleEditDlg>,
public CWinDataExchangeEx<CScaleEditDlg>
{
// .....
BEGIN_DDX_MAP(CScaleEditDlg)
DDX_CBSTRING(IDC_SCALE_MODEL, m_strModel)
DDX_TEXT(IDC_SCALE_DESCRIPTION, m_strDescription)
DDX_INT_RANGE(IDC_SCALE_SA, m_nStationAddress, 0, 999)
DDX_CONTROL_HANDLE(IDC_SCALE_IMAGE, m_ctlImage)
END_DDX_MAP()};
None of the base class DDX routines seem to get called, e.g. DDX_TEXT, DDX_INT_RANGE, etc. I set breakpoints in DDX_Text() and all others but only the DDX_CBString one gets hit. Could it have something to do with the way the macro's are defined? They are defined within a function body: (from atlddx.h)
// DDX map macros
#define BEGIN_DDX_MAP(thisClass) \
BOOL DoDataExchange(BOOL bSaveAndValidate = FALSE, UINT nCtlID = (UINT)-1) \
{ \
bSaveAndValidate; \
nCtlID;#define DDX_TEXT(nID, var) \
if(nCtlID == (UINT)-1 || nCtlID == nID) \
{ \
if(!DDX_Text(nID, var, sizeof(var), bSaveAndValidate)) \
return FALSE; \
}
// .... -
this is my added code (I am trying to implement a DDX_CBSTRING function ala MFC): (in my atlddx2.h)
namespace WTL
{#define DDX_CBSTRING(nID, var) \
if(nCtlID == (UINT)-1 || nCtlID == nID) \
{ \
if(!DDX_CBString(nID, var, sizeof(var), bSaveAndValidate)) \
return FALSE; \
}template <class T>
class CWinDataExchangeEx : public CWinDataExchange<T>BOOL DDX\_CBString(UINT nID, \_CSTRING\_NS::CString& value, int /\*cbSize\*/, BOOL bSave /\*, BOOL bValidate = FALSE\*, int nLength = 0\*/) { // implementation here..... }
};
}; // namespace WTL
then on the dialog class:
#include "atlddx2.h"
class CScaleEditDlg :
public CDialogImpl<CScaleEditDlg>,
public CWinDataExchangeEx<CScaleEditDlg>
{
// .....
BEGIN_DDX_MAP(CScaleEditDlg)
DDX_CBSTRING(IDC_SCALE_MODEL, m_strModel)
DDX_TEXT(IDC_SCALE_DESCRIPTION, m_strDescription)
DDX_INT_RANGE(IDC_SCALE_SA, m_nStationAddress, 0, 999)
DDX_CONTROL_HANDLE(IDC_SCALE_IMAGE, m_ctlImage)
END_DDX_MAP()};
None of the base class DDX routines seem to get called, e.g. DDX_TEXT, DDX_INT_RANGE, etc. I set breakpoints in DDX_Text() and all others but only the DDX_CBString one gets hit. Could it have something to do with the way the macro's are defined? They are defined within a function body: (from atlddx.h)
// DDX map macros
#define BEGIN_DDX_MAP(thisClass) \
BOOL DoDataExchange(BOOL bSaveAndValidate = FALSE, UINT nCtlID = (UINT)-1) \
{ \
bSaveAndValidate; \
nCtlID;#define DDX_TEXT(nID, var) \
if(nCtlID == (UINT)-1 || nCtlID == nID) \
{ \
if(!DDX_Text(nID, var, sizeof(var), bSaveAndValidate)) \
return FALSE; \
}
// ....Returning FALSE from a DDX method means that the data exchange method failed such that the rest of the data exchange process should be cancelled. You need to return TRUE from your DDX_CBString method unless (for example) validation of the item fails.