Solved

Program Crashes when re-opening a dialog box.

Posted on 1999-01-18
5
247 Views
Last Modified: 2013-11-20
With my dialog box based prog, I have a dialog box tied to a button in another dialog box.  In other words, when I click the button, a new dialog box comes up.  My problem is this:  When I try to re-open the same dialog box I just closed, I get an assert error that stems from wincore.cpp, line 628.  
ASSERT(pWnd->m_hWnd == NULL);   // only do once
Why can't I reopen the dialog box I just closed?
0
Comment
Question by:kirts
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1327894
How is the dialog box closed?  What function do you call?
0
 

Accepted Solution

by:
bheld earned 100 total points
ID: 1327895
It sounds like whatever method you are using to close is destroying the m_hWnd member.  If you are calling CDialog::Create() followed by CDialog::ShowWindow(SW_SHOW) to show the dialog, you will need to call CDialog::Create after the dialog box is closed before showing it again.

If this is not clear - please provide the calls you are making to show and close the dialog box.
0
 

Author Comment

by:kirts
ID: 1327896
Using ClassWizard in VC++ 6.0 I tied a function call to a button to open my class of dialog box MotorDialog.  Basically, when the button is clicked, this dialog box pops up.  This is my code to make this happen, which works.  You say that when I close the box, it is destroying the instance of m_hWnd.  I'm pretty sure I follow that.  Do I need to tie a function to the WM_CLOSE message
and put some code in there to keep from destroying m_hWnd??


Here's what I have so far to open the box:


void CBluejayFlexorDlg::OnMotorButtonClicked()
{
MotorDialog motor_dialog_box;
int nResponse = motor_dialog_box.Create(IDD_DIALOG1, NULL);      
}
0
 

Expert Comment

by:bheld
ID: 1327897
So it is failing the second time this function is called?

I think you want to define motor_dialog_box NOT as a local variable but as a member of some class.  Then call create the first time this function is called.  For subsequent times,
If so, I believe the second time u just call ShowWindow(SW_SHOW).

Give this a try and let me know
0
 

Author Comment

by:kirts
ID: 1327898
Thanks a lot for the info.  I got it going correctly now.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
twoTwo  challenge 35 108
Line meaning 9 88
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 879
Problem to open Excel file 15 179
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question