Re: Event handler continues executing after its dialog is deleted
" Do you know what conditions the modal loop stops on? Does it respond to
WM_CANCELMODE?"
Some of the event loops that I am using respond to WM_CANCELMODE. And that
is easy solution, cause I can send the message to exit the loop, through
code when the dialog is closed. In this case my event handlers like
OnBtnClick that are using the function that started the event loop, can check
how the event loop was exited ( the function that starts the event loop can
return status about success, cancel ..) and if it was Canceled it can simply
return, and I will not have to reorganize access to member data , so
everything is ok :
void MyDlg::OnClose()
{
send WM_CANCELMODE here
DestroyWindow();
}
void MyDlg::OnBtnClick()
{
if(GetGeometricObject == Cancel)
return;
acess to member data here
}
Problem :
I also have to use functions that starts event loop , but not respond to
WM_CANCELMODE. How should I do then ?
"Normally, you'd call set capture to prevent the mouse/keyboard going
anywhere else, and then exit the loop in certain circumstances, and in
general preventing reentrancy to UI options. Menu functions run a similar
loop."
I don't understand this :(
"Anthony Wieser" wrote:
Normally, you'd call set capture to prevent the mouse/keyboard going
anywhere else, and then exit the loop in certain circumstances, and in
general preventing reentrancy to UI options. Menu functions run a similar
loop.
Do you know what conditions the modal loop stops on? Does it respond to
WM_CANCELMODE?
Regarding reentering your code after destruction, can you reorganize it so
that there is no work done on member variables after the call to the library
code?
Anthony Wieser
Wieser Software Ltd
In the event handler OnMyBtnClick I am calling third party library
function
that starts event loop inside its implementation i.e uses PeekMessage or
GetMessage and DispatchMessage. i.e basically I have local event loop in
my
OnMyBtnClick. This third party function is for selecting circles,lines and
other geometric objects.
If the user closes my dialog while the event loop is running with (x Close
from the system menu) the dialog object is deleted. Then if the user
selects
some circle or something the event loop is terminated too. After the event
loop is terminated, execution continues in OnMyBtnClick function although
the
dialog is deleted, and crash occurs in ( *) where access to member data is
made.
How to prevent this situation ?
Is this common situation ?
.