以下的方法都无法发送成功
a = Format(Now, "yyyy M dd")
SendMessage 控件名柄, DTM_SETFORMAT, 0, ByVal aSendMessage 控件名柄, WM_SETTEXT, 0, ByVal a

解决方案 »

  1.   

    SysDateTimePick32 是不是VB中的 DTPicker ?也是无法通过SendMessage 来发送消息给DTPicker
      

  2.   

    终于找了两段代码,一个是C++ 一个是C# 希望高手们把这两段代码转成VB代码
    C#代码
    //===============================时间结构=======
    /// <summary>
    /// 时间类型
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public class SYSTEMTIME
    {
    public ushort wYear;
    public ushort wMonth;
    public ushort wDayOfWeek;
    public ushort wDay;
    public ushort wHour;
    public ushort wMinute;
    public ushort wSecond;
    public ushort wMilliseconds;
    }
    //=============================================
    [DllImport("user32.dll")]
    public static extern int SetFocus(IntPtr hwnd);
    [DllImport("user32.dll")]
    public static extern int SendMessage(int hWnd, int msg, int wParam, SYSTEMTIME lparam);
    [DllImport("user32.dll")]
    public static extern int SendMessage(int hWnd, int msg, int wParam, int lparam);
    [DllImport("user32.dll")]
    public static extern int PostMessage(int hWnd, int msg, int wParam, int lparam);/// <summary>
    /// 设置日期控件值
    /// </summary>
    /// <param name="dtpHwnd">日期控件句柄</param>
    /// <param name="dt">日期值</param>
    /// <returns>成功返回true 否则返回false</returns>
    public static bool SetDateTimePickerValue(IntPtr dtpHwnd, DateTime dt)
    {
    SYSTEMTIME stT = new SYSTEMTIME();
    stT.wYear = (ushort)dt.Year;
    stT.wMonth = (ushort)dt.Month;
    stT.wDay = (ushort)dt.Day;
    stT.wHour = (ushort)0;
    stT.wMinute = (ushort)0;
    stT.wSecond = (ushort)0;
    stT.wMilliseconds = (ushort)0;
    int rr=SetFocus(dtpHwnd);
    int jj=SetFocus(new IntPtr(rr));
    int yy = SendMessage(dtpHwnd.ToInt32(), 0x0007, 0, 0);
    int r = SendMessage(dtpHwnd.ToInt32(), 0x00001002, 0x00000000, stT);
    int yyy = PostMessage(dtpHwnd.ToInt32(), 0x000F, 0, 0);
    if (r == 1)
    {
    return true;
    }
    else
    {
    return false;
    }
    }
    C++代码
    //================
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    DWORD pid;
    void *pAddr;
    HANDLE hProcess;
    SYSTEMTIME st;HWND hwndParent = FindWindow("TForm1", "Temp"); //这两行根据实际情况更改
    HWND hwnd = FindWindowEx(hwndParent, NULL, "TDateTimePicker", NULL);if (hwnd != NULL)
    {
    GetWindowThreadProcessId(hwndParent, &pid);
    hProcess = OpenProcess(PROCESS_VM_READ|PROCESS_VM_WRITE
    |PROCESS_VM_OPERATION, FALSE, pid);
    if (hProcess != NULL)
    {
    pAddr = VirtualAllocEx(hProcess, NULL, sizeof(SYSTEMTIME),
    MEM_COMMIT, PAGE_READWRITE);
    if (pAddr != NULL)
    {
    GetSystemTime(&st);
    st.wHour = 9;
    st.wMinute = 52;
    st.wSecond = 32;if (WriteProcessMemory(hProcess, pAddr, &st, sizeof(SYSTEMTIME),
    NULL))
    {
    SendMessage(hwnd, DTM_SETSYSTEMTIME, 0 , (LPARAM)pAddr);
    }
    VirtualFreeEx(hProcess, pAddr, 0, MEM_RELEASE);
    }
    CloseHandle(hProcess);
    }
    }
    }