954,224 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Plz Help:In windows programming how to close dialog box?

How to close dialog box if it doesnt hav OK and CANCEL Button in windows programming.the dialog box is shown with DoModal which inturn calls onInitDialog().But how to close it ?does EndDialog hepls and how ?where to call EndDialog?

risa
Light Poster
31 posts since Jul 2007
Reputation Points: 10
Solved Threads: 1
 

you could set a timer and close the dialog box in the OnTimer() event handler. There may be a couple other options: (1) send a WM_CLOSE message from another window or (2) click the X button in the upper-right corner, assuming you have not removed that too.

Ancient Dragon
Retired & Loving It
Team Colleague
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,342
 

There is no X button and i want to close this dialog box after a particular thread ends

risa
Light Poster
31 posts since Jul 2007
Reputation Points: 10
Solved Threads: 1
 

In that case have the thread that is closing call PostThreadMessage() to send a private message to the DialogBox thread, then in the dialog's PreTranslateMesssage() event handler check for that message and call EndDialog().

Ancient Dragon
Retired & Loving It
Team Colleague
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,342
 

ur solution is not helping me frnd......i hav called a thread in onInitDialog of a dialog box(onInitDialog is called from DoModal()) .in the tread i hav done some processing and after it gets completed i need to end this thread(can i use AfxEndThread?) and should b able to catch the ending of thread after DoModal(by checking for GetExitCode()?) and close the dialog box(using EndDialog).Can do this ???

risa
Light Poster
31 posts since Jul 2007
Reputation Points: 10
Solved Threads: 1
 

>>i want to close this dialog box after a particular thread ends
That sounds like there is more than one thread in your dialog application program.

Do NOT call AfxEndThread() because you didn't call AfxBeginThread(). If you want the dialog box to exit immediately after processing OnInitDialog() then just simply call EndDialog() at the end of that function.

Ancient Dragon
Retired & Loving It
Team Colleague
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,342
 

[no there is only one thread (sorry if my statement indicated so)
i hav called thread by using AfxBeginthread in onInitdialog of Dialog box and wants to close this dialog Box only after the thread ends(do i hav to use AfxEndThread inside the thread(at the end) after the thread completes its processing)

risa
Light Poster
31 posts since Jul 2007
Reputation Points: 10
Solved Threads: 1
 

call the OnOK() function within the dialog. OnOK() is a member of CWnd and that is what the OK button calls. If you have removed the ON button, no worry. Just call the OnOK() yourself within where you want to terminate the Dialog.

wamuti
Newbie Poster
23 posts since Jan 2008
Reputation Points: 10
Solved Threads: 1
 

I think it is automatically close when you click any button in the dialog like yes no. But you must add code to each button whatever you want to accomplish with that button.

vidz
Newbie Poster
4 posts since Jan 2008
Reputation Points: 10
Solved Threads: 1
 

Hi,
i am designing a menu dailog box. clicking on a menu item will open another dailog. i tried using Destroy() and then DoModal for the another menu item. it works well for one time. the second time i click the same menu item, it shows assertion failed. can u please help me

Anitaj
Newbie Poster
1 post since May 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You