Thanks for your quick reply. I actually got the code from a MS Press
Programming Series book since I'm not terribly familiar with this stuff. But,
could you follow up on one more question.
into the user function. This does indeed do the trick of killing the app as
I wanted. But I'm just a little concerned about inserting this statement in
the function before the return statement.
...
This would be killing the parent before the child. Is this ok? BTW, the
dialog is modeess.
"Joseph M. Newcomer" wrote:
See below...
On Tue, 13 Feb 2007 09:50:01 -0800, Howard <Howard@discussions.microsoft.com> wrote:
Hi,
I'm mapping a user-defined message with
ON_MESSAGE(WM_ABC,OnExitABCdialog ).
****
You should never name user-defined messages with WM_; that prefix is reserved for use by
Microsoft. Use some other convention. Notable conventions in common use include UWM_ and
WMU_. Using the WM_ prefix will only confuse people.
****
Then I have a user function that looks like this.
long xyzView::OnExitABCdialog(UINT wParam, long lParam)
*****
I have no idea why you would think the prototype for a handler function uses the types
long, UINT, long;
there is absolutely nothing that documents this. The ONLY acceptable prototype is the one
that is documented:
LRESULT name(WPARAM, LPARAM)
because the code you wrote will not compile or work on a 64-bit system. It is extremely
important not to develop bad programming habits by redefining the prototypes to something
you think might work, instead of using the specified prototypes. Just because they happen
to compile this week and give the illusion of working does not make them correct.
Note that since you are not using either wParam or lParam, the names of the parameters can
be omitted.
The correct form of this would be
LRESULT xyzView::OnExitABCdialog(WPARAM, LPARAM)
{ ...
NEVER presume you know the implementation of a defined type; use the type specified.
****
{
if (ABC!= NULL) {
ABC->DestroyWindow();
****
And why do you not set ABC to NULL at this point?
I'm presuming ABC is a modeless dialog.
****
}
return 0L;
}
This, of course, closes the ABC dialog window. I would like to modify this,
however,so that the user-function not only destroys the ABC dialog but also
exits the mainframe in some cases (say, if ABC->killapp is true).
That is, I want to be able to exit the application.
*****
AfxGetMainWnd()->PostMessage(WM_CLOSE);
*****
Is there some change that I can make to the user function (say, return
something other than 0L) that would do this? Or is there some other way to
kill the parent app?
****
No. There is no return from the message that would cause anything special to happen
unless the CALLER used SendMessage and looked at the result.
****
Thanks, Howard
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm