Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modal box not working correctly

Status
Not open for further replies.

Valius

Programmer
Oct 20, 2000
174
US
I added a Dialog box to my program...then I poped it up by doing the following


CDialog ErrorReport(IDD_DIALOG_REPORT)

ErrorReport.DoModal();

This worked great...then I put a button on my Report dialog and tried to map a function to it. Well, it told me I had to make a new class before I could do that...no problem...so I made a new class for it. Then I mapped the function to the button....when I click the button, it does nothing. The dialog doesn't even call that function. The program is getting stuck in the the RunModalLoop() function it calls after the dialog box pops up. For some reason, my function isn't popping it out of the loop. The only way I can get out of it is to use the x in the upper right hand corner. Any clue why my buttons aren't working? Thanks for all your help!!!

Niky Williams
NTS Marketing
 
Dear Niky,

Are you still doing this:

> CDialog ErrorReport(IDD_DIALOG_REPORT)
> ErrorReport.DoModal();

If so that is the problem. You need to create an instance of the class you created using the class wizard.

CMyDialog dlg;
dlg.DoModal();

Hope this helps
-pete
 
The code you have is fine. By default the dialog is created with an OK and Cancel button which you deleted. These button take care of ending the dialog box by calling EndDialog and returning the correct value. DoModal() does return a value.

What you can do is override the CDialog::EndDialog() member function. This even gives you some control because now you can pass in the value you want returned.

void CYourDialog::YourButton(void){
EndDialog(5);
}

Ends your dialog and DoModal returns 5.

Have fun,

Brother C
 
Okay, I feel like a complete IDIOT!! That make so much sense now. I'm still a beginning VC++ programmer, so I'm still learning this stuff. Thank you so much for your help!!!


Niky Williams
NTS Marketing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top