Help me out with DestroyWindow
I created a control in OninitialUpdate:
void CdestroywindowView::OnInitialUpdate()
{
CView::OnInitialUpdate();
CSize mediaButtonSize( 150, 40 );
// PLAY BUTTON CONTROL
CPoint playPoint(10, 15);
CRect playButtonRect( playPoint,mediaButtonSize);
playButton.Create( _T("Press Play"),
WS_CHILD|WS_VISIBLE|WS_DISABLED
|BS_PUSHBUTTON,
playButtonRect,
this,
PLAY_BUTTON);
playButton.EnableWindow( TRUE );
// TODO: Add your specialized code here and/or call the base class
}
and in oncommand, I just want the button to erase when i press it, so i tried the following
BOOL CdestroywindowView::OnCommand(WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if( HIWORD(wParam) == BN_CLICKED )
{
switch ( LOWORD ( wParam) )
{
// MEDIA BUTTON CONTROLS //
// PLAY BUTTON CLICKED
case PLAY_BUTTON:
// DISABLE playButton, AND songSelectionListbox
playButton.DestroyWindow();
delete playButton;
}
}
return CView::OnCommand(wParam, lParam);
}
however, I get the following error:
Unhandled exception at 0x7c22fef2 (mfc71d.dll) in destroy window.exe: User breakpoint.
it occurs on this line in wincore.cpp
// control notification
ASSERT(nID == 0 || ::IsWindow(hWndCtrl));
What is jayhawks doing wrong?
[1549 byte] By [
Jayhawks] at [2007-11-19 19:32:58]

# 2 Re: Help me out with DestroyWindow
You can't call
delete playButton;
because playButton is not a dynamically createad object (or not if this is the aactual code).
// control notification
ASSERT(nID == 0 || ::IsWindow(hWndCtrl));
This means that either your control ID (PLAY_BUTTON) is zero, or the window is not created at that point.
Thanks cilu,
I erased the deleete playButton line
I think both my control ID is zero and my window is not created at that point...how do I fix this?
# 3 Re: Help me out with DestroyWindow
Change the code to following:
BOOL CdestroywindowView::OnCommand(WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if( HIWORD(wParam) == BN_CLICKED )
{
switch ( LOWORD ( wParam) )
{
case PLAY_BUTTON:
playButton.DestroyWindow();
break;
default:
return CView::OnCommand(wParam, lParam);
}
}
else
return CView::OnCommand(wParam, lParam);
}
After handling the message for you button click you are calling the deafult message handler and since the button is already destroyed the app crashes.
logan at 2007-11-10 23:45:32 >

# 8 Re: Help me out with DestroyWindow
What I don't undersand is why do you destroy the button in OnCommand() and not in BN_CLICKED handler.
void CdestroywindowView::OnSpecialButtonclicked()
{
// perform some operations here
// destroy the button; this function will not be called again
playButton.DestroyWindow();
}
Well, cuz I'm a beginner.
Thanks, I'll try it out.