Windows message queue

  • Thread starter Thread starter j.edwards
  • Start date Start date
J

j.edwards

I'm building a DateTimePicker in VB.NET that is a wrapper around
ComCtrls.dll and need to be able to receive win32 messages. In the compact
framework (WindowsCE namespace) there is a MessageWindow class - that's
perfect for what I want. However, I can't find an equivalent for "normal"
windows (full framework). Basically I'm doing exactly what has been done in
OpenNetCF (but in VB), however I want to add the ability to receive event
notifications such as DTN_CLOSEUP, DTN_DATETIMECHANGE etc and then trigger
events on the control.

To pre-empt the standard replies :) ... yes I know a DateTimePicker exists
in OpenNetCF and the full framework. But I want one in vb.net (which is
currently working except for handling messages), and I want it to do more
than the OpenNetCF one. And as I'm building it for CF, I want it to use the
exact same one on the full framework as well so I can develop on the PC.

Any help appreciated.
 
The date/time change notification is actually received by the shell, which
handles the daylight saving time transitions, via an event that it sets up
via CeRunAppAtEvent(). Specifically, it creates an event with the name
"DSTTimeChange" and calls CeRunAppAtEvent with the notification string set
to "\\\\.\\Notifications\\NamedEvents\\DSTTimeChange" and the event set to
NOTIFICATION_EVENT_TIME_CHANGE. This is just a wild guess, but I'm betting
that the desktop doesn't work this way. You may be able to build the same
interface, but I'm pretty sure that the code itself won't be portable.

Paul T.
 
Hi Paul, thanks for your reply. I think you are talking about something
different though.

I'm not trying to capture when the date/time changes in the system, but when
someone picks a different date/time in the DateTimePicker control. The
DateTimePicker in comctrls sends messages like the one I pasted below from
the msdn help. All I'm trying to do is capture that message and respond
accordingly.
DTN_DATETIMECHANGE
This notification message is sent by a date and time picker (DTP) control
whenever a change occurs. It is sent in the form of a WM_NOTIFY message.

DTN_DATETIMECHANGE
lpChange = (LPNMDATETIMECHANGE) lParam;Parameters
lpChange
Long pointer to an NMDATETIMECHANGE structure that contains information
about the change that took place in the control.
 
Here is some code for what I'm trying to do (this is within my
DateTimePicker class):

Dim _MsgWindow As New MsgWindow(Me)

Private Class MsgWindow
Inherits Microsoft.WindowsCE.Forms.MessageWindow

Private DTP As DateTimePicker

Public Sub New(ByVal c As DateTimePicker)
DTP = c
End Sub

Protected Overrides Sub WndProc(ByRef m As
Microsoft.WindowsCE.Forms.Message)
If IsNothing(DTP) Then Exit Sub

If m.Msg = WM_NOTIFY Then
Dim Notification As DTPNotification = m.LParam.ToInt32()
Select Case Notification
Case DTPNotification.DTN_DATETIMECHANGE
'fire the OnChange event
DTP.Change()
End Select
End If
End Sub
End Class
 
Ok, I've been doing some experimenting and have found out a few things:

Firstly, you need to assign a parent window to the MessageWindow object -
this must be so it knows what WndProc to attach to. So once I put in the
following it actually started receiving messages:

Win32Helper.SetParent(Me.Hwnd, c.DateTimePickerHWnd)

The strange thing is though the messages have a hWnd value matching the hWnd
of the MessageWindow object. i.e. it doesn't seem to be able to receive
messages from other windows (controls).

My DateTimePicker creates a new control using "CreateWindow" win32 api call.
The DateTimePicker control has it's own HWnd, and the "actual"
DateTimePicker created with CreateWindow has a separate HWnd. If I set the
MessageWindow parent to either of these I still don't get any messages from
them. Any ideas?
 
Have you read this article:-
http://msdn.microsoft.com/library/d...netcomp/html/HostingANativeWindowsControl.asp

Using P/Invoke the standard properties of the MessageWindow are altered so
it is a visible window. The native control is then created as a child of
this, and the MessageWindow therefore receives messages from the hosted
control. The mechanics of the process are abstracted out into the ControlEx
class so it is easy to build other controls from the same code. Using this
technique I re-wrote the DateTimePicker for the upcoming v1.3 release of the
SDF. In total there will be DateTimePicker, MonthCalendar, WebBrowser and
InkX controls all written using the ControlEx class, and if you have a
custom native control you'll be able to easily create additional controls by
inheriting from ControlEx.

Peter
 
Back
Top