Modify date in DateTimePicker via SendMessage

Sweetve13

Member
Joined
May 25, 2006
Messages
6
Programming Experience
Beginner
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 in advance!

VB.NET:
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Declare[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][SIZE=2] SendMessage [/SIZE][SIZE=2][COLOR=#0000ff]Lib[/COLOR][/SIZE][SIZE=2][COLOR=#800000]"user32.dll"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Alias[/COLOR][/SIZE][SIZE=2][COLOR=#800000]"SendMessageA"[/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] hwnd [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] wMsg [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] wParam [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]Byval [/COLOR][/SIZE][SIZE=2]lParam [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] SYSTEMTIME) [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Declare[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Auto[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][SIZE=2] SendMessage [/SIZE][SIZE=2][COLOR=#0000ff]Lib[/COLOR][/SIZE][SIZE=2][COLOR=#800000]"user32.dll"[/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] hwnd [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] wMsg [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] wparam [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] lparam [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Declare[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][SIZE=2] SetSystemTime [/SIZE][SIZE=2][COLOR=#0000ff]Lib[/COLOR][/SIZE][SIZE=2][COLOR=#800000]"kernel32"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Alias[/COLOR][/SIZE][SIZE=2][COLOR=#800000]"SetSystemTime"[/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff]ByRef[/COLOR][/SIZE][SIZE=2] lpSystemTime [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] SYSTEMTIME) [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Declare[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][SIZE=2] GetSystemTime [/SIZE][SIZE=2][COLOR=#0000ff]Lib[/COLOR][/SIZE][SIZE=2][COLOR=#800000]"kernel32"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Alias[/COLOR][/SIZE][SIZE=2][COLOR=#800000]"GetSystemTime"[/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff]ByRef[/COLOR][/SIZE][SIZE=2] lpSystemTime [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] SYSTEMTIME) [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Const[/COLOR][/SIZE][SIZE=2] DTM_GETSYSTEMTIME = &H1001
[/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Const[/COLOR][/SIZE][SIZE=2] DTM_SETSYSTEMTIME = &H1002[/SIZE]
 
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Structure[/COLOR][/SIZE][SIZE=2] SYSTEMTIME
[/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] wYear [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] wMonth [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] wDayOfWeek [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] wDay [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] wHour [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] wMinute [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] wSecond [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] wMilliseconds [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Structure[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2][COLOR=#000000] hwnd, datehwnd[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ErrMessage [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2]hwnd = FindWindow(vbNullString, [/SIZE][SIZE=2][COLOR=#800000]"NameofApplication"[/COLOR][/SIZE][SIZE=2])[/SIZE][SIZE=2]
datehwnd = FindWindowEx(hwnd, 0, [/SIZE][SIZE=2][COLOR=#800000]"DateTimePickerClassInfo"[/COLOR][/SIZE][SIZE=2], vbNullString)[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] gettime [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SYSTEMTIME
[/SIZE][SIZE=2]SendMessage(datehwnd, DTM_GETSYSTEMTIME, 0, gettime)
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] changetime [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SYSTEMTIME
changetime.wDay = 2
changetime.wMonth = 3
changetime.wYear = 2006
[/SIZE][/SIZE][SIZE=2]SendMessage(datehwnd, DTM_SETSYSTEMTIME, 0, changetime)[/SIZE][SIZE=2]
[/SIZE]

 
I made the suggested changes (SYSTEMTIME from Integer to Int16) as well as checked my declarations with the ApiViewer (That's for the tip!). I am still getting the " PInvokeStackImbalance was detected" error message. I noticed I could get/set the system timeclock in the taskbar but not the time in the datetimepicker after making the changes. So at least now I know the SYSTEMTIME declaration appears to be correct. Any suggestions? Thanks!

Here is the modified code:

VB.NET:
[COLOR=blue][FONT=Courier New]Imports[/FONT][/COLOR][COLOR=black][FONT=Courier New] System.Runtime.InteropServices[/FONT][/COLOR]
 
[COLOR=blue][FONT=Courier New]Declare [/FONT][/COLOR][COLOR=blue][FONT=Courier New]Function[/FONT][/COLOR][COLOR=black][FONT=Courier New] SendMessage [/FONT][/COLOR][COLOR=blue][FONT=Courier New]Lib[/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"user32.dll"[/FONT][/COLOR][COLOR=blue][FONT=Courier New]Alias[/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"SendMessageA"[/FONT][/COLOR][COLOR=black][FONT=Courier New] ([/FONT][/COLOR][COLOR=blue][FONT=Courier New]ByVal[/FONT][/COLOR][COLOR=black][FONT=Courier New] hwnd [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int32, [/FONT][/COLOR][COLOR=blue][FONT=Courier New]ByVal[/FONT][/COLOR][COLOR=black][FONT=Courier New] wMsg [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int32, [/FONT][/COLOR][COLOR=blue][FONT=Courier New]ByVal[/FONT][/COLOR][COLOR=black][FONT=Courier New] wParam [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int32, [/FONT][/COLOR][COLOR=blue][FONT=Courier New]ByVal[/FONT][/COLOR][COLOR=black][FONT=Courier New] lParam [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int32) [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int32[/FONT][/COLOR]
[COLOR=blue][FONT=Courier New]Declare [/FONT][/COLOR][COLOR=blue][FONT=Courier New]Function[/FONT][/COLOR][COLOR=black][FONT=Courier New] SendMessage [/FONT][/COLOR][COLOR=blue][FONT=Courier New]Lib[/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"user32.dll"[/FONT][/COLOR][COLOR=blue][FONT=Courier New]Alias[/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"SendMessageA"[/FONT][/COLOR][COLOR=black][FONT=Courier New] ([/FONT][/COLOR][COLOR=blue][FONT=Courier New]ByVal[/FONT][/COLOR][COLOR=black][FONT=Courier New] hwnd [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int32, [/FONT][/COLOR][COLOR=blue][FONT=Courier New]ByVal[/FONT][/COLOR][COLOR=black][FONT=Courier New] wMsg [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int32, [/FONT][/COLOR][COLOR=blue][FONT=Courier New]ByVal[/FONT][/COLOR][COLOR=black][FONT=Courier New] wParam [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int32, [/FONT][/COLOR][COLOR=blue][FONT=Courier New]ByVal[/FONT][/COLOR][COLOR=black][FONT=Courier New] lParam [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] SYSTEMTIME) [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int32[/FONT][/COLOR]
[COLOR=blue][FONT=Courier New]Declare [/FONT][/COLOR][COLOR=blue][FONT=Courier New]Function[/FONT][/COLOR][COLOR=black][FONT=Courier New] SetSystemTime [/FONT][/COLOR][COLOR=blue][FONT=Courier New]Lib[/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"kernel32.dll"[/FONT][/COLOR][COLOR=black][FONT=Courier New] ([/FONT][/COLOR][COLOR=blue][FONT=Courier New]ByRef[/FONT][/COLOR][COLOR=black][FONT=Courier New] lpSystemTime [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] SYSTEMTIME) [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int32[/FONT][/COLOR]
[COLOR=blue][FONT=Courier New]Declare [/FONT][/COLOR][COLOR=blue][FONT=Courier New]Sub[/FONT][/COLOR][COLOR=black][FONT=Courier New] GetSystemTime [/FONT][/COLOR][COLOR=blue][FONT=Courier New]Lib[/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"kernel32.dll"[/FONT][/COLOR][COLOR=black][FONT=Courier New] ([/FONT][/COLOR][COLOR=blue][FONT=Courier New]ByRef[/FONT][/COLOR][COLOR=black][FONT=Courier New] lpSystemTime [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] SYSTEMTIME)[/FONT][/COLOR]
[COLOR=blue][FONT=Courier New]Declare [/FONT][/COLOR][COLOR=blue][FONT=Courier New]Function[/FONT][/COLOR][COLOR=black][FONT=Courier New] FindWindow [/FONT][/COLOR][COLOR=blue][FONT=Courier New]Lib[/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"user32.dll"[/FONT][/COLOR][COLOR=blue][FONT=Courier New]Alias[/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"FindWindowA"[/FONT][/COLOR][COLOR=black][FONT=Courier New] ([/FONT][/COLOR][COLOR=blue][FONT=Courier New]ByVal[/FONT][/COLOR][COLOR=black][FONT=Courier New] lpClassName [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As [/FONT][/COLOR][COLOR=blue][FONT=Courier New]String[/FONT][/COLOR][COLOR=black][FONT=Courier New], [/FONT][/COLOR][COLOR=blue][FONT=Courier New]ByVal[/FONT][/COLOR][COLOR=black][FONT=Courier New] lpWindowName [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As [/FONT][/COLOR][COLOR=blue][FONT=Courier New]String[/FONT][/COLOR][COLOR=black][FONT=Courier New]) [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int32[/FONT][/COLOR]
[COLOR=blue][FONT=Courier New]Declare [/FONT][/COLOR][COLOR=blue][FONT=Courier New]Function[/FONT][/COLOR][COLOR=black][FONT=Courier New] FindWindowEx [/FONT][/COLOR][COLOR=blue][FONT=Courier New]Lib[/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"user32.dll"[/FONT][/COLOR][COLOR=blue][FONT=Courier New]Alias[/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"FindWindowExA"[/FONT][/COLOR][COLOR=black][FONT=Courier New] ([/FONT][/COLOR][COLOR=blue][FONT=Courier New]ByVal[/FONT][/COLOR][COLOR=black][FONT=Courier New] hWnd1 [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int32, [/FONT][/COLOR][COLOR=blue][FONT=Courier New]ByVal[/FONT][/COLOR][COLOR=black][FONT=Courier New] hWnd2 [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int32, [/FONT][/COLOR][COLOR=blue][FONT=Courier New]ByVal[/FONT][/COLOR][COLOR=black][FONT=Courier New] lpsz1 [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As [/FONT][/COLOR][COLOR=blue][FONT=Courier New]String[/FONT][/COLOR][COLOR=black][FONT=Courier New], [/FONT][/COLOR][COLOR=blue][FONT=Courier New]ByVal[/FONT][/COLOR][COLOR=black][FONT=Courier New] lpsz2 [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As [/FONT][/COLOR][COLOR=blue][FONT=Courier New]String[/FONT][/COLOR][COLOR=black][FONT=Courier New]) [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int32[/FONT][/COLOR]
 
[COLOR=blue][FONT=Courier New]Const[/FONT][/COLOR][COLOR=black][FONT=Courier New] DTM_FIRST [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int32 = &H1000[/FONT][/COLOR]
[COLOR=blue][FONT=Courier New]Const[/FONT][/COLOR][COLOR=black][FONT=Courier New] DTM_GETSYSTEMTIME [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int32 = (DTM_FIRST + 1)[/FONT][/COLOR]
[COLOR=blue][FONT=Courier New]Const[/FONT][/COLOR][COLOR=black][FONT=Courier New] DTM_SETSYSTEMTIME [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int32 = (DTM_FIRST + 2)[/FONT][/COLOR]
 
 
[COLOR=black][FONT=Courier New]<StructLayout(LayoutKind.Sequential)> [/FONT][/COLOR][COLOR=blue][FONT=Courier New]Structure[/FONT][/COLOR][COLOR=black][FONT=Courier New] SYSTEMTIME[/FONT][/COLOR]
[COLOR=blue][FONT=Courier New]Public[/FONT][/COLOR][COLOR=black][FONT=Courier New] wYear [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int16[/FONT][/COLOR]
[COLOR=blue][FONT=Courier New]Public[/FONT][/COLOR][COLOR=black][FONT=Courier New] wMonth [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int16[/FONT][/COLOR]
[COLOR=blue][FONT=Courier New]Public[/FONT][/COLOR][COLOR=black][FONT=Courier New] wDayOfWeek [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int16[/FONT][/COLOR]
[COLOR=blue][FONT=Courier New]Public[/FONT][/COLOR][COLOR=black][FONT=Courier New] wDay [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int16[/FONT][/COLOR]
[COLOR=blue][FONT=Courier New]Public[/FONT][/COLOR][COLOR=black][FONT=Courier New] wHour [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int16[/FONT][/COLOR]
[COLOR=blue][FONT=Courier New]Public[/FONT][/COLOR][COLOR=black][FONT=Courier New] wMinute [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int16[/FONT][/COLOR]
[COLOR=blue][FONT=Courier New]Public[/FONT][/COLOR][COLOR=black][FONT=Courier New] wSecond [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int16[/FONT][/COLOR]
[COLOR=blue][FONT=Courier New]Public[/FONT][/COLOR][COLOR=black][FONT=Courier New] wMilliseconds [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=black][FONT=Courier New] Int16[/FONT][/COLOR]
[COLOR=blue][FONT=Courier New]End [/FONT][/COLOR][COLOR=blue][FONT=Courier New]Structure[/FONT][/COLOR]
 
[COLOR=blue][FONT=Courier New]Dim[/FONT][/COLOR][COLOR=black][FONT=Courier New] hwnd, datehwnd [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As[/FONT][/COLOR][COLOR=blue][FONT=Courier New]Integer[/FONT][/COLOR]
[COLOR=blue][FONT=Courier New]Dim[/FONT][/COLOR][COLOR=black][FONT=Courier New] gettime [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As [/FONT][/COLOR][COLOR=blue][FONT=Courier New]New[/FONT][/COLOR][COLOR=black][FONT=Courier New] SYSTEMTIME[/FONT][/COLOR]
[COLOR=blue][FONT=Courier New]Dim[/FONT][/COLOR][COLOR=black][FONT=Courier New] changetime [/FONT][/COLOR][COLOR=blue][FONT=Courier New]As [/FONT][/COLOR][COLOR=blue][FONT=Courier New]New[/FONT][/COLOR][COLOR=black][FONT=Courier New] SYSTEMTIME[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]changetime.wDay = 13[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]changetime.wMonth = 5[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]changetime.wYear = 2004[/FONT][/COLOR]
 
[COLOR=black][FONT=Courier New]hwnd = FindWindow(vbNullString, [/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"NameOfApplication"[/FONT][/COLOR][COLOR=black][FONT=Courier New])[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]datehwnd = FindWindowEx(hwnd, 0, [/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"DateTimePickerClassInfo"[/FONT][/COLOR][COLOR=black][FONT=Courier New], vbNullString)[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]SendMessage(datehwnd, DTM_GETSYSTEMTIME, 0, gettime)[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]SendMessage(datehwnd, DTM_SETSYSTEMTIME, 0, changetime)[/FONT][/COLOR]
[COLOR=blue][FONT=Courier New]End [/FONT][/COLOR][COLOR=blue][FONT=Courier New]Sub[/FONT][/COLOR]
[COLOR=blue][FONT=Courier New]End [/FONT][/COLOR][COLOR=blue][FONT=Courier New]Class[/FONT][/COLOR]
 
Could it be that you haven't set all the values in the structure?

You may have already seen these but, here's a link to a site that may be of help..

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/datetime/messages/dtm_setsystemtime.asp

Also, for vb.net we should be using the p/invoke instead of those 'declare' things. So here's a link to a good site for migrating to p/invoke...

http://www.pinvoke.net/http://www.pinvoke.net/default.aspx/user32/FindWindow.html
 
Sweetve13, I changed the lparam of the Systemtime overload of SendMessage from ByVal to Byref, it stops complaining about the stack imbalance and works too. I tried the SendMessage DTM_Get.. by putting a DateTimePicker on my own form and passed its Handle.ToInt32 as hwnd, it reported correct values in the Systemtime structure. I don't think the code above will get you anywhere, though. When I do API GetClassName with my known hwnd it reports "WindowsForms10.SysDateTimePick32", but when I try to find the hwnd by its class name it only return 0.
You should at least try to inspect the window class with APIs GetClassName and WindowFromPoint, because DateTimePickerClassInfo looks like its unknown to the rest of the world.
 
Back
Top