tags:

views:

47

answers:

2

There's a great code sample in this post:

http://stackoverflow.com/questions/2399954/datetimepicker-automatically-move-to-next-datepart

which shows how to clean up some of the behavior of the DateTimePicker in .NET. Unfortunately the code won't compile, since .NET can't understand the WM_KEYDOWN type stuff. I was able to google and get values for a lot of the constants, like

WM_KEYUP = 0x0101;

But I'm really stuck getting NMHDR and WM_REFLECT to work. Is there some sort of Win32 assembly I need to add to my project to get all of this to work?

Thanks!

+3  A: 

You need to use what is known as P/Invoke.

[...] As an increasing developer base moves its production applications to managed code, it seems only natural that there will be even more occasions for developers to dip down into the underlying operating system for some critical tidbit of functionality—at least for the time being. Thankfully, the interop features of the common language run-time (CLR), called Platform Invoke (P/Invoke), are very complete [...].

http://www.pinvoke.net/default.aspx/Constants/WM.html

private const UInt32 WM_KEYDOWN        = 0x0100;

http://www.pinvoke.net/default.aspx/Structures/NMHDR.html

[StructLayout(LayoutKind.Sequential)] 
struct NMHDR 
{
   public IntPtr hwndFrom;
   public IntPtr idFrom;
   public int code;
}
smink
Great response, thanks!
Adam
Glad to help...
smink
+2  A: 

Visit pinvoke.net for these declarations. Or use the PInvoke Interop Assistant.

Hans Passant