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. prevent window closing

prevent window closing

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
4 Posts 4 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.
  • A Offline
    A Offline
    Arrun
    wrote on last edited by
    #1

    i have created a modal window using MFC, as soon as ENTER key is pressed the window is destroyed. what to do to avoid this?

    M C A 3 Replies Last reply
    0
    • A Arrun

      i have created a modal window using MFC, as soon as ENTER key is pressed the window is destroyed. what to do to avoid this?

      M Offline
      M Offline
      Monty2
      wrote on last edited by
      #2

      Add a function to the dialog class

      //In MyDlg.h file
      virtual void OnOK();

      //in MyDlg.Cpp
      void CMyDlg::OnOK()
      {
      //Remove this line if already there
      //CDialog::OnOK();
      }

      hope this helps and get a good MFC book :D


      C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg

      1 Reply Last reply
      0
      • A Arrun

        i have created a modal window using MFC, as soon as ENTER key is pressed the window is destroyed. what to do to avoid this?

        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #3

        Add a handler for the Ok and Cancel buttons and remove the call to OnOk() and OnCancel() in these functions.

        1 Reply Last reply
        0
        • A Arrun

          i have created a modal window using MFC, as soon as ENTER key is pressed the window is destroyed. what to do to avoid this?

          A Offline
          A Offline
          Antony M Kancidrowski
          wrote on last edited by
          #4

          I prefer to override PreTranslateMessage and handle the CR myself

          BOOL CMyDialog::PreTranslateMessage(MSG* pMsg)
          {
            if ((pMsg->message == WM_KEYUP) || (pMsg->message == WM_KEYDOWN))
            {
              if (pMsg->wParam == VK_RETURN)
              {
                // TODO: Process all we want from the RETURN key

          // Ignore further processing
                return TRUE;
              }
            }
            return CDialog::PreTranslateMessage(pMsg);
          }

          Ant. I'm hard, yet soft.
          I'm coloured, yet clear.
          I'm fruity and sweet.
          I'm jelly, what am I? Muse on it further, I shall return!
          - David Walliams (Little Britain)

          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