Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have an application in which I am displaying messagebox on button click of the dialog box. After displaying messagebox, I want to show same dialog box again.
I don't know how to do it. I tried ShowWindow(SW_SHOW) but it's not working.
Please help me to do this & also tell me how to hide dialogbox.

Thanks in advance......
Posted
Updated 13-Apr-11 22:38pm
v2
Comments
I did not get the question but what i understood is you want show same dialog box two times one after the other correct?

Your question is little unclear to me but according me you want following solution...

Before showing to message box call OnCancel() method of dialog box and after returning the control from message box use DoModal() method of dialog box.
 
Share this answer
 
Comments
virus131 14-Apr-11 5:39am    
thanx for your reply, but, I have already tried this, but it's not working.
LaxmikantYadav 14-Apr-11 9:11am    
can u please put your code here. It wil help to identify problem
Hey first thing That if you called message box on OnOk()
then
void YourDialog::OnOk()
{
  AfxMessageBox("HELLO");
  OnOk();
}

Then it display message and Di8alog will invisible,
So
For Remain in Same dialog after displaying messagebox please remove OnOk();
void YourDialog::OnOk()
{
  AfxMessageBox("HELLO");
  //OnOk();

}


Now if you want to Hide the dialog then just Called OnCancel() or OnOk();
If Not understand then please provide your code block where you doing all this activities.
 
Share this answer
 
Comments
virus131 14-Apr-11 5:56am    
Thank you very much for your answer....
Actually I am creating the application in which, on button click am checking existance of the, that is when I enter filename, it will check file exists or not. If entered file already exists, it will show alert message- "File already exist in the directory, please enter another name", & to enter another name I need to display same dialog box again.
I am doing this-
Onbtn_CreateFile()
{
CDialog::onOK();
if(...) //condition for checking existance of file
{
MessageBox(...);
DoModal();
}
else
{
//code for creating directory/file
}
}
Here, I am not using default OK button. I dont want to use it.
Please help me if you can.
Thanks........
LaxmikantYadav 14-Apr-11 9:44am    
Please comment firt line in Onbtn_CreateFile()
ie CDialog::onOK();
[no name] 15-Apr-11 3:41am    
Try this,
Onbtn_CreateFile()
{
JUMP: DoModal();

if(...) //condition for checking existance of file
{
MessageBox(...);
goto JUMP;
}
else
{
//code for creating directory/file
}
}
I guess you are closing the dialog and therefore showwindow won't work because you should create the dialog again via a DoModal or another method...

If you are doing that via pressing the OK or CANCEL buttons, then you could do what has been posted on the second solution or create another button with the specific functionality you need... which probably would be clearer and you could use the OK/CANCEL buttons if they are needed in a unknown future...

If you make another button, you can always:

1. hide your dialog (showwindow...).
2. create the messagebox.
3. show the dialog (showwindow...).

HTH!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900