Solved

EndDialog does not end the dialog

Posted on 2000-04-13
12
1,014 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add content to output file 4 67
VBA "SendKeys" Syntax for Multiple Keystrokes 7 117
how to split multiple lines delimiter : 8 111
Way to decrease size of apk file 9 87
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.

828 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