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. Dialog Help!

Dialog Help!

Scheduled Pinned Locked Moved C / C++ / MFC
c++questioncomjsonhelp
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.
  • J Offline
    J Offline
    Joseph LeBlanc
    wrote on last edited by
    #1

    Hello, I'm working on a dialog for one of my projects that allows the user to enter various program settings. Since most of the values that must be entered are numerical I have to check them to make sure they are in the right range, etc. I've created integer member variables for every edit box I have on my dialog and set the range on each, however, if the user presses backspace to clear the 0 that is automatically put in the edit box they get yelled at instantly with a very annoying "Please Enter A Number" message box. What I would like to do is change these variables to CStrings and then make sure that all values are exceptable when the user clicks the OK button of my dialog. However, when I create a handle to capture the BN_CLICKED message of the OK button, add some code and run my program, the dialog box remains when the user presses OK. The dialog box is invoked from the rest of the program in an if statement: if (MyDialog.DoModal()==IDOK) ... How can I have my dialog do all necessary value checking when the user clicks OK and still close and return IDOK to the main program? I'm new to the world of MFC and Visual C++ and I haven't had any luck finding anything like this. I really appreciate any help, thanks! Joseph LeBlanc, unixd0od@hotmail.com

    C L 2 Replies Last reply
    0
    • J Joseph LeBlanc

      Hello, I'm working on a dialog for one of my projects that allows the user to enter various program settings. Since most of the values that must be entered are numerical I have to check them to make sure they are in the right range, etc. I've created integer member variables for every edit box I have on my dialog and set the range on each, however, if the user presses backspace to clear the 0 that is automatically put in the edit box they get yelled at instantly with a very annoying "Please Enter A Number" message box. What I would like to do is change these variables to CStrings and then make sure that all values are exceptable when the user clicks the OK button of my dialog. However, when I create a handle to capture the BN_CLICKED message of the OK button, add some code and run my program, the dialog box remains when the user presses OK. The dialog box is invoked from the rest of the program in an if statement: if (MyDialog.DoModal()==IDOK) ... How can I have my dialog do all necessary value checking when the user clicks OK and still close and return IDOK to the main program? I'm new to the world of MFC and Visual C++ and I haven't had any luck finding anything like this. I really appreciate any help, thanks! Joseph LeBlanc, unixd0od@hotmail.com

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Ah - the dreaded M$ screwed up DDX bug. You make them CStrings, as you thought, and keep the ints as a seperate variable. Hungarian notation is good here, ie m_szValue/m_iValue. Now go to your dialog editor and click on each edit box and add a handler function for EN_CHANGE ( from memory, it's the one that you get when someone types text ). Now in your handler, UpdateData() to get the value in, parse it and pass the value to the int only if it is valid, but bring up a dialog only if the value given is positively wrong, rather than empty or on the way to being right ( i.e. if you accept 5-100, don't complain about < 100 until user presses OK, as they may have been entering 10, 27, 43, etc ). Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.

      1 Reply Last reply
      0
      • J Joseph LeBlanc

        Hello, I'm working on a dialog for one of my projects that allows the user to enter various program settings. Since most of the values that must be entered are numerical I have to check them to make sure they are in the right range, etc. I've created integer member variables for every edit box I have on my dialog and set the range on each, however, if the user presses backspace to clear the 0 that is automatically put in the edit box they get yelled at instantly with a very annoying "Please Enter A Number" message box. What I would like to do is change these variables to CStrings and then make sure that all values are exceptable when the user clicks the OK button of my dialog. However, when I create a handle to capture the BN_CLICKED message of the OK button, add some code and run my program, the dialog box remains when the user presses OK. The dialog box is invoked from the rest of the program in an if statement: if (MyDialog.DoModal()==IDOK) ... How can I have my dialog do all necessary value checking when the user clicks OK and still close and return IDOK to the main program? I'm new to the world of MFC and Visual C++ and I haven't had any luck finding anything like this. I really appreciate any help, thanks! Joseph LeBlanc, unixd0od@hotmail.com

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        If you do decide to override the click of the OK Button, the last line of that function should be CDialog::OnOK(); so: void MyDialog::OnOK() { .......... //whatever CDialog::OnOK(); }

        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