|
Sorry I've not replied to this before now.
Looking at it now, it is a bit inconsistent, as the function is const, but the variable returned isn't (explicitly) const. It would probably be better to either remove the const, or to have two functions:
const CEdit* GetEditControl() const { return m_pEdit; }
CEdit* GetEditControl() { return m_pEdit; }
although it could then be argued that the const version is superfluous, as the non-const can always be assigned to a const variable if required. Having said that, if the method is called on a const date picker pointer/reference, the non-const one would then fail to compile.
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
|
|
|
|
|
I have a KillFocus event on my form which is assigned to the date time picker. During this kill focus, I want to set a new date into the date time picker, but when I do this, this will result in a crash when the code gets to the line:
CEdit::OnKillFocus(pNewWnd);
void CDateTimeEditCtrlEditCtrl::OnKillFocus(CWnd* pNewWnd)
{
CDateTimeEditCtrl* pDateTimeEditCtrl = DYNAMIC_DOWNCAST(CDateTimeEditCtrl, GetParent());
if (pDateTimeEditCtrl != NULL)
{
// send notification to parent of date time ctrl
CWnd* pParent = pDateTimeEditCtrl->GetParent();
if (pParent != NULL)
{
NMHDR nmhdr;
nmhdr.hwndFrom = pDateTimeEditCtrl->m_hWnd;
nmhdr.idFrom = pDateTimeEditCtrl->GetDlgCtrlID();
nmhdr.code = NM_KILLFOCUS;
pParent->SendMessage(WM_NOTIFY, (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
}
}
CEdit::OnKillFocus(pNewWnd); //Will crash here
}
Why is it crashing?
Thanks
|
|
|
|
|
I have submitted an updated version (3.6.1) of this control, which addresses the following:
- fixed missing and incorrect NM_KILLFOCUS notifications
- changed to compile correctly in VC7 (VS2003) and VC8 (VS2005)
- added fix to control being shown if hidden in initialising of parent
It should appear here soon!
Paul.
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
|
|
|
|
|
Thank you for this wonderful control! I have always been so frustrated with the standard datetime control.
I am having a problem with getting the control to hide when calling ShowWindow(SW_HIDE). I want to hide the date control until they select some radio button for example. When I use the following code I can't get the control to hide. I am calling this function before the window is shown if that makes any difference.
void CMyDialog::FieldHide(int control, BOOL hide)<br />
{<br />
CWnd *slot;<br />
<br />
slot=GetDlgItem(control);<br />
slot->ShowWindow(hide ? SW_HIDE : SW_SHOW); <br />
}
When I use this the control still shows up. I have had success by simply calling this function twice passing in the same parameters. The normal MS control works fine when using this code so I think the problem might be in how you are recreating the controls. Thanks for your help!
|
|
|
|
|
Yes, you're right, it is due to the re-creating. The re-creation is triggered by the first message that hits the window, if the message loop has not already picked it up. However, if the first message is WM_SHOWWINDOW, then its visiblity state is wrong when picking up the existing style in the re-creation function. I'll be publishing a new version in the next few days (to work correctly in VC7/8) which will include a fix, but in the meantime you can add the following code in the CDateTimeEditCtrl::WindowProc function, just after the call to DispatchMessage:
if (message == WM_SHOWWINDOW)
ShowWindow(wParam ? SW_SHOW : SW_HIDE);
This will ensure that if it is the WM_SHOWWINDOW message that triggers the re-creation, it retains the correct visibilty state.
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
|
|
|
|
|
Hi,
Just wanting to know if you have managed to create a VS 2005 Compilable version of the editable date time picker?
Thanks,
|
|
|
|
|
I have a VS2005 (and VS2003) compilable version, which also includes a couple of other fixes. I am hoping to post an update in the next few days.
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
|
|
|
|
|
Hello, I also search a version which is compilable with VS2005.
When do you think that you can upload these files?
Thanks in advance!
|
|
|
|
|
How to change the background color of the combo like think in the date picker control iam managed to change th efont and color of the cDatetime ctrl but not of the combo box in which it resides
|
|
|
|
|
Hi,
I would like to use the KillFocus message, but it doesn't react as I want. It only occurs when I click on the calendar button, but not when the focus leaves the CDateTimeEditCtrl control.
Your help would be very welcome...
Thanks
|
|
|
|
|
This is because the date/time control doesn't really have the focus, as the overlying edit control has it. To remedy this, you can add code to the edit control to pass the NM_KILLFOCUS notification on to the date/time control's parent when the edit control loses focus. You'll need to add this manually, as the Class wizard doesn't work properly with nested classes. Add the following to the message map of the CDateTimeEditCtrlEditCtrl:
ON_WM_KILLFOCUS()
then add the following to the CDateTimeEditCtrlEditCtrl message map declarations in the header file:
afx_msg void OnKillFocus(CWnd* pNewWnd);
and finally, add the following function to the cpp file:
void CDateTimeEditCtrlEditCtrl::OnKillFocus(CWnd* pNewWnd)
{
CDateTimeEditCtrl* pDateTimeEditCtrl = DYNAMIC_DOWNCAST(CDateTimeEditCtrl, GetParent());
if (pDateTimeEditCtrl != NULL)
{
CWnd* pParent = pDateTimeEditCtrl->GetParent();
if (pParent != NULL)
{
NMHDR nmhdr;
nmhdr.hwndFrom = pDateTimeEditCtrl->m_hWnd;
nmhdr.idFrom = pDateTimeEditCtrl->GetDlgCtrlID();
nmhdr.code = NM_KILLFOCUS;
pParent->SendMessage(WM_NOTIFY, (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
}
}
CEdit::OnKillFocus(pNewWnd);
} What you will find though is that the parent gets a NM_KILLFOCUS when passing the focus to the control, as the control immediately passes the focus onto the edit control. To stop this, add a handler for the NM_KILLFOCUS to the CDateTimeEditCtrl, modify it to return BOOL, modify the message map entry to use ON_NOTIFY_REFLECT_EX , and add the following code to it:
BOOL CDateTimeEditCtrl::OnKillfocus(NMHDR* pNMHDR, LRESULT* pResult)
{
*pResult = 0;
if (CWnd::GetFocus() == m_pEdit)
return TRUE;
return FALSE;
} This should make the notifications work as per the standard date control.
I'll add this to my list of pending updates, and post it as soon as I get some time.
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
|
|
|
|
|
Thanks for your help. I think I understand.
But I still have a problem with the OnKillfocus method : the mapping with ON_NOTIFY_REFLECT_EX doesn't accept it because of its BOOL return value (it expects a void method)...
|
|
|
|
|
Yes, it works !
In fact the problem was the name of the method : I've changed CDateTimeEditCtrl::OnKillfocus in CDateTimeEditCtrl::OnNMKillfocus and it works very well.
Thank you very much !
This KillFocus message will be useful to read the new COleDateTime only after the user has finished to write or choose it.
|
|
|
|
|
Hi, I'm not a CPP expert, but tried to add it to our solution as a separate project. It didn't compile. Do you have a compilable version under Visual Studio 2003 ?
Thx,
noy
|
|
|
|
|
Hello,
I also had an error during compilation. I have solved it this way, in the CDateTimeEditCtrlEditCtrl::OnKeyDown method :
CString sSeps(s_chDateSep);
I hope that will help you...
|
|
|
|
|
Sorry I didn't answer this one. For some reason, the notification of this, and PetitPapaNoel's reply got put in my Junk email folder.
I am hoping to go through all my articles' code soon and make sure they work in VS2003 and VS2005, and publish updates accordingly.
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
|
|
|
|
|
Can anyone tell me, how i can implement the DTS_SHOWNONE Style?
thanx in advance
Bender
|
|
|
|
|
This control was intended to be an alternative to using the standard control with the DTS_SHOWNONE style, so I hadn't thought that anyone would actually want it. Can you tell me why you need this style with this class, and what you would want to give you that you don't get already?
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
|
|
|
|
|
ah, i see
well, i want to use the control in a project, where Stingray's Objective Grid is
already heavily used.
I have to show the Date-Text in the picker in another color and i have to draw the background of the picker in another color too.(not the calender, that would be too easy )
The Problem is, i cant replace the CDateTimeCtrl class (removed #include afxdtctl.h and replaced it with my "CDateTimeCtrl.h"), i get Linker Errors (NAFXCWD.LIB->WINCTRL5.CPP) like hell in VC6
So your way of handling that problem seemed the most effective to gain control over that ...grmbl#* DatePicker Great work, by the way!!!
The DTS_SHOWNONE style is used with Objective Grid, and the customer wants to see that control in exactly that way, it is displayed in the grids.....
|
|
|
|
|
Not sure why the standard one causes you problems, but my class simply uses a standard DateTime picker, and super-imposes an edit control. If my class works for you, then I would have thought you should be able to create you own override of CDateTimeCtrl, which just does nothing.
Alternatively, although I don't intend to fully implement DTS_SHOWNONE in the way that the standard control does (i.e. with the check box etc), you could remove the ASSERTs which fire when trying to use the style in my class.
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
|
|
|
|
|
well, the standard one won't let me change the colors, thats just it
I tried to overwrite the CDateTimeCtrl of course, but that wont help, because i cant use it together with that "Objective Grid"... Plus, even if in a Testproject without the Grid, i cant change the
Textcolor in the Picker.
The checkbox is just wanted from the customerside, i for sure would not care, if i see that dumb checkbox hahaha I removed the asserts for DTS_SHOWNONE, but that did not help. And time is running out, so many other stuff todo...
But thanks for your patience man! :->
|
|
|
|
|
Thank for the great work. I need to catch the SETFOUS message, when tha edit is focused. Can you tell me how ?
Tank You.
Raffaele Eugenelo
|
|
|
|
|
To catch the control getting the focus, you can add a handler for NM_SETFOCUS to the control's parent.
(I noticed when trying this that while tabbing to the control generates this notification, clicking in the control does not. However, the behaviour in my control is exactly the same as in the standard control. If you want to catch a focus change caused by the mouse clicking in the edit control, you could try adding a WindowProc or DefWindowProc override to the CDateTimeEditCtrlEditCtrl class, and sending the WM_SETFOCUS to the parent.)
Paul.
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
|
|
|
|
|
Thanks for an insightful article with great code!
Has anyone expanded on the DateTimePicker idea to include the editing of the time of day ?
Thanks, Fred
|
|
|
|
|
Thanks - it's good to know that people find it useful.
I have often thought that there should be a better way of editing time. What kind of support did you have in mind for that?
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
|
|
|
|