I am wanting to get and change the display date in the datetimepicker control located in a 3rd party application that runs in the background and thus not in focus. I found that DTM_GetSystemTime and DTM_SetSystemTime can do this but I have been unable to get it to work. I get an error message stating: "A call to PInvoke function 'DateTimePicker!DateTimePicker.Form1::SendMessage' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature." I've noticed that changing the "Byval lParam As SYSTEMTIME" to "ByRef lParam As SYSTEMTIME" in the Sendmessage declare will remove this message BUT it still does not make any changes! Any suggestions? Thanks.
Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, Byval lParam As SYSTEMTIME) As Integer Declare Auto Function SendMessage Lib "user32.dll" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wparam As Integer, ByVal lparam As String) As IntegerPublic Declare Function SetSystemTime Lib "kernel32" Alias "SetSystemTime" (ByRef lpSystemTime As SYSTEMTIME) As IntegerPublic Declare Function GetSystemTime Lib "kernel32" Alias "GetSystemTime" (ByRef lpSystemTime As SYSTEMTIME) As IntegerPublic Const DTM_GETSYSTEMTIME = &H1001 Public Const DTM_SETSYSTEMTIME = &H1002 Public Structure SYSTEMTIME Public wYear As Integer Public wMonth As IntegerPublic wDayOfWeek As IntegerPublic wDay As IntegerPublic wHour As IntegerPublic wMinute As IntegerPublic wSecond As IntegerPublic wMilliseconds As IntegerEnd Structure Dim hwnd, datehwndAs IntegerDim ErrMessage As Integerhwnd = FindWindow(vbNullString, "NameofApplication")datehwnd = FindWindowEx(hwnd, 0, "DateTimePickerClassInfo", vbNullString)Dim gettime As New SYSTEMTIMESendMessage(datehwnd, DTM_GETSYSTEMTIME, 0, gettime) Dim changetime As New SYSTEMTIMEchangetime.wDay = 2 changetime.wMonth = 3 changetime.wYear = 2006 SendMessage(datehwnd, DTM_SETSYSTEMTIME, 0, changetime)
|