Click here to Skip to main content
15,921,276 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
all i want to do is to click a menu item, then create a modeless dialog.
i built a new class called CParamDisplay,in the ListTestView.h,i added
#include "ParamDisplay.h"
...
CParamDisplay*	m_pParamdisplay;

and then i added the code in ParamDisplay.h
void CListTestView::OnParamDisplay() 
{
	// TODO: Add your command handler code here
        m_pParamdisplay = new CParamDisplay;

	if (m_pParamdisplay == NULL)
	{
		m_pParamdisplay = new CParamDisplay;
		m_pParamdisplay->Create(ID_PARAM_DISPLAY,this);
	}

	m_pParamdisplay->ShowWindow(SW_SHOW);
}

i ran it,then error;
debug, stopped at:
BOOL CWnd::ShowWindow(int nCmdShow)
{
	ASSERT(::IsWindow(m_hWnd));
...
}

so what's the probelm?
Posted

1 solution

If the statement
m_pParamdisplay = new CParamDisplay;

succeedes, you do NOT call Create (while you must call it).

I'd suggest something more like:

void CListTestView::OnParamDisplay() 
{
        m_pParamdisplay = new CParamDisplay;
        if(m_pParamdisplay == NULL)
        {
                // warning message?
                AfxMessageBox("Something went wrong", MB_OK|MB_ICONEXCLAMATION);
        }
        else
        {
                m_pParamdisplay->Create(ID_PARAM_DISPLAY,this);
                m_pParamdisplay->ShowWindow(SW_SHOW);
        }
}


BTW: Even with these modifications the code works only if OnParamDisplay is called just once.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900