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?

Recommended Answers

All 9 Replies

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.

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

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().

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 ???

>>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.

[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)

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.

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.