Solved

EndDialog does not end the dialog

Posted on 2000-04-13
12
1,059 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

636 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