Solved

EndDialog does not end the dialog

Posted on 2000-04-13
12
993 Views
Last Modified: 2013-11-20
Hello Experts,
 I have some simple code which I have complicated by using some ShellNotify, etc. Here is the logic:

 I display the dialog using DoModal.
 
 In the dialog I call ShellNotify to create a Tray Icon (the small thingies that run next to the clock). After installing the tray icon the code is hiding the dialog: ShowWindow(SW_HIDE). All this is standard practice for the creating a tray icon.
 In the click event for the tray icon I display a menu which has "Exit" as one of the options.
 In the handler code for the exit menu item click event I call EndDialog to end the dialog box. You'd expect DoModal to return with the exit value. It does not.

 I understand from the MSDN documentation, and I quote, "EndDialog does not close the dialog box immediately. Instead, it sets a flag that directs the dialog box to close as soon as the current message handler returns."

 Couple of things you need to know. I am setting off some timers using SetTimer for doing some periodic monitoring work which I am killing using KillTimer. When the timer expires I use CSocket to communicate with some servers over the network. Basically the app is a monitoring tool.

 How do I make the "current message handler return" (from where?)? Is there a way to flush out all the messages and make the dialog exit gracefully and my app to exit gracefully ... or just say forget those freaking message and exit already :)

 The problem is that the app continues to execute in the background even after the tray is cleared and the dialog is not to be seen. I have to use task manager to kill it.

XPert.
0
Comment
Question by:XPert
  • 2
  • 2
  • 2
  • +5
12 Comments
 
LVL 8

Expert Comment

by:VinExpert
ID: 2714667
Hi,

Instead of calling EndDialog() try and call OnOK()

VinExpert
0
 
LVL 1

Expert Comment

by:MT_MU
ID: 2714707
of OnCancel
0
 
LVL 4

Expert Comment

by:inpras
ID: 2715032
Some code I think would have been helped more to solve the problem...?
0
 
LVL 2

Expert Comment

by:vbk_bgm
ID: 2715071
Try ,
EndDialog(IDOK);
DestroyWindow();
0
 

Expert Comment

by:degarn
ID: 2715125
Or also,

OnOK();
EndDialog(IDOK);

or

OnCancel();
EndDialog(IDCANCEL);

But I feel like the best solution is the one offered by vbk_bgm !
0
 

Expert Comment

by:degarn
ID: 2715154
Btw, the fact your apllication doesn't exit when you call EndDialog shows that something is still "running" in it!
You should verify if everything (Timers, Sockets, etc...) is completely closed and destroyed before call to  EndDialog. Well, logically, DestroyWindow() call within the main dlg of your dialog based application should categorically do it for you !
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:NoXPert
ID: 2717022
I have pretty much explored all the OnOK() or OnCancel or DestroyWindow() calls and nothing seems to matter.
degarn has hit it right where it hurts. There is something still running or some messages still in the queue. I have made sure that the timers are destroyed and the sockets are closed (though I will double-check that)

 I need to know a way to flush out all the messages and exit from the app. A call to exit() function is no good as all of us know. It throws an exception.

 I highly appreciate your help in solving this problem. I will still be waiting.

Cheers,
XPert.
0
 

Expert Comment

by:NoXPert
ID: 2717032
inpras,
 I will try and paste some code as my next comment. I had to be on the road in the am period and so haven't yet reached my work desk. I shud be there after noon.

XPert.
0
 

Author Comment

by:XPert
ID: 2717062
OOps !!!

I guess I found out the password for my other ID NoXPert. It was on my laptop and I thought I had forgotten it. Well I hope the folks at the Exchange don't get angry at me for using two ids.

So for the last two comments NoXPert == XPert.

Sorry!!!
XPert.
0
 

Accepted Solution

by:
bertp earned 100 total points
ID: 2717368
PostQuitMessage(0); should shut you down, just remeber to do whatever cleanup you need to peform first
 
0
 

Author Comment

by:XPert
ID: 2718116
bertp,
 You the man, the guru, the expert, the deserving 100 point winner. PostQuitMessage(0) in the red corner wins.
 I shall investigate PostQuitMessage further but can the guru, bertp, spare some time and shed some light on PostQuitMessage (the 100 point are yours regardless)

Cheers,
XPert & NoXPert.
0
 

Expert Comment

by:bertp
ID: 2718467
Sure,
  A UI thread terminates when WM_QUIT  is posted to its message queue and of course this is what the PostQuitMessage function does..
   DestrowWindow() on your main window should cause this to ultimately happen.. If you find out why it didn't please let me know ;-)

Bert
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running shell command from Access 3 69
maven archtype selection in eclipse 1 53
NotAlone Challenge 20 79
matchUp  challenge 9 93
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now