MonthCalendar control in CF 2.0

  • Thread starter Thread starter Lonifasiko
  • Start date Start date
L

Lonifasiko

How dissapointing is to see that MonthCalendar control does not work as
expected!
Date_Changed event is fired even when the previous month/next month
arrows are pressed. I needed a Date_Selected event, not Date_Changed.

Besides, in my case, the event fires infinite times. If you code
Date_Changed event, just click next month arrow, and you'll see that
the event is fired continuously all the time. Incredible! Smells like a
terrible bug.

Well, in a previous month, they suggested me taking a look at this nice
and easy article at
http://blog.opennetcf.org/ayakhnin/PermaLink.aspx?guid=9a6a541c-9109-4748-b3e0-6f8d0ed2f95f

I need same functionality but oriented to MonthCalendar and
DateSelected event.
I've more or less coded what I need but my fix does not work all good
it should.

If you see the linked article, I would like to know what values do I
need to my particular case. The following values are related to
Combobox, but I need MonthCalendar control related values, values for
DateSelected event.
Where can I find them? These are the values used for Combobox:

private const int WM_COMMAND = 0x111;
private const int CBN_DROPDOWN = 7;

Can anybody point me in the right direction please?

Thanks very much.
 
Searched a bit more but I have no solutions at this time. I'll post my
code:

public class CustomMonthCalendar : OpenNETCF.Windows.Forms.NativeWindow
{
private const int WM_NOTIFY = 0x004E; // EXTRACTED FROM
WinUser.h

private const int MCN_SELECT = 7;

public event DateRangeEventHandler Date_Selected;

private MonthCalendar monthCalendar;

public CustomMonthCalendar(MonthCalendar monthCalendar, Control
parent)
{

this.monthCalendar = monthCalendar;

//Subclass parent form
this.AssignHandle(parent.Handle);
}

protected override void WndProc(ref Message m)
{
if (m.Msg == WM_NOTIFY)
{
// Make sure that's its MonthCalendar control
if (m.LParam == monthCalendar.Handle)
{
if (Date_Selected != null)
{
// Raise the event
Date_Selected(monthCalendar, new
DateRangeEventArgs(monthCalendar.SelectionStart,
monthCalendar.SelectionEnd));
}
}
}

base.WndProc(ref m);
}
}

I'm using this class from my form this way:

CustomMonthCalendar monthCalendar = new
CustomMonthCalendar(monthCalendar1, this);

monthCalendar.Date_Selected += new
DateRangeEventHandler(monthCalendar_Date_Selected);

The problem is that this condition is never true: m.LParam ==
monthCalendar.Handle
Any parameter in the Message is the same as monthCalendar.Handle, that
is the reason. Which should be the comparison then?

Another thing: Everytime I select a date, "WndProc" method is called
four or five times. Is this normal?

Why do I need the MCN_SELECT value (is not 7 but I can't find it) if I
don't use it in the code!

Any help will be greatly appreciated. Regards.

What am I doing wrong guys?
 
You need to become familiar with the header files from your SDK. All
constants, messages, etc. are defined there.

--
Chris Tacke
Co-founder
OpenNETCF.org
Are you using the SDF? Let's do a case study.
Email us at d c s @ o p e n n e t c f . c o m
http://www.opennetcf.org/donate
 
Thanks Chris, it's a pretty good idea, and be sure I'd love to
(really), but I have no time and my MonthCalendar control must be
working properly the earliest I can.

Reading MSDN documentation and thanks to Alex Yakhnin's response, I
finally discovered that
private const ulong MCN_SELECT = unchecked(0U - 750U) + 4; // MCN_FIRST
+ 4
but I still don't understand the use of this constant in the code
snippet of Alex. MSDN documentation about this header files is not very
clear. Can be that I'm completely fool? I'm not used to low-level
programing and these days I'm suffering a bit. I promise you I will
update my skill on this kind of programming.

At the moment I'm quite lost, therefore, I would appreciate any urgent
help on this.

If you want, you can also follow the conversation I've had with Alex at
http://blog.opennetcf.org/ayakhnin/PermaLink.aspx?guid=9a6a541c-9109-4748-b3e0-6f8d0ed2f95f

Thanks and regards.
Thanks and reagards.
 
Back
Top