Is there a way to tell that a modal dialog is open?

Howdy,

I have an MFC dialog app that has a notification area (or system tray, or
whatever we are calling it this week) icon.  Per customer spec, when the
user right clicks this icon he or she gets a menu that includes an "exit"
choice which causes the app to send a WM_CLOSE message to itself.

The problem is that sometimes I get hangs or crashes if the user selects
this menu choice when a modal dialog is showing over the dialog window.

Is there a clean way to either tell that a modal dialog is open and thereby
know to disable this menu choice, or to ensure that any open modal dialog
gets closed in an orderly way?

thanks

Jim H


0
jnhtx (73)
8/27/2004 7:48:10 PM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
470 Views

Similar Articles

[PageSpeed] 47

First, determine why it is crashing. That's important. This may be more important than
knowing how to disable the menu item. 

There are several approaches. For example, you could create a dialog superclass that set a
flag indicating a dialog was active, and make all your dialogs be subclasses of this
class. (See my essay on subclassing dialog boxes on my MVP Tips site). A bit clumsy to
use, because as you create each new dialog you have to go through the subclassing magic.

Another would be to enumerate all the windows owned by the process and see if any of them
are dialog windows. This would not tell you if they are modal or modeless dialogs, but we
could handle that. It could also tell you if there is a messagebox active. If such a
window is found, you could disable the shutdown option. I'd favor this one.

if you have modeless dialogs, you could have a user-defined message UWM_QUERY_MODELESS
which you would send to each open dialog. Your modeless dialogs would respond with TRUE,
anything else would ignore it.

The problem with closing a modal dialog is that you have to know what will happen when you
close it. For example, you could send a message which caused it to effectively "cancel",
but then the question arises about what happens if it was only displaying an OK button,
and what is going to happen when it closes. What would happen if the message was
"Unrecoverable error" and the user should have taken some action. 

You could add a user-defined UWM_QUERY_CLOSE_DIALOG message which would allow a dialog to
indicate its willingness to close, and if it said "true", indicating it could close
cleanly, a UWM_PLEASE_CLOSE message could be sent. If any dialog refused to honor this
request, then you would disable the menu item.
				joe

On Fri, 27 Aug 2004 14:48:10 -0500, "Jim Howard" <jnhtx@spamcop.net> wrote:

>Howdy,
>
>I have an MFC dialog app that has a notification area (or system tray, or
>whatever we are calling it this week) icon.  Per customer spec, when the
>user right clicks this icon he or she gets a menu that includes an "exit"
>choice which causes the app to send a WM_CLOSE message to itself.
>
>The problem is that sometimes I get hangs or crashes if the user selects
>this menu choice when a modal dialog is showing over the dialog window.
>
>Is there a clean way to either tell that a modal dialog is open and thereby
>know to disable this menu choice, or to ensure that any open modal dialog
>gets closed in an orderly way?
>
>thanks
>
>Jim H
>

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15972)
8/27/2004 9:11:00 PM
Agreeing with Dr. Newcomer's comment, find out why it's crashing.  Perhaps
it has some connection to the fact that MFC dialogs only simulate modality,
as mentioned in this article: "The singular non-modality of MFC modal
dialogs" at http://www.codeproject.com/dialog/notmodaldialogs.asp

I was struck by the similarities in the symptoms you describe and the
article's author's explanation of how he found his problem, at
http://www.codeproject.com/dialog/notmodaldialogs.asp#xx466038xx

Mike


"Jim Howard" <jnhtx@spamcop.net> wrote in message
news:%23kaEM7GjEHA.3612@TK2MSFTNGP12.phx.gbl...
> Howdy,
>
> I have an MFC dialog app that has a notification area (or system tray, or
> whatever we are calling it this week) icon.  Per customer spec, when the
> user right clicks this icon he or she gets a menu that includes an "exit"
> choice which causes the app to send a WM_CLOSE message to itself.
>
> The problem is that sometimes I get hangs or crashes if the user selects
> this menu choice when a modal dialog is showing over the dialog window.
>
> Is there a clean way to either tell that a modal dialog is open and
thereby
> know to disable this menu choice, or to ensure that any open modal dialog
> gets closed in an orderly way?
>
> thanks
>
> Jim H
>
>


0
8/27/2004 9:55:35 PM
"Michael K. O'Neill" <MikeAThon2000@nospam.hotmail.com> wrote in message
news:up4JYCIjEHA.1652@TK2MSFTNGP09.phx.gbl...
> Agreeing with Dr. Newcomer's comment, find out why it's crashing.  Perhaps
> it has some connection to the fact that MFC dialogs only simulate
modality,
> as mentioned in this article: "The singular non-modality of MFC modal
> dialogs" at http://www.codeproject.com/dialog/notmodaldialogs.asp
>
> I was struck by the similarities in the symptoms you describe and the
> article's author's explanation of how he found his problem, at
> http://www.codeproject.com/dialog/notmodaldialogs.asp#xx466038xx
>

