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. Get all controls on a form

Get all controls on a form

Scheduled Pinned Locked Moved C / C++ / MFC
9 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.
  • B Offline
    B Offline
    braune
    wrote on last edited by
    #1

    Is there an easy way to cycle through all the controls on a form. I want to be able to determine if an entry has been made in a certain control (edit box) that is a required field. These required fields can change by user. Eric

    H M D 3 Replies Last reply
    0
    • B braune

      Is there an easy way to cycle through all the controls on a form. I want to be able to determine if an entry has been made in a certain control (edit box) that is a required field. These required fields can change by user. Eric

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      Do you want this cycle for controls on your program or other programs?


      WhiteSky


      B 1 Reply Last reply
      0
      • H Hamid Taebi

        Do you want this cycle for controls on your program or other programs?


        WhiteSky


        B Offline
        B Offline
        braune
        wrote on last edited by
        #3

        I want to cycle through the edit boxes on my screen, without have to put in all the IDC_??? names. Here is a sample of what I am doing: if ((sLabelName[i]=="IDC_STATIC_COMPANY")&&(iLabelRequired[i]==1)) { GetDlgItemText(IDC_COMPANY, sTemp); if (sTemp.GetLength()

        1 Reply Last reply
        0
        • B braune

          Is there an easy way to cycle through all the controls on a form. I want to be able to determine if an entry has been made in a certain control (edit box) that is a required field. These required fields can change by user. Eric

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          I suppose you can enumerate the child windows looking for edit controls, something like this (I'm assuming you're using MFC, based on the code you posted):

          BOOL CALLBACK MyDialogEnumChildProc(HWND hwnd, LPARAM lParam)
          {
          TCHAR szClassName[32];
          if (::GetClassName(hwnd, szClassName, 32))
          {
          if (!_tcsicmp(szClassName, _T("EDIT")))
          {
          CMyDialog *pMyDialog = (CMyDialog *)lParam;

               // Edit control found - do something here
            }
          

          }

          return TRUE;
          }

          ...

          void CMyDialog::SomeFunc()
          {
          ::EnumChildWindows(*this, MyDialogEnumChildProc, (LPARAM)this);
          }

          Mark

          Mark Salsbery Microsoft MVP - Visual C++

          1 Reply Last reply
          0
          • B braune

            Is there an easy way to cycle through all the controls on a form. I want to be able to determine if an entry has been made in a certain control (edit box) that is a required field. These required fields can change by user. Eric

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

            braune wrote:

            I want to be able to determine if an entry has been made...

            At what point are you doing this check?


            "A good athlete is the result of a good and worthy opponent." - David Crow

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            B 1 Reply Last reply
            0
            • D David Crow

              braune wrote:

              I want to be able to determine if an entry has been made...

              At what point are you doing this check?


              "A good athlete is the result of a good and worthy opponent." - David Crow

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              B Offline
              B Offline
              braune
              wrote on last edited by
              #6

              I want to do the check when the user clcks a button to perform an operation. The first item of business for this operation would be to field validation, ie. make sure the required fields have entries and they are of a minimum length. Eric

              D 1 Reply Last reply
              0
              • B braune

                I want to do the check when the user clcks a button to perform an operation. The first item of business for this operation would be to field validation, ie. make sure the required fields have entries and they are of a minimum length. Eric

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

                braune wrote:

                I want to do the check when the user clcks a button to perform an operation.

                Do not enable the button until all conditions have been met. Otherwise, this just leads to confusion.


                "A good athlete is the result of a good and worthy opponent." - David Crow

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                B 2 Replies Last reply
                0
                • D David Crow

                  braune wrote:

                  I want to do the check when the user clcks a button to perform an operation.

                  Do not enable the button until all conditions have been met. Otherwise, this just leads to confusion.


                  "A good athlete is the result of a good and worthy opponent." - David Crow

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  B Offline
                  B Offline
                  braune
                  wrote on last edited by
                  #8

                  Its not quite that simply. I have multiple customers who have different requirements. Here is what I am doing: I have created an external file that I read in when the program starts. The external file contains a list of the fields that are required and the minimum length of each. When I read the file in I set all the labels for these fields to RED, so the user knows they are required fields. I set the labels using the following: if ((sLabelName[i]=="IDC_STATIC_COMPANY")&&(iLabelRequired[i]==1)) m_stCOMPANY.SetTextColor(LIGHTRED); if ((sLabelName[i]=="IDC_STATIC_WELLNAME")&&(iLabelRequired[i]==1)) m_stWELLNAME.SetTextColor(LIGHTRED); I would rather cycle through all the labels on the form, rather than putting them in statically. When the user selects a button I do much the same to test, except using the editbox controls to correct if required and the minimum length. Hope this info helps. Eric

                  1 Reply Last reply
                  0
                  • D David Crow

                    braune wrote:

                    I want to do the check when the user clcks a button to perform an operation.

                    Do not enable the button until all conditions have been met. Otherwise, this just leads to confusion.


                    "A good athlete is the result of a good and worthy opponent." - David Crow

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    B Offline
                    B Offline
                    braune
                    wrote on last edited by
                    #9

                    Another thought is, can I just use the variable to reference the control? ie. sLabelName[i].text, GetDlgItemText(sControlName[i], sTemp); Eric

                    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