Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
I want to dismiss the message box for any click on the message box. Please help me with this.
Posted
Comments
Sergey Alexandrovich Kryukov 20-May-11 4:37am    
There is not such language or platform as VS2008! Tag it all!
--SA

There is no simple way to do it (I am talking about winforms here as there is no tag in the qustion I am not sure what’s the question is related to). You will have to write custom control to achieve that.
 
Share this answer
 
Comments
Tarun.K.S 20-May-11 6:21am    
Like creating a Custom Window instead of MessageBox, and then handling its MouseDown event to close the window. Am I right?
CS2011 20-May-11 6:55am    
Hit the nail on the head. Absolutely correct.
Tarun.K.S 20-May-11 7:22am    
Thanks! 5d
Yes, you can easily do it. Never do it! Don't make your user mad. Message box is message box, not after you implement a "feature" like that.

—SA
 
Share this answer
 
Comments
Tarun.K.S 20-May-11 6:20am    
It's a requirement SA which the OP wants to implement.
Sergey Alexandrovich Kryukov 20-May-11 23:46pm    
Why do you think requirement is an excuse?! Tomorrow your manager will send you the requirement to rob a bank. When police arrests to you, will you excuse that it was a requirement work. That manager will say that is was a result of typo, and that you were supposed to give him feedback and point out the problem instead of actually robbing the bank. You will go to prison.

Programming is exact same thing.
--SA
Tarun.K.S 21-May-11 14:03pm    
I must say the example of yours is very less practical.
Sergey Alexandrovich Kryukov 22-May-11 2:13am    
About robbing the bank? Sure, not robbing the bank is quite a practical way not to go to prison. :-)
--SA
Albert Holguin 20-May-11 10:35am    
lol, SA is right, this sounds like building in a bug intentionally!
If this is MFC based, you can just intercept the messages going to the dialog and dismiss it when you catch the messages that you want to trigger this effect (mouse down and you may think of others), but I do agree with SA, this doesn't seem like a desirable effect at all.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 20-May-11 23:49pm    
With the last note it make sense, my 5 :-)
--SA
Albert Holguin 21-May-11 11:21am    
lol... its an odd "feature"
Sergey Alexandrovich Kryukov 22-May-11 2:10am    
Don't you think this is way too typical for questions we see here: some people very uncomfortable with very basic programming chores requesting for hard-to-implement "features" designed to make potential users mad?
--SA
Albert Holguin 22-May-11 16:41pm    
Definitely. Seems to be a common goal of new developers to annoy users.
Sergey Alexandrovich Kryukov 22-May-11 17:40pm    
I would not mind to get annoyed at first if my response can help and if the help is understood and used to improve things.
--SA
well...
typically when you press a button in the messagebox it disappears returning the value of the button you've pressed... you'll have to decide how to process that value once it has reached again your program flow...

Tipically (in pseudocode):
A = MessageBox(...)
switch (A)
{
  case...
}


So it is up to you to dismiss it or not...

In fact if you call only messagebox without assigning it's return to a variable then nothing will happen apart of the MessageBox disappearing.



OOps!

re-read your question...

Messagebox is an api, you can't subclass it... you should replicate a dialog that look like a messagebox and put your functionality there...

Look here: http://www.codeproject.com/Messages/938953/How-can-I-subclass-MessageBox.aspx[^]

Anyway take a look here also : http://www.codeguru.com/cpp/w-p/win32/messagebox/article.php/c14605[^]

HTH...
 
Share this answer
 
v2
Comments
bunathangaraj 20-May-11 4:12am    
Thanks John, I am aware of pressing a button in message box will dispear message box window.

But, my requirement is on clicking a msg box window( not button but anywhere in the window) should disappear the window ...

Any idea?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900