Hi everybody,
I stumbled on a little error that is confusing.
My program uses tabs to control two dialog boxes each having their own classes and functions. I instantiate them as follows:
I also have some code that listens to messages from the dialog box and sets theDialog1 pointer appropriately:Code:if(GetCurSel() == 0) { if (theDialog1 != NULL) { theDialog1->SetFocus(); } else { theDialog1 = new dialog1; theDialog1->Create(IDD_DIALOG1,this); }
In my Dialog1 class, I have this code for sending the message to the parent that instantiated an instance of this class when someone clicks on the ESC key:Code:ON_MESSAGE(WM_USER_DIALOG_DESTROYED, OnDialogDestroyed) LRESULT tabControl::OnDialogDestroyed (WPARAM wParam, LPARAM lParam) { theDialog1 = NULL; return 0; }
Alas everytime the program reaches the line CWnd* pWindow = GetParent();Code:// dialog1 message handlers void dialog1::PostNcDestroy() { CDialog::PostNcDestroy(); CWnd* pWindow = GetParent(); //AfxGetMainWnd()-> pWindow->SendMessage (WM_USER_DIALOG_DESTROYED, 0, 0); delete this; } void dialog1::OnCancel() { DestroyWindow(); }
it crashes and gives me a debug assertion failed error.
Can anybody look at the code and let me know what I am doing wrong. Also if I use AfxGetMainWnd()-> it works fine but the class that instantiated the dialog window does not seem to get the message properly. I am thinking it's because it is not the main window. Can someone confirm this. Thanks
Amish



LinkBack URL
About LinkBacks