Michael, it sounds very much like my problem, including the tray icon. I
knew from Blaszcak that MFC modal dialogs are not really modeless, but I
hadn't looked into the details.

 I'll also follow Dr Newcomber's advice and look into the actual crashes,
and I'll also try and grok the codeproject article, it looks helpful.

thanks

Jim H


0
jnhtx (73)
8/30/2004 4:07:57 PM
Reply:

Similar Artilces:

Best Way ?
G'day All, Looking for some information. With Outlook you can have all your contacts...address, email address, yada, yada, yada. Can I use this information in to say mail merge with Word and email a letter to the ppl with email addresses? Or is this better done with a Access? The reason I ask is that we want to deliver an email to all our clients with the latest promotions. And want it to be a bit more automated? Any information or pointers in the right direction would be appreciated. Have a good one, Scott V You can use either Access or Outlook as the data source for a ma...

Open Hyperlink without Confirmation Message?
Excel 2003 insists on opening a "Microsoft Office" message box whenever a hyperlink that opens an external file (.mpg in this case) is clicked: "Opening xxxx.... some files can contain blah blah blah. Would you like to open this file?" Does anyone know how to get a worksheet's hyperlinks to open with a single click and skip this *annoying* (but oh so safe) message? Changing security levels under Macro settings does not do the trick. xl2003??? If yes, then Jim Rech posted this: http://google.co.uk/groups?threadm=ea%23IfqLoDHA.3700%40TK2MSFTNGP11.phx.gbl Curtis Phi...

CD keeps opening automatically
Hi: After having installed printer, CD slot keeps opening automatically, as if I'm going to put a CD in it. Then, I need to keep closing it every two minutes or so. My question is; How to stay CD slot keeps closing? Thanks for your help in advance. "MapleE." <someone|@comcast.net> wrote in message news:uj#T$oHELHA.5724@TK2MSFTNGP05.phx.gbl... > Hi: > After having installed printer, CD slot keeps opening automatically, as if > I'm going to put a CD in it. Then, I need to keep closing it every two > minutes or so. > >...

How to forbid opening subform
Can i forbid opening the subform by itself ? I want my subform to be opened only by the main form and i somebody wants to open the subform not to allow it -- Message posted via http://www.accessmonster.com samotek via AccessMonster.com wrote: > Can i forbid opening the subform by itself ? I want my subform to be > opened only by the main form and i somebody wants to open the subform > not to allow it Try referring to the subform's Parent property in the Open event. When NOT opened as a subform that will raise an error. You can then have an error handler that cancels the Op...

How do I eliminate restrictions to opening hyperlinks in emails?
When I click on a hyperlink in an email, I get this message: “This operation has been canceled due to restrictions in effect on this computer. Please contact your system administrator.” I just started receiving this message on my private laptop that is not connected to any system. How do I remove the "restrictions"? Thank you. Reassigning or resetting your favorite Internet browser usually does the trick. For details see; http://www.msoutlook.info/question/242 -- Robert Sparnaaij [MVP-Outlook] Coauthor, Configuring Microsoft Outlook 2003 http://www.howto-out...

Is there a way to color code Outlook Contact File Folder Labels?
Is there a way to color code Outlook Contact File Folder Labels? No. -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hours Coauthor, OneNote 2003 for Windows (Visual QuickStart Guide) Author, Google and Other Search Engines (Visual QuickStart Guide) Outlook Tips: http://www.outlook-tips.net/ Outlook & Exchange Solutions Center: http://www.slipstick.com Join OneNote Tips mailing list: http://www.onenote-tips.net/ "isailhbca" <isailhbca@discussions.microsoft.com> wrote in message news:4DBD10F7-FAA0-4102-A4C3-E2697908EFE8@microsoft.com... >...

A way to create sub-categories?
I want to group contacts by category and then a sub-category for easy viewing. Apart from creating a new field for sub-category is there a way of doing this? Outlook doesn't seem to support sub-categories. Thanks Nope. -- Patricia Cardoza Outlook MVP Author - Special Edition Using Microsoft Office Outlook 2003 Lead Author - Access 2003 VBA Programmer's Reference Author - Absolute Beginner's Guide to Microsoft OneNote 2003 http://blogs.officezealot.com/cardoza http://www.cardozasolutions.com "Casebase" <junkmail@casebase.net> wrote in message news:%23rx5a...

is there a way to crop a corner out of a rectangular image in Visi
Using subtract on two shapes accomplishes what i want to do, but when the first shape is a .gif image, it does not work. No, the "boolean operations", as they're called, do not operate on foreign objects like bitmaps and controls. Visio has crop functionality for imported graphics, but it is only rectangular. You could draw a small white triangle and give it "no line". Then place it over the corner of your bitmap. -- Hope this helps, Chris Roth Visio MVP "doug" <doug@discussions.microsoft.com> wrote in message news:29D479A6-6099-4051-B7A0-1...

is there a way to change the time card repor format?
i'm using activereports in RMS to generate a custome timecard report. for my timein and timeout colums, the datatype i have assigned to the columns is vbDate. when I generate the report, the columns only show the date as mm/dd/yyyy, they do not show the time of day piece for exactly when the cashier punched in or out. is there any way to change the formatting of this so that in the report the time shows up? for example, instead of showing 2/6/2005 in the time in column, it would show 2/5/2005 8:00:00 AM. thanks in advance, kevin There is a timecard report on the Reports Library...

best way to deserialize xml
I'm at a quandry as to what's the best/fastest way to deserialize an incoming xml stream? I ran a small test on xmlserializer and on a small file it performed 10 times worse then when I used the XMLDocument and deserialized the values myself. Is the xmlserializer really that slow? I'm expecting a file about 1 MB in length and if it's that slow on a 2 K file then I can't phantom how it's going to behave on a 1 MB file. Should I just skip the xmlserializer and XML Dom and go straight to xmlreader and do the deserialization myself? This has been discussed a few times...

Can You Count This Way?
I have some cells with note type data: For ex: ax,3b7,22,xy,zz, Is there a way to count every item between the commas? Thanks. Hi try =LEN(A1)-LEN(SUBSTITUTE(A1,",","")+LEN(A1)>0 -- Regards Frank Kabel Frankfurt, Germany Timothy Wright wrote: > I have some cells with note type data: > > For ex: > > ax,3b7,22,xy,zz, > > Is there a way to count every item between the commas? > > Thanks. On Wed, 19 May 2004 20:13:53 +0200, "Frank Kabel" <frank.kabel@freenet.de> wrote: >Hi >try >=LEN(A1)-LEN(SUBSTITUTE(A1,&q...

Is there a way to Sort data by color in Excel?
I am trying to sort data by color, is that possible? see http://www.xldynamic.com/source/xld.ColourCounter.html#sorting -- HTH Bob Phillips "SRTUC" <SRTUC@discussions.microsoft.com> wrote in message news:B5121232-FB1D-46AF-94F8-04B7EAA2D90C@microsoft.com... > I am trying to sort data by color, is that possible? You're gonna need a User defined function to get the value of a color. See Chip Pearson's site for a nice version: http://www.cpearson.com/excel/colors.htm Look for: Returning The ColorIndex Of A Cell Then you could use that UDF in a separate colu...

Fastest way to load an xml file into an array in .net
Hi All VS 2005 SP1 (C#, VB.NET) I need the absolut fastest way of loading an xml-file of about 700KB into an array. I need to load about 1500 of those xml-Files into arrays on startup of my application. Therefore it needs to be as fast as possible. Please also tell me if the xml structure can be improved. the xml looks like: y: Year m: Month h: Hour value <data> <v y="1998" m="1" h="1">0.227777109151971</v> <v y="1998" m="1" h="2">0.206573903224972</v> <v y="1998" m="1"...

Hidden Figure after closing then opening the Visio file
Dear all, I have a Visio file which has PNG/JPEG figures attached on it. However if I close that file, then opening it again those figures are gone? And whenever I saved the Visio file as EPS or other, I also can't see the figure. Strangely, I still can see the "dashed frame" of those figure in Visio file. It seems that the figures are still there, I just can't see it. Why is this happening? Is there a way to prevent or recover those figure back again? I am using MS-Visio Pro 2002. -- Edward On Thu, 05 Jul 2007 07:01:56 -0000, foolishbrat <ewijaya@gmail.com> wrot...

Is there a convenient way to save data
Is there a convenient way to save dialog data so it remembers the users last selection? I have a dialog based application that only has three user variables all of which are ints. What is the best way to make theses variables persistent for a given user on a given machine? Thanks "Jeff B" <jb@nospan.net> wrote in message news:fpDif.10451$Ay6.2336@fe13.lga... > > Is there a convenient way to save dialog data so it remembers the users last > selection? I have a dialog based application that only has three user > variables all of which are ints. What is the best w...

Is there a way
G'Day, Is there a way to turn off NDR's in Ex5.5 SP4 on an NT server running SP6a ? Also, can the ability for the server to receive TELNET connections be turned off? My server isn't an open relay, but, I know it's being used to SPAM using DNR's and I can see TELNET connections in the log files.... Thank You, Admin_In_Syd i know that u can turn off the ndrs to be sent from exchange at the standard poliy setting, thats how i configured it at exchange 2000 .... there must be also a setting at exch 5.5, actually i dont remeber it .... "Steve@Home" <sprob@...

Word Won't Open with File Double-click if Word not open
I'm running Vista Home Premium SP2 on an Acer desktop system with 2 gigs of Ram and running Office 2007. My primary internet browser is Firefox. For the past few months I can no longer double click on a Word file (not matter where it's stored or what it is) unless I first open up Word itself. I get an error message (see below). When I first purchased and download Office 2007 in 2006 there was no problem opening up Word files with a double click and it's been that way up until a few months ago. Opening Excel files has always and now works just fine. Here's the ...

Office Crashes When Opened
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel Whenever I open any Microsoft Office 2008 application I get the "Microsoft App has encountered a problem and needs to close. We are sorry for the inconvenience." I can't find any solution online that is working, what should i try? ~Thanks <JackTheMetalHead@officeformac.com> wrote: > Whenever I open any Microsoft Office 2008 application I get the > "Microsoft App has encountered a problem and needs to close. We are > sorry for the inconvenience." I can't find any solution onli...

way to verify time stamp?
Is there a way to verify when a forwarded message to you had originally been sent? I suspect someone is mis- representing themselves and simply typed new fields into the "original message" time and date. If not - is it possible (or at all likely) that someone sent me two emails days ago and they never bounced back and never made it to my inbox, while all other email functions appear completely normal?? Thanks! "Julie" <anonymous@discussions.microsoft.com> wrote in message news:27d701c49d00$dd3315d0$a401280a@phx.gbl... > Is there a way to verify when a for...

VB6 Code 1/2 way finished......any suggestions
Have a issue with a VB6 program, had someone write some code, he got 1/2 way thru and decided to work on other projects and keeps putting us on the back burner, been waiting 4 months now, looking at what he has put together looks very nice, but is trademarked? so we cant get to the code, any ideas or suggestions? Thanks Bill On 4/1/2010 12:48 AM, David Kaye wrote: > "Bill"<got2believe@msn.com> wrote: > >> trademarked? so we cant get to the code, any ideas or suggestions? Thanks > > If it'...

How can I open a text file to the screen
Can anybody tell me how to open (print)a text file to the screen. For example, to click a botton and the file will be shown in the screen. Using something like the code below.(the code below is not good, but I want to give you an idea) private: System::Void ShwCrdBtn_Click(System::Object^ sender, System::EventArgs^ e) { FileInfo^ fi = gcnew FileInfo("C:\\MyFile.txt"); fi->OpenRead(); } -- Thanks Allen Basically, there are several things you can do depending on exactly what you want the result to look like. If the only thing you want to be vis...

spreadsheet won't open "too many
different cell formats". There's a guy in our company that has created this HUGE spreadsheet - and now they can't open it because it gives the error message "too many different cell formats". I know how to resolve the issue if I can open the file - is it too far gone? Is there any way to open this file? Any help is appreciated! Thanks so much! xl2002 has a better reputation for opening files that xl2k and before couldn't. So if you're not using xl2002, you may want to see if you can find a copy so you can try it. And I think I read someone post that t...

OPEN RELAY #6
I am running Exchange 5.5 and I've noticed a lot of messages in the IMS SMTP Protocol Log that have an unknown sender and recipient that is NOT in my domain. It looks like I have an OPEN RELAY. When I RCPT TO: my Exchange server, it says that "Relaying is Prohibited". I've deleted these messages, but more arrive. There are a few NDRs, but most of them are being transmitted out again. HELP! I can't seem to figure this one out. Tommy Tommy wrote: > I am running Exchange 5.5 and I've noticed a lot of > messages in the IMS SMTP Protocol Log that have ...

Modal dialog box with a tree control is hidden
I am facing a strange problem on Windows 98 system,The Modal dialog box with a tree control is hidden behind the property sheet, which invokes that dialog. The application is a MDI application with two views,the view which is derived from the scroll view class invokes the property page for a widget in that view.In the property page on clicking on a button should invoke a modal dialog box with a tree control in it.This works fine on Win Xp, WinNT machines but on Win98,it behaves strangely as i have mentioned above. Is it a know bug ?? Thanks in advance. Pavan K Thirunagari It sounds like i...

trying to figure out a two way lookup to determine a value
I have a large spreadsheet that lists numerous customers. Each custtomer has a code for the service that we provide them and then has a price negotiated at the time of service. We are have set up a price list that gives the service code, in a vertical column and then has a range of dollar values for each service code (about 20 separate codes) ranging from $0 to $75 broken up in 5 grade (E,D,C,B, A) categories. The pricing is different ranges for each service code. What I need to do is have each customer line, take their code, find a match in the Price LIst code, the take the price they are pa...