现在可以显示出DATETIMEPICKER来了,代码如下,一个可以简单使用DATETIMEPICKER的类,
但是现在的问题是这样的:我的WINCE设备不是触摸屏,所以我必须用键盘来控制我的程序,但是我的程序是C#写的,在我的DATETIMEPICKER获得焦点的时候,我如何接收键盘消息呢,因为我必须接收比如回车或者TAB之类的键以便切换界面上的控件的焦点,否则程序的焦点永远落在DATETIMEPICKER上了...
using System;
using System.Runtime.InteropServices;
namespace VCANSMobilePower
{
///
/// CVMDateTimePicker 的摘要说明。
///
public class CVMDateTimePicker
{
[DllImport("Commctrl.Dll")]
public static extern bool InitCommonControlsEx(ref LPINITCOMMONCONTROLSEX lpInitCtrls);
[DllImport("coredll.Dll")]
public static extern IntPtr CreateWindowEx(int dwExStyle, string lpClassName, string lpWindowName, int dwStyle, int X, int Y, int nWidth, int nHeight, IntPtr hWndParent, int hMenu, int hInstance, string lpParam);
[DllImport("coredll.Dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("coredll.Dll")]
public static extern IntPtr SetFocus( IntPtr hWnd);
[DllImport("coredll.Dll",EntryPoint = "SendMessage")]
public static extern int SendMessage_SYSTEMTIME(IntPtr hWnd, int Msg, int wParam, ref SYSTEMTIME lParam);
[StructLayout(LayoutKind.Sequential)]
public struct LPINITCOMMONCONTROLSEX
{
public UInt32 dwSize;
public UInt32 dwICC;
}
private const int ICC_DATE_CLASSES = 256;
private const int WS_POPUP = -2147483648;
private const int WS_BORDER = 8388608;
private const int WS_CHILD = 1073741824;
private const int WS_VISIBLE = 268435456;
private const int DTM_GETSYSTEMTIME = 4097;
private const int MCM_SETCURSEL = 4098;
public struct SYSTEMTIME
{
public UInt16 wYear;
public UInt16 wMonth;
public UInt16 wDayOfWeek;
public UInt16 wDay;
public UInt16 wHour;
public UInt16 wMinute;
public UInt16 wSecond;
public UInt16 wMilliseconds;
}
public CVMDateTimePicker()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static IntPtr Show(IntPtr FormHandle,int Width, int Height)
{
IntPtr hWnd;
LPINITCOMMONCONTROLSEX myLPINITCOMMONCONTROLSEX = new LPINITCOMMONCONTROLSEX();
myLPINITCOMMONCONTROLSEX.dwICC = ICC_DATE_CLASSES;
myLPINITCOMMONCONTROLSEX.dwSize = (UInt32)Marshal.SizeOf(myLPINITCOMMONCONTROLSEX);
InitCommonControlsEx(ref myLPINITCOMMONCONTROLSEX);
hWnd = CreateWindowEx(0, "SysDateTimePick32", null, WS_VISIBLE | WS_BORDER | WS_CHILD, 0, 0, Width, Height,FormHandle, 0, 0, null);
return hWnd;
}
public static void SetDateTime(IntPtr hWnd,SYSTEMTIME st)
{
SendMessage_SYSTEMTIME(hWnd,MCM_SETCURSEL,0,ref st);
}
public static SYSTEMTIME GetDateTime(IntPtr hWnd)
{
SYSTEMTIME st = new SYSTEMTIME();
SendMessage_SYSTEMTIME(hWnd,DTM_GETSYSTEMTIME,0,ref st);
return st;
}
}
}
复制代码