473,503 Members | 1,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8448
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1382
by: E-Cube | last post by:
Hello All, I have a datetimepicker whose initial format is: DateTimePicker1.Format = DateTimePickerFormat.Custom DateTimePicker1.CustomFormat = " " DateTimePicker1.Checked = False which will...
9
3934
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
9
5025
by: Ed Crowley | last post by:
I have a DateTimePicker control on my form that is displaying the date format in UK format (dd/mm/yy). However, in my code dtpStartDate.Value gives a date in US format, but...
0
903
by: Steve Cutting | last post by:
Hi all, I have created a form used for entry of repair details into a table on a MSDE database. I am using a datetimepicker for entry of the repair date. It is set to SHORT display format and I...
2
3369
by: Chris Fairman | last post by:
NG, Maybe I'm missing a key step, but it seems when typing dates into a DateTimePicker control (format = 'Short'), the controls' .text property is not updated until the control losses focus. ...
5
5425
by: Alpha | last post by:
I have a DateTimePicker control that originally displays "1/1/1900" on screen. I want to change it to current date when a user clicks on it. I use the follow code but nothing is happening. Can...
5
7616
by: Terry | last post by:
My system short date format is dd/mm/yy. The DateTimePicker returns mm/dd/yyyy hh:mm:ss PM. I need to get this value formated into dd/mm/yyyy regardless of the system short date format, what...
0
2579
by: tschroeder250 | last post by:
Hi Everyone, There are so many Nullable DateTimePickers out there that this post may not even be found among all the others, but I wanted to try. First, I want to thank all the authors of the...
11
4986
by: jessy | last post by:
Hi, I have a problem with my DateTimePicker javascript code which i downloaded , the problem is when i pick the date and the date appears in my Text Field and i click Submit the date which i picked...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7089
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5581
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.