如何使用sendmessage更新datetimepicker [英] How do I update datetimepicker using sendmessage
问题描述
我正在尝试编写一个程序,使用SendMessage将信息发送到第三方程序。到目前为止,我已经成功使用了组合框和文本框,但是在更新DateTimePicker控件时遇到了困境。
使用SendMessage时对于DateTimePicker,它似乎不会更改日期/数据。有没有其他人遇到这个问题?
我确实希望你知道我已经在这方面工作了几天而且我用各种方式用Google搜索我知道怎么但没有拿出来一个办法。基本上,我打电话给:
我尝试了什么:
< pre lang =vb> 声明 功能 SendMessage Lib user32.dll 别名 SendMessageA( ByRef hwnd < span class =code-keyword> As Int32 , ByRef wMsg 作为 Int32 , ByRef wParam 作为 Int32 , ByRef lParam 正如 SYSTEMTIME) As Int32
< StructLayout(LayoutKind.Sequential)> 结构 SYSTEMTIME
公共 wYear As Int16
公共 wMonth As Int16
公开 wDayOfWeek As Int16
公开 wDay As Int16
公开 wHour As Int16
公共 wMinute As Int16
公共 wSecond As Int16
公开 wMilliseconds 作为 Int16
结束 结构
公共 Const DTM_FIRST As Int32 =& H1000
公开 Const DTM_GETSYSTEMTIME As Int32 =(DTM_FIRST + 1 )
公共 Const DTM_SETSYSTEMTIME 作为 Int32 =(DTM_FIRST + 2 )
公开 共享 Sub SendMessageDateToControl(ControlHandle As 整数,消息作为 日期 )
Dim hwnd,datehwnd As 整数
Dim gettime 作为 新 SYSTEMTIME
Dim changetime 作为 新 SYSTEMTIME
changetime.wDay = Message.Day
changetime.wMonth = Message.Month
changetime.wYear = Message.Year
SendMessage(ControlHandle, DTM_GETSYSTEMTIME, 0 ,gettime)
SendMess age(ControlHandle,DTM_SETSYSTEMTIME, 0 ,更改时间)
结束 Sub
公开 共享 功能 GetChildWindows( ByVal ParentHandle As IntPtr ) As IntPtr ()
Dim ChildrenList As 新列表( IntPtr )
Dim ListHandle < span class =code-keyword> As GCHandle = GCHandle.Alloc(ChildrenList)
尝试
EnumChildWindows( ParentHandle, AddressOf EnumWindow,GCHandle.ToIntPtr(ListHandle))
最后
< span class =code-keyword>如果 ListHandle.IsAllocated 那么 ListHandle.Free()
结束 尝试
返回 ChildrenList.ToArray
结束 功能
公开 共享 功能 GetWindowHandle(WindowCaption As 字符串) 整数
返回 FindWindow( Nothing ,WindowCaption)
结束 功能
私有 Sub GetControlInfo()
' 获取窗口句柄
Dim hWnd = WindowControlHandleInfo.GetWindowHandle(TextBoxWindowName.Text)
如果(hWnd = 0 )那么
MessageBox.Show( 找不到控制窗口,Application.ProductName, MessageBoxButtons.OK,MessageBoxIcon.Information)
返回
结束 如果
' 获取表单子项的所有控制句柄
Dim rtnChildWindows As IntPtr ()= WindowControlHandleInfo.GetChildWindows(hWnd)
如果 rtnChildWindows。长度= 0 然后 返回 ' 未找到任何控件
myControlInfo = 新列表( WindowControlInfo)
Dim zOrder As 整数 = 0
' 遍历每个子窗口并将其添加到myControlInfo
对于 每个 i As 整数 在 rtnChildWindows
' 获取类名
Dim strClassName 作为 字符串 = CStr (WindowControlHandleInfo.GetClassName(i))
' 获取控件标题
Dim ControlText As String = WindowControlHandleInfo.GetMesasgeFromControl(i)
myControlInfo.Add( New WindowControlInfo(strClassName,zOrder,i ,ControlText))
zOrder + = 1
下一页
结束 Sub
私有 Sub ButtonSendDateToDateTimePicker_Click(发件人 As 对象,e As EventArgs)句柄 ButtonSendDateToDateTimePicker.Click
WindowControlHandleInfo .SendMessageDateToControl(TextBoxHandelDateTimePicker.Text, 02/01/1991)
结束 Sub
我也尝试过:
公共 声明 功能 SendMessage Lib user32.dll 别名 SendMessageA( ByVal hwnd As Int32 , ByVal wMsg 作为 Int32 , ByVal wParam 作为 Int32 , ByVal lParam As String ) As Int32
Public Const WM_SETTEXT 作为 Int32 =& HC
公共 Const WM_GETTEXT As Int32 =& HD
SendMessage(chwnd,WM_SETTEXT, 0 , 02 / 01/1991)
两者都没有改变DateTimePicker的值。
公共 Const WM_GETTEXT As Int32 =& HD
SendMessage(chwnd,WM_SETTEXT, 0 , 02/01/1991)
假设上面有拼写错误,WM_SETTEXT的值为x0C。
< blockquote>这是一个错字。应该是
公共 Const WM_SETTEXT 作为 Int32 =& HC
我已更新原始问题
I am attempting to write a program that will send information to a third-party program using SendMessage. I have been successful so far with the Combo Boxes and Text Boxes, but I am running into a brick wall when it comes to updating a DateTimePicker control.
When using SendMessage to a DateTimePicker, it does not appear to change the date/data whatsoever. Has anyone else run into this problem?
I do want you to know that I have been working on this for a couple of days and I have Googled every way that I know how but have not come up with a solution. Basically, I call:
What I have tried:
Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByRef hwnd As Int32, ByRef wMsg As Int32, ByRef wParam As Int32, ByRef lParam As SYSTEMTIME) As Int32
<StructLayout(LayoutKind.Sequential)> Structure SYSTEMTIME
Public wYear As Int16
Public wMonth As Int16
Public wDayOfWeek As Int16
Public wDay As Int16
Public wHour As Int16
Public wMinute As Int16
Public wSecond As Int16
Public wMilliseconds As Int16
End Structure
Public Const DTM_FIRST As Int32 = &H1000
Public Const DTM_GETSYSTEMTIME As Int32 = (DTM_FIRST + 1)
Public Const DTM_SETSYSTEMTIME As Int32 = (DTM_FIRST + 2)
Public Shared Sub SendMessageDateToControl(ControlHandle As Integer, Message As Date)
Dim hwnd, datehwnd As Integer
Dim gettime As New SYSTEMTIME
Dim changetime As New SYSTEMTIME
changetime.wDay = Message.Day
changetime.wMonth = Message.Month
changetime.wYear = Message.Year
SendMessage(ControlHandle, DTM_GETSYSTEMTIME, 0, gettime)
SendMessage(ControlHandle, DTM_SETSYSTEMTIME, 0, changetime)
End Sub
Public Shared Function GetChildWindows(ByVal ParentHandle As IntPtr) As IntPtr()
Dim ChildrenList As New List(Of IntPtr)
Dim ListHandle As GCHandle = GCHandle.Alloc(ChildrenList)
Try
EnumChildWindows(ParentHandle, AddressOf EnumWindow, GCHandle.ToIntPtr(ListHandle))
Finally
If ListHandle.IsAllocated Then ListHandle.Free()
End Try
Return ChildrenList.ToArray
End Function
Public Shared Function GetWindowHandle(WindowCaption As String) As Integer
Return FindWindow(Nothing, WindowCaption)
End Function
Private Sub GetControlInfo()
' Get a Window's Handle
Dim hWnd = WindowControlHandleInfo.GetWindowHandle(TextBoxWindowName.Text)
If (hWnd = 0) Then
MessageBox.Show("Control Window Was Not Found", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
End If
' Get all the Control Handles for the Forms Child
Dim rtnChildWindows As IntPtr() = WindowControlHandleInfo.GetChildWindows(hWnd)
If rtnChildWindows.Length = 0 Then Return ' No Controls were Found
myControlInfo = New List(Of WindowControlInfo)
Dim zOrder As Integer = 0
' Loop Through Each Child Window and add it to the myControlInfo
For Each i As Integer In rtnChildWindows
' Get the Class Name
Dim strClassName As String = CStr(WindowControlHandleInfo.GetClassName(i))
' Get the Controls Caption
Dim ControlText As String = WindowControlHandleInfo.GetMesasgeFromControl(i)
myControlInfo.Add(New WindowControlInfo(strClassName, zOrder, i, ControlText))
zOrder += 1
Next
End Sub
Private Sub ButtonSendDateToDateTimePicker_Click(sender As Object, e As EventArgs) Handles ButtonSendDateToDateTimePicker.Click
WindowControlHandleInfo.SendMessageDateToControl(TextBoxHandelDateTimePicker.Text, "02/01/1991")
End Sub
I have also tried:
Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As String) As Int32
Public Const WM_SETTEXT As Int32 = &HC
Public Const WM_GETTEXT As Int32 = &HD
SendMessage(chwnd, WM_SETTEXT, 0, "02/01/1991")
Neither is changing the value of the DateTimePicker.
Public Const WM_GETTEXT As Int32 = &HD SendMessage(chwnd, WM_SETTEXT, 0, "02/01/1991")
Assuming there is a typo in the above, WM_SETTEXT has the value x0C.
That is a typo. It should have been
Public Const WM_SETTEXT As Int32 = &HC
I have updated my original question
这篇关于如何使用sendmessage更新datetimepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!