|
I'm having a problem with date controls. Basically, I want the 2nd control(finalize date) to default to the date value in the first control(business date). And, the 2nd control should allow the date to be changed to a date that is within one day of the 1st control.
OnDatetimechangeDtcBusiness(NMHDR* pNMHDR, LRESULT* pResult) <br />
{<br />
COleDateTime dtMinRange;<br />
COleDateTime dtMaxRange;<br />
<br />
CString csBusDate;<br />
GetDlgItem(IDC_DTC_BUSINESS)->GetWindowText(csBusDate);<br />
<br />
COleDateTime dtBusDate;<br />
dtBusDate.ParseDateTime(csBusDate);<br />
<br />
dtMinRange.SetDate(dtBusDate.GetYear(), dtBusDate.GetMonth(), dtBusDate.GetDay() - 1);<br />
dtMaxRange.SetDate(dtBusDate.GetYear(), dtBusDate.GetMonth(), dtBusDate.GetDay() + 1);<br />
<br />
((CDateTimeCtrl*)GetDlgItem(IDC_DTC_FINALIZE_DATE))->SetRange(&dtMinRange, &dtMaxRange);<br />
m_dtFinalizeOnDate = dtBusDate;<br />
<br />
*pResult = 0;<br />
}
The 2nd date is not defaulting to the 1st date. The 2nd date is defaulting to one day after the 1st date.
Any and all comments are greatly appreciated. If you see something that could be done a better way, please let me know.
Thank you.
|
|
|
|
|
So what's the problem? Why are you using GetDlgItem() rather than an actual control variable?
"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
|
|
|
|
|
Sorry about that, I edited my message post. The problem is that the 2nd control date is defaulting to one day after the 1st control date(business date).
|
|
|
|
|
littleGreenDude wrote: The problem is that the 2nd control date is defaulting to one day after the 1st control date(business date).
Isn't that what you told it to do?
dtMaxRange.SetDate(dtBusDate.GetYear(), dtBusDate.GetMonth(), dtBusDate.GetDay() + 1);
"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
|
|
|
|
|
No. That sets the allowable range for the 2nd date control. The minimum can be one day before the date of the 1st date control, and the maximum can be up to one day after the date of the 1st control.
((CDateTimeCtrl*)GetDlgItem(IDC_DTC_FINALIZE_DATE))->SetRange(&dtMinRange, &dtMaxRange);
The user should be allowed to change the 2nd date to any value within the 3 day range. But, when they change the date in the 1st control, the range should reset and the new default date of the 2nd date control should be the value of the 1st date control.
|
|
|
|
|
littleGreenDude wrote: ...the new default date of the 2nd date control should be the value of the 1st date control.
So where/what is your code to do this?
"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
|
|
|
|
|
Right after the range is set.
m_dtFinalizeOnDate = dtBusDate;
|
|
|
|
|
Ok, is m_dtFinalizeOnDate a CDateTimeCtrl or CTime object? If the former, shouldn't you be using the SetTime() method?
"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
|
|
|
|
|
m_dtFinalizeOnDate is a COleDateTime object that is set by a CDateTimeCtrl.
|
|
|
|
|
littleGreenDude wrote: ...is set by a CDateTimeCtrl.
I'm not exactly sure what you mean by this, but your code snippet worked fine for me by making one small change.
"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
|
|
|
|
|
"is set by a CDateTimeCtrl" means the control object on the screen is the date time picker control included with the IDE.
DDX_DateTimeCtrl(pDX, IDC_DTC_FINALIZE_DATE, m_dtFinalizeOnDate);
When using ClassWizard to add a member var to the control you are given 2 options one is by control (CDateTimeCtrl), and the other is by value (COleDateTime).
I chose the latter.
COleDateTime m_dtFinalizeOnDate;
What was the one change you made?
|
|
|
|
|
littleGreenDude wrote: DDX_DateTimeCtrl(pDX, IDC_DTC_FINALIZE_DATE, m_dtFinalizeOnDate);
Did you forget to call UpdateData(FALSE) ?
littleGreenDude wrote: What was the one change you made?
Using CDateTimeCtrl .
"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
|
|
|
|
|
Why would I want to use SetTime()?
|
|
|
|
|
Can't remember off the top of my head but, this looks potentially dangerous.
dtMinRange.SetDate(dtBusDate.GetYear(), dtBusDate.GetMonth(), dtBusDate.GetDay() - 1);
What if dtBusDate.GetDay() returns a 1?
Maybe using COleDateTimeSpan would be safer?
|
|
|
|
|
You are correct. If I choose Jan 1st, it bombs. I defined COleDateTimeSpan, and it seems to work fine. Except the 2nd date is not defaulting to the same date as the 1st control.
const COleDateTimeSpan dtOneDay(1, 0, 0, 0);<br />
<br />
dtMinRange = dtBusDate - dtOneDay;<br />
dtMaxRange = dtBusDate + dtOneDay;
|
|
|
|
|
Left click on the selected item will highlite it but next right click anywhere in control will remove this highlite.
What function does this on / off highlite and can it be contolled?
I basically need to keep the highlite on untill my right click pop-up is done executing not before.
Thanks for your help.
Cheers
Vaclav
|
|
|
|
|
Shift+click and Ctrl+click not working for you?
"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 shift and ctrl works fine.
I need to do pop-up on right click ( in the control rectangle) which works fine but removes the highlite from control items.
Basically I need to keep the higlite on to show the user which items are being modified.
The way it works now - the user does not have a clue.
For example - I need the pop-up to delete selected items.
|
|
|
|
|
Vaclav_Sal wrote: The way it works now - the user does not have a clue.
For example - I need the pop-up to delete selected items.
Can you list those items in the confirmation dialog?
"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 have that working.
But I have decided that simple pop-up menu would be nicer since I do just few modifications (delete, modify single subitem)to the list which is partially visible anyway.
I'll try to set focus on the selection and see if that works.
|
|
|
|
|
Have you tried using LVS_SHOWSELALWAYS ?
"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, same results.
However, just noticed that the selection higlite rectangle does not cover the whole first (item) column - it covers item text only.Also when the color ( I assume some Windoze standard - dark blue) goes away it leaves dotted rectangle which stays when I do right click on the control.
I'll do some more research on the list control itself - this has to be documented somewhere - I hope.
Thanks for your input.
Cheers
Vaclav
|
|
|
|
|
Vaclav_Sal wrote: However, just noticed that the selection higlite rectangle does not cover the whole first (item) column - it covers item text only.
Try setting the LVS_EX_FULLROWSELECT style.
"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 migrate the project from vc6 to vs2008.
In vs2008 resource editor, the control looks nice, but when I run it, it is still the vc6 style?
Why?
Any way to show with the vs2008 style?
BTW: Is there any way to make control nicer with mfc9?
I'm working for a project that needs a better UI.
Thanks a lot.
|
|
|
|
|
Try adding this line to your stdafx.h file...
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
More info here...[^]
Most, if not all the controls you are using are common controls
provided by the operating system. If you want them to look different,
you need to draw them yourself. Search for "custom draw" and "owner draw"
here and you'll find lots of examples.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|