If
ASSERT(::IsWindow(m_hWnd))
failed, it means that the dialog (or the control) you are trying to access was not created yet.
It is often tricky to make a class inherit from an existing
CDialog
one. I would like to ask several questions:
- Is
CSampleDlg
a fully functionnal dialog? I mean can you display it using
DoModal
without problem?
- Why does
CDerivedOne
inherit from
CSampleDlg
?
--> do you use a different resource for
CDerivedOne
?
--> or is this class just to add some methods and members to
CSampleDlg
without modifying the UI?
Could you post the .h files and the .cpp files (at least the constructors,
DoDataExchange
,
OnInitDialog
, and macros like
BEGIN_MESSAGE_MAP
,
DECLARE_DYNAMIC
, ...)
----------------
I read your code from your comments and the problem is easy to fix:
void CMlkOne::ChangeVariableValue(int VarId, int VarValue)
{
CSampleDialogLogicDlg objBaseDialog;
objBaseDialog.ChangeCheckStatus(2);
}
You have an asssertion here because even though you instanciated the dialog object,
the dialog resource is not created yet (it is created after
DoModal
is called for example).
Moreover, what you want here is not instanciating another object, but calling the base method.
So just replace your code by this one:
void CMlkOne::ChangeVariableValue(int VarId, int VarValue)
{
CSampleDialogLogicDlg::ChangeCheckStatus(2);
}
-----------------------
Shiva, I just saw an error I hadn't seen before: you overrided
OnInitDialog
in
CMlkOne
class like this:
BOOL CMlkOne::OnInitDialog()
{
return TRUE;
}
This can't work. All initialization is done in
OnInitDialog
and with your code, you just by-pass the initialization so your dialog is not created!
You must call the base method:
BOOL CMlkOne::OnInitDialog()
{
return __super::OnInitDialog();
}
And if you want to call
ChangeVariableValue
in
OnInitDialog
, do like this:
BOOL CMlkOne::OnInitDialog()
{
__super::OnInitDialog();
ChangeVariableValue(2);
return TRUE;
}
I hope it is clear this time.