Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modify date in DateTimePicker via SendMessage

Status
Not open for further replies.

Sweetve13

MIS
May 25, 2006
5
0
0
US
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.


Code:
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 Integer
Public Declare Function SetSystemTime Lib "kernel32" Alias "SetSystemTime" (ByRef lpSystemTime As SYSTEMTIME) As Integer
Public Declare Function GetSystemTime Lib "kernel32" Alias "GetSystemTime" (ByRef lpSystemTime As SYSTEMTIME) As Integer
Public Const DTM_GETSYSTEMTIME = &H1001
Public Const DTM_SETSYSTEMTIME = &H1002
 
Public Structure SYSTEMTIME
Public wYear As Integer
Public wMonth As Integer
Public wDayOfWeek As Integer
Public wDay As Integer
Public wHour As Integer
Public wMinute As Integer
Public wSecond As Integer
Public wMilliseconds As Integer
End Structure
 
Dim hwnd, datehwndAs Integer
Dim ErrMessage As Integer
hwnd = FindWindow(vbNullString, "NameofApplication")
datehwnd = FindWindowEx(hwnd, 0, "DateTimePickerClassInfo", vbNullString)
Dim gettime As New SYSTEMTIME
SendMessage(datehwnd, DTM_GETSYSTEMTIME, 0, gettime)
Dim changetime As New SYSTEMTIME
changetime.wDay = 2
changetime.wMonth = 3
changetime.wYear = 2006
SendMessage(datehwnd, DTM_SETSYSTEMTIME, 0, changetime)




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top