如何修改SysDateTimePick32 日期控件的日期?

Amdlcom 2007-08-14 09:00:04
以下的方法都无法发送成功
a = Format(Now, "yyyy M dd")
SendMessage 控件名柄, DTM_SETFORMAT, 0, ByVal a

SendMessage 控件名柄, WM_SETTEXT, 0, ByVal a
...全文
833 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Amdlcom 2007-09-06
  • 打赏
  • 举报
回复
终于找了两段代码,一个是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);
}
}
}
Amdlcom 2007-08-15
  • 打赏
  • 举报
回复
高手在哪里?分不够我再加呀~~再不够我去借啊~~~~~帮帮忙吧

1,453

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