Solved

EndDialog does not end the dialog

Posted on 2000-04-13
12
981 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 98
Detect CR LF to each line 12 137
conditional code and condition difference 9 65
twoTwo  challenge 35 86
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 video discusses moving either the default database or any database to a new volume.

759 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

18 Experts available now in Live!

Get 1:1 Help Now