See below...
Post by Stuart RedmannPost by Oliver RegenfelderHello,
Should the
enum { IDD = IDD_SOME_VALUE }
entry of an MFC class be public or can it also
be protected, or private?
I guess the dialog ID is made public because you may want to create
the dialog modeless through CDialog::Create, and one of the overloaded
versions of Create needs the dialog ID. Since the modeless creation of
CDialog seems quite defective (CDialog behaves as if it is always
created as modal dialog, unless you overwrite the OnOkey/OnCancel
handlers), this is probably a relict from the olden days. If you only
ever use your dialogs as modal dialogs, you should be save to declare
the IDD private/protected.
****
I have no idea what this paragraph is trying to say, because a lot of it is complete
nonsense.
A dialog is created modal if you call DoModal. It is created as modeless if you do
CDialog::Create using the symbol IDD, .e.g,
CDialog * modeless; // in the class definition
void CSomething::CreateMyModelessDialog()
{
ASSERT(modeless == NULL); // don't forget to initialize it!
// or, if you don't want to do the extra work to disable the dialog creation, see
below
modeless = new CMyDialog;
modeless->Create(IDD);
Another way to handle it is
void CSomething::CreateMyModelessDialog()
{
if(modeless != NULL)
{
modeless->ShowWindow(SW_RESTORE);
modeless->ShowWindow(SW_SHOW);
}
else
{
...create as shown previously
}
it is frequently desirable to "dismiss" the modeless dialog by overriding OnClose:
void CMyDialog::OnClose()
{
ShowWindow(SW_HIDE):
}
The statement that CDialog behaves as if it is always created as modal unless you override
(not overwrite!) CDialog::OnOK and CDialog::Cancel is complete and utter gibberish. The
rule is that a modal dialog terminates by calling EndDialog() and a modeless dialog
terminates by calling DestroyWindow, so the only reason you need to override (not
overwrite!) OnOK and OnCancel is to make sure they do NOT call EndDialog, which would
cause erroneous behavior. This is not a "relic", it is how dialogs are defined to work!
Note that you should do
void CMyDialog::PostNcDestroy()
{
... stuff
delete this;
}
and this means you had better have a way to set that variable to NULL. Importing the
class definition that has that variable would be erroneous program construction, and the
correct form is to typically do
PostNcDestroy:
...stuff
parent->SendMessage(UWM_I_HAVE_BEEN_CLOSED);
delete this;
}
where parent is a CWnd * (not a CView*, or CMainFrame*, or anything OTHER that a CWnd *)
in which you store the pointer to the window to be notified of closure:
LRESULT CWhatever::OnIHaveBeenClosed(WPARAM, LPARAM)
{
modeless = NULL;
return 0;
}
See my essay on message management on my MVP Tips site.
joe
****
Joseph M. Newcomer [MVP]
email: ***@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm