473,386 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to programmatically close a messagebox?

I am trying to programmatically close a messagebox. I don't see any
obvious managed choices. Back in the day, I remember using a
combination of FindWindow and EndDialog apis(
http://msdn2.microsoft.com/en-us/library/ms645472.aspx ), but how can I
ensure that the dialog that I am destroying actually belongs to my
application?

Thanks.
Jun 26 '07 #1
6 21498
Frank,

Well, there aren't any managed ways to do this. You will have to use
the FindWindow and EndDialog api's just as you would in unmanaged code.

If you want to make sure that the dialog belongs to your app, the only
way I can think of is to get the handle of the window, and then call the
GetWindowThreadProcessId API function through the P/Invoke layer. It will
give you the thread id and the process id that the window belongs to. With
that, you should be able to make a match between the messagebox dialog and
your app.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Frank Rizzo" <no**@none.comwrote in message
news:u9**************@TK2MSFTNGP03.phx.gbl...
>I am trying to programmatically close a messagebox. I don't see any
obvious managed choices. Back in the day, I remember using a combination
of FindWindow and EndDialog apis(
http://msdn2.microsoft.com/en-us/library/ms645472.aspx ), but how can I
ensure that the dialog that I am destroying actually belongs to my
application?

Thanks.
Jun 26 '07 #2
"Frank Rizzo" <no**@none.comwrote in message
news:u9**************@TK2MSFTNGP03.phx.gbl...
>I am trying to programmatically close a messagebox. I don't see any
obvious managed choices. Back in the day, I remember using a combination
of FindWindow and EndDialog apis(
http://msdn2.microsoft.com/en-us/library/ms645472.aspx ), but how can I
ensure that the dialog that I am destroying actually belongs to my
application?
In addition to Nicholas' response, I'm slightly curious about this...

Is the MessageBox in question not being generated by an application which
you are writing...? If so, then surely you have control over the code which
generates the MessageBox in the first place...

So, if you don't need it, don't show it...
--
http://www.markrae.net

Jun 26 '07 #3
Mark Rae wrote:
"Frank Rizzo" <no**@none.comwrote in message
news:u9**************@TK2MSFTNGP03.phx.gbl...
>I am trying to programmatically close a messagebox. I don't see any
obvious managed choices. Back in the day, I remember using a
combination of FindWindow and EndDialog apis(
http://msdn2.microsoft.com/en-us/library/ms645472.aspx ), but how can
I ensure that the dialog that I am destroying actually belongs to my
application?

In addition to Nicholas' response, I'm slightly curious about this...

Is the MessageBox in question not being generated by an application
which you are writing...? If so, then surely you have control over the
code which generates the MessageBox in the first place...

So, if you don't need it, don't show it...
Basically the situation is this. The application is supposed to log
people off after an hour of inactivity. If they performed an operation
that threw up a dialog box (such as a validation of some sort) and then
the user went to lunch, at some point I need to get rid of the message
box, close some other windows and bring the app to the login screen.
Jun 27 '07 #4
On Tue, 26 Jun 2007 17:11:02 -0700, Frank Rizzo <no**@none.comwrote:
Basically the situation is this. The application is supposed to log
people off after an hour of inactivity. If they performed an operation
that threw up a dialog box (such as a validation of some sort) and then
the user went to lunch, at some point I need to get rid of the message
box, close some other windows and bring the app to the login screen.
So, taking as an assumption that your code IS the code that's calling the
MessageBox.Show() method, I would recommend that the answer is to not use
MessageBox. Instead, just use your own custom form, calling ShowDialog()
on it to do basically the same thing as the MessageBox class. Then, you
have the instance of the form itself, and you can call Close() on that
instance to close it.

I assume, of course, that whatever is being displayed is known to be
cancellable without any serious harm (that is, it's not a yes/no
MessageBox that says "should I keep all of the work that you've done over
the last 48 hours?")

Pete
Jun 27 '07 #5
Hi Frank ,

How about your issue now? Normally, I agree with Peter that you'd better
create a customized messagebox to show to the user so that you can control
its life time through the reference easily.

If you still need any help, please feel free to feedback, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Jul 2 '07 #6

""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comschrieb im Newsbeitrag
news:jf**************@TK2MSFTNGHUB02.phx.gbl...
Hi Frank ,

How about your issue now? Normally, I agree with Peter that you'd better
create a customized messagebox to show to the user so that you can control
its life time through the reference easily.

If you still need any help, please feel free to feedback, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

Hi Frank,

there is a way to do this, but not managed. You can set a CBT Hook
right before you call the MsgBox and then look for the MsgBox in the
Callback and manipulate it from there the way you want it, e.g. Add
Buttons, Icons, close it, etc,...

I have a lot of Visual Basic 6 Code but i think this is more handy
for you: http://www.codeproject.com/cs/miscct...IndirectCS.asp
Its in C# and a part of the code and article shows exactly what you want.
Beste Grüsse / Best regards / Votre bien devoue

Kerem Gümrükcü
-----------------------
"This reply is provided as is, without warranty express or implied."




Jul 2 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: s-galit | last post by:
hi, how to close messageBox (and the form wont be closed too) ??? i tried it with close and dispose but then the form is closed too. thanks
8
by: deko | last post by:
Can I close a MsgBox with VBA Code? Something like: If IsOpen (MsgBox, "Title") Then Close(MsgBox, "Title") Run some code Else Run other code End If Can this be done in VBA? Do I need to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.