Home > Back-end >  C # call the Windows API changes the Value of the external application DateTimePicker control Value?
C # call the Windows API changes the Value of the external application DateTimePicker control Value?

Time:10-10

For this problem, I can now put the DateTimePicker control display time (Text Value) is changed, but the DateTimePicker control Value can't be modified, I don't know what a great spirit to guide, to realize not only can modify the Text values, the Value Value can also modify functions, with other methods can also be, as long as can achieve this... My code is as follows:
Double retVal=0;
Int processId=0;
Int structMemLen=Marshal. SizeOf (typeof (Windows_API. SYSTEMTIME));
IntPtr hndProc=IntPtr. Zero;//the starting address of the memory area
IntPtr lpAddress=IntPtr. Zero;
Byte [] buffer=new byte [structMemLen];

Windows_API. SYSTEMTIME sysTime=new Windows_API. SYSTEMTIME ();
//Assign the values as you --
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);

//get the process Id
RetVal=Windows_API. GetWindowThreadProcessId (ww) WindowHandle, out processId);
//open the process
HndProc=Windows_API. OpenProcess (Windows_API PROCESS_ALL_ACCESS, false, processId);

NMHDR [] myNMHDR=new NMHDR [1].

//the application memory space
LpAddress=
Windows_API. VirtualAllocEx (hndProc (IntPtr), null, (uint) Marshal. SizeOf (typeof (NMHDR)),
Windows_API.AllocationType.Com MIT | Windows_API. AllocationType. Reserve, Windows_API. MemoryProtection. ExecuteReadWrite);

MyNMHDR [0]. HwndFrom=ww. WindowHandle;
MyNMHDR [0]. IdFrom=0;
MyNMHDR [0]. Code=0;

//to write values to the application of memory
Windows_API. WriteProcessMemory (hndProc lpAddress, buffer, buffer. The Length, IntPtr. Zero).

//can change the Text Value, but can not change the Value Value
Int m11=Windows_API. SendMessage (WDTP. WindowHandle, Windows_API DTM_SETSYSTEMTIME, (IntPtr) Windows_API. GDT_VALID, lpAddress);

HndProc Windows_API. CloseHandle ((int));
  • Related