DateTimePicker - OpenNETCF 1.3

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

So with OpenNETCF 1.2 we had the DateTimePicker. Its “Checked†property did
not work but we had the following code that we could use to uncheck it:

int DTM_SETSYSTEMTIME = 0x1002;
int GDT_NONE = 1;

foreach( Control c in this.Controls )
{
if( c.GetType() == typeof( DateTimePicker )){
Win32Window.SendMessage(
(IntPtr) ( Win32Window.GetWindow((IntPtr)Win32Window.FromControl(
c ),
Win32Window.GetWindowParam.GW_CHILD )),
DTM_SETSYSTEMTIME, GDT_NONE, 0 );
}
}

With the advent of OpenNETCF 1.3 we must change the
Win32Window.GetWindowParam.GW_CHILD statement to OpenNETCF.Win32.GW.CHILD in
order to get things to compile and run. Unfortunately however, this code no
longer unchecks the checkboxes though. I would also note that if you go to
the property window and set the Checked property from true to false that
OpenNETCF produces the following compile error:
“'OpenNETCF.Windows.Forms.DateTimePicker' does not contain a definition for
'Checked'â€.

So what has been changed with the DateTimePicker in the new version and is
there another way to programmatically control the state of its check boxes
that works with 1.3?

Bill
 
What's been changed is that a DTP control is hosted inside MessageWindow
,which is hosted inside generic control. For this reason you need another
level of GetWindow(GW_CHILD).
Fortunately there is also a new property called ChildHandle, which you can
use to obtain DTP control hWnd without resorting to GetWindow
 
Alex, I apologize for being so dense, but this code seems to exist in the
nether-world between C#, OpenNETCF, and MFC code and I'm confused. I'm not
sure what you mean be another "level" of GetWindow(). Also I poked around a
bit in DateTimePicker.Control and I found GetChildIndex(), and
SetChildIndex() methods, but no ChildHandle property. (I hope we aren't
talking about features to become available in .NET 2005 - we need to go live
with this code in August)

I'd be grateful if you could humor me with another post on this thread.

Bill
 
Ok, Bill, my apologies. ChildHandle is a protected member. So, what you do
is this:

foreach( Control c in this.Controls )
{
if( c.GetType() == typeof( DateTimePicker )){
IntPtr hWnd = (IntPtr) (
Win32Window.GetWindow((IntPtr)Win32Window.FromControl( c ),
Win32Window.GetWindowParam.GW_CHILD ));
hWnd = (IntPtr) ( Win32Window.GetWindow(hWnd,
Win32Window.GetWindowParam.GW_CHILD ));
Win32Window.SendMessage( hWnd, DTM_SETSYSTEMTIME, GDT_NONE, 0 );
}
}

As for the missing Checked property - we'll try to get a fix into 1.4 if
possible.
 
The ChildHandle property is protected - therefore only accessible if you
derive your own control from the DateTimePicker class. This stores the
native handle to the date time picker control itself (the child of a
modified messagewindow which itself is child of the Control implementation).
This approach (specific to .NETCF v1.0) is described in my MSDN article
here:-
http://msdn.microsoft.com/library/d...netcomp/html/HostingANativeWindowsControl.asp
The DateTimePicker control was updated for v1.3 to use this approach to
support events. I've modified the code in the vault to implement the Checked
property - so for v1.4 you'll see expected behaviour from setting the
property from the designer.

Peter

--
Peter Foot
Windows Embedded MVP
http://www.inthehand.com | http://www.peterfoot.net |
http://www.opennetcf.org
 
Back
Top