我想为外部系统面板中嵌入的DatePicker控件设置特定的日期值。通过SPy ++,我可以读取该控件的类名称为'SysDateTimePick32'。我有什么解决方案可以使用Excel VBA执行该操作吗?
我尝试了sevaral方法,但都失败了,例如:
API
SendMessage(Handle, WM_SETTEXT, byval 0&, ByVal "2019-01-05")
UI_Automation
valuePattern = (ValuePattern)element.GetCurrentPattern(ValuePattern.Pattern);
valuePattern.SetValue("2019-01-05")
我尝试了以下代码,但仍然无法正常工作,此行始终返回zeor: 'a = SendMessage(hControl,DTM_SETSYSTEMTIME,0,pStrBufferMemory)'
Public Const DTM_SETSYSTEMTIME = &H1002
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Const MEM_COMMIT = &H1000
Private Const PAGE_EXECUTE_READWRITE = &H40
Public Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Sub Test()
Dim hms As SYSTEMTIME
Dim hControl As Long
Dim pid As Long
Dim hProcess As Long
Dim pStrBufferMemory As Long
Dim a As Long
Dim b As Long
hms.wYear = 1982
hms.wMonth = 10
hms.wDay = 2
GetWindowThreadProcessId hControl, pid
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
pStrBufferMemory = VirtualAllocEx(hProcess, ByVal 0&, LenB(hms), MEM_COMMIT, PAGE_EXECUTE_READWRITE)
If (WriteProcessMemory(hProcess, pStrBufferMemory, hms, LenB(hms), 0)) Then
a = SendMessage(hControl, DTM_SETSYSTEMTIME, 0, pStrBufferMemory)
End If
VirtualFreeEx hProcess, pStrBufferMemory, 0, MEM_RELEASE
CloseHandle hProcess
End sub