Get all controls on a form
-
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
Do you want this cycle for controls on your program or other programs?
WhiteSky
-
Do you want this cycle for controls on your program or other programs?
WhiteSky
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()
-
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
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++
-
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
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
-
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
-
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
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
-
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
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
-
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