468,514 Members | 1,636 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,514 developers. It's quick & easy.

DateTimePicker Format changes from Time to Short Date

I have a number of DateTimePicker controls, some set to dates, some set to a
format of Time. The controls are all embedded in dialogs. I created the
controls by dragging the DateTime picker from the Toolbox and then set the
Format property appropriately.

I have noticed that sometimes the Time format will reset spontaneously to
Short Date. I looked at the .rc file and found that the usual form for a
Short Date is as follows:

CONTROL "DateTimePicker1",IDC_REGATTA_DATE,"SysDateTimePic k32",
DTS_UPDOWN | WS_TABSTOP,116,77,64,14

The text for a format of Time is as follows:

CONTROL "DateTimePicker2",IDC_CREATE_START_TIME,
"SysDateTimePick32",DTS_RIGHTALIGN | DTS_UPDOWN |
DTS_SHOWNONE | WS_TABSTOP | 0x8,8,131,70,14

so I deduced that the DateTimePicker1 indicates a date and DateTimePicker2
indicates a time.

However, when I edit a date control and change the format into a Time, the
..rc file then contains the following:

CONTROL "DateTimePicker1",IDC_REGATTA_DATE,"SysDateTimePic k32",
DTS_UPDOWN | WS_TABSTOP | 0x8,116,77,64,14

and the only difference that I can see is the bar that separates the
WS_TABSTOP from the string of numbers.

I assume all the format info must be embedded into the .rc file text so I
can't see in this case what the real difference is between the Short Date
format and the Time format. However, when the resource editor reads the .rc
file it should be able to figure out the correct format. I wonder if this
difference between the use of the ...Picker2 and ...Picker1 can make the
editor make the wrong decision about which format to use when the properties
are displayed.

Is there a known problem with the format for the DateTimePicker or is there
anything I can do to keep the format the same?

I am running on XP using C++ from .NET 2003. I have an unmanaged project
that was converted from VS6.0.

Ed
--
Edward E.L. Mitchell
Web: www.racesail.org
Phone: (239)415-7039
6707 Daniel Court
Fort Myers, FL 33908
Nov 17 '05 #1
7 8088
"Edward Mitchell" <em*******@nospam.ieee.org> wrote in message
news:u1**************@TK2MSFTNGP11.phx.gbl...
I have a number of DateTimePicker controls, some set to dates, some set to a format of Time. The controls are all embedded in dialogs. I created the
controls by dragging the DateTime picker from the Toolbox and then set the
Format property appropriately.

I have noticed that sometimes the Time format will reset spontaneously to
Short Date. I looked at the .rc file and found that the usual form for a
Short Date is as follows:

CONTROL "DateTimePicker1",IDC_REGATTA_DATE,"SysDateTimePic k32",
DTS_UPDOWN | WS_TABSTOP,116,77,64,14

The text for a format of Time is as follows:

CONTROL "DateTimePicker2",IDC_CREATE_START_TIME,
"SysDateTimePick32",DTS_RIGHTALIGN | DTS_UPDOWN |
DTS_SHOWNONE | WS_TABSTOP | 0x8,8,131,70,14

so I deduced that the DateTimePicker1 indicates a date and DateTimePicker2
indicates a time.

However, when I edit a date control and change the format into a Time, the
.rc file then contains the following:

CONTROL "DateTimePicker1",IDC_REGATTA_DATE,"SysDateTimePic k32",
DTS_UPDOWN | WS_TABSTOP | 0x8,116,77,64,14

and the only difference that I can see is the bar that separates the
WS_TABSTOP from the string of numbers.

I assume all the format info must be embedded into the .rc file text so I
can't see in this case what the real difference is between the Short Date
format and the Time format. However, when the resource editor reads the ..rc file it should be able to figure out the correct format. I wonder if this
difference between the use of the ...Picker2 and ...Picker1 can make the
editor make the wrong decision about which format to use when the properties are displayed.

Is there a known problem with the format for the DateTimePicker or is there anything I can do to keep the format the same?


The difference is that 0x8 being ORd with the styles. In theory it should be
DTS_TIMEFORMAT which the SDK headers say is 0x0009, but I think that is
0x8|DTS_UPDOWN. I don't know why the IDE writes it this way. Anyway, I can
repro that the IDE looses this style on reload of the resource. I suspect
it's a bug, but I don't know if its known or what a workaround could
possibly be -- other than not letting the IDE touch the resource, or not
using VS2003 for development until they get it fixed.
--
Jeff Partch [VC++ MVP]
Nov 17 '05 #2
>I suspect
it's a bug, but I don't know if its known or what a workaround could
possibly be


