// Same a a click on the Date Time drop down button void IInvokeProvider.Invoke() { // Make sure that the control is enabled if (!SafeNativeMethods.IsWindowEnabled(_hwnd)) { throw new ElementNotEnabledException(); } IntPtr hwndCalendar; if (!WindowsDateTimePicker.IsCalendarPopupVisible(_hwnd, out hwndCalendar)) { Misc.PostMessage(_hwnd, NativeMethods.WM_KEYDOWN, (IntPtr)NativeMethods.VK_F4, IntPtr.Zero); Misc.PostMessage(_hwnd, NativeMethods.WM_KEYUP, (IntPtr)NativeMethods.VK_F4, IntPtr.Zero); // Wait for the window to come up; 10 tries for (int i = 0; i < 10 && !WindowsDateTimePicker.IsCalendarPopupVisible(_hwnd, out hwndCalendar); i++) { System.Threading.Thread.Sleep(0); } } else { // A post message must be used at the processing of the WM_KEYDOWN is achieve in a PeekMessageLoop Misc.PostMessage(hwndCalendar, NativeMethods.WM_KEYDOWN, (IntPtr)NativeMethods.VK_ESCAPE, new IntPtr(0x10001)); // Wait for the window to go away; 10 tries for (int i = 0; i < 10 && UnsafeNativeMethods.IsWindow(hwndCalendar); i++) { System.Threading.Thread.Sleep(0); } } }
// Static Create method called by the event tracker system internal static void RaiseEvents(IntPtr hwnd, int eventId, object idProp, int idObject, int idChild) { if (idObject != NativeMethods.OBJID_VSCROLL && idObject != NativeMethods.OBJID_HSCROLL) { WindowsDateTimePicker wdt = new WindowsDateTimePicker(hwnd, null, 0); if (eventId == NativeMethods.EventObjectNameChange) { if (idProp == ValuePattern.ValueProperty && idObject == NativeMethods.OBJID_WINDOW) { // The dispatch method expects EventObjectValueChange for the Value change property eventId = NativeMethods.EventObjectValueChange; idObject = NativeMethods.OBJID_CLIENT; } else { // The name of the control should never change return; } } wdt.DispatchEvents(eventId, idProp, idObject, idChild); } }