problem with CSplitButton::SetDropDownMenu method
-
Hi, I have created a dialog based application in visual studio 2010 and I have added a CSplitButton Control to my dialog through resource editor, also I have made a menu in resource editorwith the ID of IDR_MENU_BUTTON_FILE and a sud menu after all, my code looks like the following code:
BOOL CMyDialogDlg::OnInitDialog()
{
CSplitButton* pCtrlSpiltBtn = (CSplitButton*)this->GetDlgItem(IDC_SPLITBUTTON1);
pCtrlSpiltBtn ->SetDropDownMenu(IDR_MENU_BUTTON_FILE, 0);
}however the pCtrlSpiltBtn get initialized correctly and every thing is OK. but
pCtrlSpiltBtn ->SetDropDownMenu(IDR_MENU_BUTTON_FILE, 0);
fails when I trace the case I found that this line call the following methods of MFC classes.
void CSplitButton::SetDropDownMenu(UINT nMenuId, UINT nSubMenuId)
{
Cleanup();
m_nMenuId = nMenuId;
m_nSubMenuId = nSubMenuId;
}void CSplitButton::SetDropDownMenu(CMenu* pMenu)
{
Cleanup();
m_pMenu = pMenu;
}void CSplitButton::Cleanup()
{
if (m_pMenu)
{
delete m_pMenu;
}
m_pMenu = NULL;
m_nMenuId = (UINT)-1;
m_nSubMenuId = (UINT)-1;
}and the m_pMenu pointer is always initialized and while the line
delete m_pMenu;
get executed all the application ruining fails. Please help me solve the case, what should I do?