Disabling Keypress on MessageBox
-
Hi I have an application where a user types a message into an edit control, after they have exceeded a certain number of characters they are shown a warning. ie AfxMessageBox("you have exceeded X number of characters"); it seems that if the user is typing fast by pressing return of the space bar this is calling the OnOK and quickly turning off the message box so the users are not seeing the warning. Does anyone know if there is a way you can disable the return key and the space key on Afxmessagebox ? i could create a custom dialog to do this but that seems a long way round can anyone help thanks Simon
-
Hi I have an application where a user types a message into an edit control, after they have exceeded a certain number of characters they are shown a warning. ie AfxMessageBox("you have exceeded X number of characters"); it seems that if the user is typing fast by pressing return of the space bar this is calling the OnOK and quickly turning off the message box so the users are not seeing the warning. Does anyone know if there is a way you can disable the return key and the space key on Afxmessagebox ? i could create a custom dialog to do this but that seems a long way round can anyone help thanks Simon
You could try a few things. 1. Add
MB_NOFOCUS
to the flags. In theory this will not give focus to the message box, and so keyboard events will not get sent to it. There is no documentation that I could find on this, so behaviour might be a bit sketchy. 2. Try setting the default button to one that doesn't exist withMB_DEFBUTTON4
. If neither of these work, then all I can think of is: 1. Make a dialog box that looks like a message box and don't set a default button in it 2. If you want the message to have Vista/7 styles on Vista/7, use XMessageBox - A reverse-engineered MessageBox()[^] and don't set a default button. 3. Hooks. Either keyboard or API. This is a rather big way of doing it, so you would want to try this as a last resort. I wish that more people think like you. While typing this message an update box popped up as I hit the space bar. :D -
Hi I have an application where a user types a message into an edit control, after they have exceeded a certain number of characters they are shown a warning. ie AfxMessageBox("you have exceeded X number of characters"); it seems that if the user is typing fast by pressing return of the space bar this is calling the OnOK and quickly turning off the message box so the users are not seeing the warning. Does anyone know if there is a way you can disable the return key and the space key on Afxmessagebox ? i could create a custom dialog to do this but that seems a long way round can anyone help thanks Simon
si_69 wrote:
I have an application where a user types a message into an edit control, after they have exceeded a certain number of characters they are shown a warning. ie AfxMessageBox("you have exceeded X number of characters");
This sounds messy. Why not just send the edit control a
EM_LIMITTEXT
message?si_69 wrote:
it seems that if the user is typing fast by pressing return of the space bar this is calling the OnOK and quickly turning off the message box so the users are not seeing the warning.
You should initially disable the OK button and only enable it if all of the criteria have been met.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather