当前位置:编程学习 > C#/ASP.NET >>

C# 调用 Windows API 如何改变外部应用程序中 DateTimePicker 控件中的 Value 值?

对于该问题,我现在可以把 DateTimePicker 控件的显示时间(Text值)修改成功,但是 DateTimePicker 控件的 Value 不能够被修改,不知哪位大神指导一下,能够实现 不仅 Text 值能够修改,Value 值也能够修改的功能,用其它的方法也可以的,只要能实现这个目的就好...我的代码如下:
              double retVal = 0;
            int processId = 0;
            int structMemLen = Marshal.SizeOf(typeof(Windows_API.SYSTEMTIME));
            IntPtr hndProc = IntPtr.Zero;//内存区域的起始地址
              IntPtr lpAddress = IntPtr.Zero;
            byte[] buffer = new byte[structMemLen];

            Windows_API.SYSTEMTIME sysTime = new Windows_API.SYSTEMTIME();
            //Assign the values as you prefer
            sysTime.wYear = 2012;
            sysTime.wMonth = 5;
            sysTime.wDay = 20;

            IntPtr dataPtr = Marshal.AllocHGlobal(structMemLen);
            Marshal.StructureToPtr(sysTime, dataPtr, true);
            Marshal.Copy(dataPtr, buffer, 0, structMemLen);
            Marshal.FreeHGlobal(dataPtr);

            //获取进程 Id
            retVal = Windows_API.GetWindowThreadProcessId(ww.WindowHandle, out processId);
            //打开进程
            hndProc = Windows_API.OpenProcess(Windows_API.PROCESS_ALL_ACCESS, false, processId);

            NMHDR[] myNMHDR = new NMHDR[1];
            
            //申请内存空间
            lpAddress =
                Windows_API.VirtualAllocEx(hndProc, (IntPtr)null, (uint)Marshal.SizeOf(typeof(NMHDR)),
                Windows_API.AllocationType.Commit | Windows_API.AllocationType.Reserve, Windows_API.MemoryProtection.ExecuteReadWrite);

            myNMHDR[0].hwndFrom = ww.WindowHandle;
            myNMHDR[0].idFrom = 0;
            myNMHDR[0].code = 0;

            //向申请的内存中写入值
            Windows_API.WriteProcessMemory(hndProc, lpAddress, buffer, buffer.Length, IntPtr.Zero);

            //能改变 Text 值,但是不能改变 Value 值
            int m11 = Windows_API.SendMessage(wdtp.WindowHandle, Windows_API.DTM_SETSYSTEMTIME, (IntPtr)Windows_API.GDT_VALID, lpAddress);

            Windows_API.CloseHandle((int)hndProc); 外部程序 DateTimePicker 控件 windows API 修改 时间 控件 Value 值 C# .NET --------------------编程问答-------------------- 各位大神帮帮忙呗,急呀...... --------------------编程问答-------------------- 为什么还没有人 回答你啊。。。


这个问题困扰我很久了,我赋值都赋不上去

烦死人了
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,