It's a bug that MS have known about for ages. There's no workaround
that I know of, other than to keep hand editing the RC file - or as
I've ended up doing, ensure the control is created with the correct
style in code :(

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
Nov 17 '05 #3
I asked the team that owns this to take a look and enter the bug if it
wasn't in our database yet.

Ronald Laeremans
Visual C++ team

"David Lowndes" <da****@mvps.org> wrote in message
news:ru********************************@4ax.com...
I suspect
it's a bug, but I don't know if its known or what a workaround could
possibly be


It's a bug that MS have known about for ages. There's no workaround
that I know of, other than to keep hand editing the RC file - or as
I've ended up doing, ensure the control is created with the correct
style in code :(

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq

Nov 17 '05 #4
The DTS_TIMEFORMAT is defined as 0x0009. There is a 0x0008 (single bit)
missing in the DTS_ definitions and the 0x0009 seems to clash with the
DTS_UPDOWN if they really are single bit selectors!

Can I enforce the style with something like (in the OnInitDialog):

CDateTimeCtrl* pTime =
(CDateTimeCtrl*)GetDlgItem(IDC_CREATE_START_TIME);
DWORD dwStyle = pTime->GetStyle();
pTime->SetStyle((dwStyle & ! DTS_SHORTDATEFORMAT) | DTS_TIMEFORMAT);
...

I assume that this will ensure that the style is always the TIME format.

Ed

"Ronald Laeremans [MSFT]" <ro*****@online.microsoft.com> wrote in message
news:e4**************@TK2MSFTNGP10.phx.gbl...
I asked the team that owns this to take a look and enter the bug if it
wasn't in our database yet.

Ronald Laeremans
Visual C++ team

"David Lowndes" <da****@mvps.org> wrote in message
news:ru********************************@4ax.com...
I suspect
it's a bug, but I don't know if its known or what a workaround could
possibly be


It's a bug that MS have known about for ages. There's no workaround
that I know of, other than to keep hand editing the RC file - or as
I've ended up doing, ensure the control is created with the correct
style in code :(

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq


Nov 17 '05 #5
Hello Ed,

Thanks for your response. I did not find SetStyle method of CDateTimeCtrl,
anyway, you can call ModifyStyle to change a window's style. Please refer
to the following code:

//--------------code snippet-------------
CDateTimeCtrl* pTime = (CDateTimeCtrl*)GetDlgItem(IDC_CREATE_START_TIME);
pTime->ModifyStyle(DTS_SHORTDATEFORMAT, DTS_TIMEFORMAT);
//------------------end of-------------------

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #6
"Edward Mitchell" <em*******@nospam.ieee.org> wrote in message
news:OE**************@TK2MSFTNGP12.phx.gbl...
The DTS_TIMEFORMAT is defined as 0x0009. There is a 0x0008 (single bit)
missing in the DTS_ definitions and the 0x0009 seems to clash with the
DTS_UPDOWN if they really are single bit selectors!
As I tried to explain in my original reply, I think this 0x0009 is arrived
at by using 0x0008|DTS_UPDOWN as the 'time format' style logically includes
the 'updown' style. So it's not a clash, it's an enforcement.

Can I enforce the style with something like (in the OnInitDialog):

CDateTimeCtrl* pTime =
(CDateTimeCtrl*)GetDlgItem(IDC_CREATE_START_TIME);
DWORD dwStyle = pTime->GetStyle();
pTime->SetStyle((dwStyle & ! DTS_SHORTDATEFORMAT) | DTS_TIMEFORMAT);
...

I assume that this will ensure that the style is always the TIME format.


I realize that either this solution or Dave's dynamic creation suggestion
are about the only options, but it's still a horrible thing to have to do to
compensate for a bug in the dialog editor. The thing that really gets me is
that it seems to be thoughtfully written to add that compromised 0x08 style
value and include the DTS_UPDOWN style, but thoughtlessly written to ignore
its own scheme as well as the real DTS_TIMEFORMAT style. Awful.
--
Jeff Partch [VC++ MVP]
Nov 17 '05 #7
I appreciate the feedback. I used ModifyStyle(...) for the three time
controls and it works like a charm.

Hopefully I can remove these lines when the next .NET comes out!

Ed
"Tian Min Huang" <ti******@online.microsoft.com> wrote in message
news:1k**************@cpmsftngxa07.phx.gbl...
Hello Ed,

Thanks for your response. I did not find SetStyle method of CDateTimeCtrl,
anyway, you can call ModifyStyle to change a window's style. Please refer
to the following code:

//--------------code snippet-------------
CDateTimeCtrl* pTime = (CDateTimeCtrl*)GetDlgItem(IDC_CREATE_START_TIME);
pTime->ModifyStyle(DTS_SHORTDATEFORMAT, DTS_TIMEFORMAT);
//------------------end of-------------------

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by E-Cube | last post: by
9 posts views Thread by Ed Crowley | last post: by
reply views Thread by Steve Cutting | last post: by
2 posts views Thread by Chris Fairman | last post: by
5 posts views Thread by Terry | last post: by
11 posts views Thread by jessy | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.