473,847 Members | 1,856 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 "DateTimePicker 1",IDC_REGATTA_ DATE,"SysDateTi mePick32",
DTS_UPDOWN | WS_TABSTOP,116, 77,64,14

The text for a format of Time is as follows:

CONTROL "DateTimePicker 2",IDC_CREATE_S TART_TIME,
"SysDateTimePic k32",DTS_RIGHTA LIGN | 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 "DateTimePicker 1",IDC_REGATTA_ DATE,"SysDateTi mePick32",
DTS_UPDOWN | WS_TABSTOP | 0x8,116,77,64,1 4

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 8508
"Edward Mitchell" <em*******@nosp am.ieee.org> wrote in message
news:u1******** ******@TK2MSFTN GP11.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 "DateTimePicker 1",IDC_REGATTA_ DATE,"SysDateTi mePick32",
DTS_UPDOWN | WS_TABSTOP,116, 77,64,14

The text for a format of Time is as follows:

CONTROL "DateTimePicker 2",IDC_CREATE_S TART_TIME,
"SysDateTimePic k32",DTS_RIGHTA LIGN | 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 "DateTimePicker 1",IDC_REGATTA_ DATE,"SysDateTi mePick32",
DTS_UPDOWN | WS_TABSTOP | 0x8,116,77,64,1 4

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.or g> wrote in message
news:ru******** *************** *********@4ax.c om...
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_T IME);
DWORD dwStyle = pTime->GetStyle();
pTime->SetStyle((dwSt yle & ! DTS_SHORTDATEFO RMAT) | 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******** ******@TK2MSFTN GP10.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.or g> wrote in message
news:ru******** *************** *********@4ax.c om...
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_T IME);
pTime->ModifyStyle(DT S_SHORTDATEFORM AT, 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*******@nosp am.ieee.org> wrote in message
news:OE******** ******@TK2MSFTN GP12.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_UPDO WN 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_T IME);
DWORD dwStyle = pTime->GetStyle();
pTime->SetStyle((dwSt yle & ! DTS_SHORTDATEFO RMAT) | 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******@onlin e.microsoft.com > wrote in message
news:1k******** ******@cpmsftng xa07.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_T IME);
pTime->ModifyStyle(DT S_SHORTDATEFORM AT, 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
1405
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 change to DateTimePicker1.Format = DateTimePickerFormat.Short
9
3979
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 will not set the value of the control and will leave the checked status of the checkbox to false when a user selects a new date. this works fine when using the control on a win2k machine but if we use it on a win XP box and call
9
5048
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 dtpStartDate.Value.ToString() gives the date in the required UK format! Any ideas? All system locale settings are set to British/UK settings.
0
923
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 have UP/DOWN enabled. The only 3 references to this control in my code are: 1. in my form load event datRepairDate.Value = Date.Today
2
3390
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. I'm handling an <enter> key event on a DateTimePicker control. Essentially I want to give a user the ability to type a date in the DTP, and press <enter> and have a DataGrid populate with user supplied data from the DTP control.
5
5440
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 someone tell me what I'm doing wrong? Thanks, Alpha private void dtpLastOdoDate_Click(object sender, System.EventArgs e) { dtpLastOdoDate.Value = DateTime.Today.Date; }
5
7694
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 do I need to use please. Regards Terry
0
2605
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 code I used as a starting point. Second, I hope this code helps someone as much as they helped me. I have built a Nullable DateTimePicker and NullableCalendarColumn/Cell/EditingControl that is nearly 100% complete, as far as I can tell. There is...
11
5033
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 is not sent to the DB and instead the default value of the text field which is 00-00-0000 is Sent so what i need is to make the value i picked replace the value of the Text Field and i cant seem to get the Js code which i downloaded . i'm...
0
9886
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9730
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10983
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10706
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9481
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5719
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5910
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4119
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3164
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.