|
In this case, I would make a function validating every editbox content. And if all are ok, then return true.
If you have lot of EditBoxes (I have one dialog with 24 coloured comboboxes), you can make it dinamically. I put the example to NUM_EDITS different editboxes.
CEdit* m_aPEdits [NUM_EDITS];
.
void CMyEdit::OnInitDialog ()
{
m_aPEDits [0] = (CEdit*) GetDlgItem(IDC_MY_EDIT1);
m_aPEDits [1] = (CEdit*) GetDlgItem(IDC_MY_EDIT2);
m_aPEDits [2] = (CEdit*) GetDlgItem(IDC_MY_EDIT3);
m_aPEDits [3] = (CEdit*) GetDlgItem(IDC_MY_EDIT4);
}
BOOL CMyEdit::ValidateEditContents ()
{
int nError = 0;
for (int i = 0; i < NUM_EDITS; i++)
{ int nTemp = -1;
nTemp = itoa (m_aPEdits[i]->GetDialogText ());
if ( ((10 * i) < nTemp) && (nTemp < (10 * (i+1))) )
continue;
nError++;
}
if (!nError)
return TRUE;
return FALSE;
}
void CMyEdit::OnOK ()
{
if (ValidateEditContents ())
m_bDlgOK = TRUE;
}
void SomeClass::A_Function ()
{
CMyDialog newDlg;
EditStartLabel:
if (IDCANCEL == newDlg.DoModal ())
goto EditEndLabel;
if (!newDlg.m_bDlgOK)
{ MessageBox ("One of the edits has an invalid value, please correct it", "Error", MB_OK);
goto EditStartLabel;
}
EditEndLabel:
return;
}
I know that is not an elegant code, but it works perfectly. I won't probably use this structure in my next project or if i rewrite this one in the future, so any tip, correction, opinion... will be wellcome.
But to start getting the concept about data validation in a "simple" way I think is good
Hope it helps
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Goto/Labels !!! your code belongs to the Coding Horror forum !
|
|
|
|
|
I know , it was my first MFC programm but the final project of studies, my teacher was "Dr." in java and wanted a particular structure very easy to read, he changes my structure at the third month . So I started to ask him what he wanted before coding new things.
Why do you think I am going to rewrite my whole programm?
It has some code horrors (like this) that I want to erase and I want to add language support, "standard" windows functions like undo, copy, paste... and port some things to DLLs.
But the doubt was about validation and functionality and this aspect is quite clear
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
you could start by changing your code to using while/for loops, because goto/labels don't bring anything useful here. actually, the only point they could be useful is to get out of several nested loops, for performance purpose... i don't see that in you code
|
|
|
|
|
I still have lot to learn, thanks for the advice I had thought use the do... while (!m_bDlgOk)
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
toxcct wrote: to restrict an edit to a given range, you could attach it a spin control.
That would not keep the user from typing 11 into the control.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
yeah, i figured that out after i posted...
|
|
|
|
|
in MFC you can use:
DDV_MinMaxInt(pDX, IDC_EDIT_BOX, 1, 10);
in the function DoDataExchange of your dialog...
|
|
|
|
|
Haroon Sarwar wrote: DDV_MinMaxInt(pDX, IDC_EDIT_BOX, 1, 10);
This is a bad idea as it falsely gives the user the impression that everything is fine until they decide to click the OK button. Then they get some sort of error message. It's better to disable the OK button until all controls contain valid data.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
thanks for the piece of code.. now i have another doubt.. can i use this piece of code multiple times in the DoDataExchange Function..
something like this,
<br />
DDX_Control(pDX, IDC_EDIT1, m_edit1);<br />
DDX_Text(pDX, IDC_EDIT2, m_edit2);<br />
DDX_Text(pDX, IDC_EDIT3, m_edit3);<br />
DDV_MinMaxInt(pDX, IDC_EDIT1, 1, 10);<br />
DDV_MinMaxInt(pDX, IDC_EDIT2, 1, 20);<br />
DDV_MinMaxInt(pDX, IDC_EDIT3, 20, 30); <br />
|
|
|
|
|
Chandrasekharanp wrote: ...can i use this piece of code multiple times in the DoDataExchange Function..
Yes, but they don't do validation until the OK button is clicked.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Are you using MFC? What is it that you are wanting to do if the entered value is out-of-range (e.g., disable the OK button)? A simple solution is to handle the EN_CHANGE notification.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
yes i am doing this in MFC. when it enters out of range it should pop up a message.. that can be done.
|
|
|
|
|
If you provided a handler for the EN_KILLFOCUS notification, you could do validation at the time the control loses focus. Still not an optimal solution IMO.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Can anybody tell me how to insert an icon in dialogue box ?
Regards,
Shaiju
|
|
|
|
|
in the resource editor add a picture control and set it's Type to Icon, then set the Image property to the ID of the icon...
|
|
|
|
|
You must use of LoadIcon for load icon and then use of SetIcon of course you need to a static control.
|
|
|
|
|
Can anybody explain me how to insert a Control Panel Icon in Edit box ?
Regards
|
|
|
|
|
Edit controls typically do not contain icons. What exactly are you trying to accomplish?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi ALL,
I am using Propertysheet class in my project in which I add number of
pages in it.
I want to acccess pointer of this propersheet in one menu function.
void
CMainFrame::OnOpenWebSite()
{
COpenWebSiteShet openWebSiteDlg;
// COpenWebSiteShet derived from CProperSheet class.
if(ID_WIZFINISH == openWebSiteDlg.DoModal())
{
COpenWebSiteShet *pSheet = (COpenWebSiteShet*)GetParent();
}
pSheet is always get NULL handle. So how can get the correct handle of
propertySheet in Mainframe class.
Thanks in Advance
Om
|
|
|
|
|
You could try this :-
void
CMainFrame::OnOpenWebSite()
{
COpenWebSiteShet openWebSiteDlg;
// COpenWebSiteShet derived from CProperSheet class.
if(ID_WIZFINISH == openWebSiteDlg.DoModal())
{
COpenWebSiteShet *pSheet = &openWebSiteDlg;
}
the GetParent() is going to try and return the CMainFrame's parent, which is in most cases as you noted NULL, and you already have the address of the PropertySheet because you created it on the stack.
|
|
|
|
|
At the point you are calling GetParent() , the window associated with openWebSiteDlg has been destroyed. Once DoModal() has returned, you can only access openWebSiteDlg 's member variables.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
i have a console application.
how can i detect when the process is terminated through task manager?
i tried using SetConsoleCtrlHandler() function. it catches the signal when we end the task through task manager. but it can not detect when the process is terminated from the processes tab of task manager.
can anyone help me.
Thanks in advance.
|
|
|
|
|
harsha u wrote: how can i detect when the process is terminated through task manager?
you can't determine when application is cut off by TaskMagr!. there is no way except you put a monitoring application which monitor application at regular interval.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Thanks a lot Alok.
That gave me some clarification.
|
|
|
|