Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Disabling Keypress on MessageBox

Disabling Keypress on MessageBox

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    si_69
    wrote on last edited by
    #1

    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

    A D 2 Replies Last reply
    0
    • S si_69

      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

      A Offline
      A Offline
      Andrew Brock
      wrote on last edited by
      #2

      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 with MB_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

      1 Reply Last reply
      0
      • S si_69

        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

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups