Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


Modify date in DateTimePicker via SendMessage


Modify date in DateTimePicker via SendMessage

Author
Message
Sweetve13
Sweetve13
Forum God
Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)

Group: Forum Members
Posts: 3, Visits: 8

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)


GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search