Link to home
Start Free TrialLog in
Avatar of el_rooky
el_rooky

asked on

Date Time Picker control

I have a DateTimePicker control with a checkbox ("Show None" property selected). I can check the ckeckbox with the following command:

CWnd* hWndCtrl = GetDlgItem(IDC_MYDATE);
hWndCtrl->SendMessage(DTM_SETSYSTEMTIME ,GDT_VALID, 0);


How do I check if the checkedbox is checked?

Avatar of wolfpackinc
wolfpackinc

what compiler are you using???
Avatar of el_rooky

ASKER

I am using VC++ 6
Avatar of DanRollins
Did you try:
hWndCtrl->SendMessage(DTM_SETSYSTEMTIME ,GDT_NONE, 0);

The documentation says that that will set the the control into its "no date" mode and it will cleaar the checkbox.

It also says that this will only work if the control has the DTS_SHOWNONE style.

-- Dan
Yes, I've tried that:
hWndCtrl->SendMessage(DTM_SETSYSTEMTIME ,GDT_NONE, 0) always returns 1

hWndCtrl->SendMessage(DTM_SETSYSTEMTIME ,GDT_VALID, 0) always returns 0

The 'show none' style is selected in the control.
oops, I should be using DTM_GETSYSTEMTIME instead.
But now I get an access viloation error  

hWndCtrl->SendMessage(DTM_GETSYSTEMTIME ,GDT_NONE, 0)

any idea why?
ASKER CERTIFIED SOLUTION
Avatar of Slordak
Slordak

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>But now I get an access viloation error  

You are getting an access violation becasue the LPARAM in the SendMessage call needs to point to a variable that will receive the return value:

SYSTEMTIME rST;
int nRet= hWndCtrl->SendMessage(DTM_SETSYSTEMTIME ,GDT_VALID, (LPARAM)&rST );

if ( nRet == GDT_NONE ) {
    // checkbox is unchecked
}

-- Dan
Oops, I meant:

SYSTEMTIME rST;
int nRet= hWndCtrl->SendMessage(DTM_GETSYSTEMTIME ,GDT_VALID, (LPARAM)&rST );
Dan and Slordak,
Thanks. Both sugestions worked fine. I find this method of casting the control much easier to use, though.