-
January 10th, 2002, 10:41 AM
#1
CMonthCalCtrl
Is there a way to disable the left click date selection in the CMonthCalCtrl? I want to display a one month calendar but do not need to be able to select days.
Thanks in advance,
Hal
up·grade (up'gräd'),
to take out old bugs
and put in new ones.
-
January 10th, 2002, 10:54 AM
#2
Re: CMonthCalCtrl
Hi,
Create your own MonthCal class derived from CMonthCalCtrl and handle the WM_LBUTTONDOWN/UP message. See this// header
class CMyMonthCal : public CMonthCalCtrl
{
// Construction
public:
CMyMonthCal();
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyMonthCal)
protected:
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CMyMonthCal();
// Generated message map functions
protected:
//{{AFX_MSG(CMyMonthCal)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
// cpp file
#include "MyMonthCal.h"
CMyMonthCal::CMyMonthCal()
{
}
CMyMonthCal::~CMyMonthCal()
{
}
BEGIN_MESSAGE_MAP(CMyMonthCal, CMonthCalCtrl)
//{{AFX_MSG_MAP(CMyMonthCal)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyMonthCal message handlers
LRESULT CMyMonthCal::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if ((message == WM_LBUTTONDOWN) || (message == WM_LBUTTONUP))
return 1;
return CMonthCalCtrl::WindowProc(message, wParam, lParam);
}
Now put a MonthCal resource on your dialog (for example) and add a member variable of Control type. Instead using the default CMonthCalCtrl class put CMyMonthCal. Then left button message are disabled.
Regards,
Emi
Regards,
Emanuel Vaduva
-
January 10th, 2002, 03:30 PM
#3
Re: CMonthCalCtrl
Thanks for the reply. It does disable the day selection as I want, but I can no longer select another month. Can the WPARAM or LPARAM be used to determine if the click was in the calendar or in the title bar?
Regards,
Hal
up·grade (up'gräd'),
to take out old bugs
and put in new ones.
-
January 10th, 2002, 03:41 PM
#4
Re: CMonthCalCtrl
Sure. See this sampleLRESULT CMyMonthCal::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if ((message == WM_LBUTTONDOWN) || (message == WM_LBUTTONUP))
{
int xPos = LOWORD(lParam);
int yPos = HIWORD(lParam);
TRACE("xPos = %d, yPos = %d\n", xPos, yPos);
if (yPos > 25)
return 1;
}
return CMonthCalCtrl::WindowProc(message, wParam, lParam);
}
But you have to know the size of title bar.
Regards,
Emi
Regards,
Emanuel Vaduva
-
January 10th, 2002, 03:43 PM
#5
Re: CMonthCalCtrl
if (yPos > GetSystemMetrics(SM_CYSIZE))
return 1;
// change to this
Regards,
Emi
Regards,
Emanuel Vaduva
-
January 10th, 2002, 04:49 PM
#6
Re: CMonthCalCtrl
up·grade (up'gräd'),
to take out old bugs
and put in new ones.
-
January 10th, 2002, 04:54 PM
#7
Re: CMonthCalCtrl
You're welcome.
Regards,
Emi
Regards,
Emanuel Vaduva
-
January 11th, 2002, 11:09 AM
#8
Re: CMonthCalCtrl
Two more questions if you don't mind. Now that we have disabled the date selection I would like to know if there is a way to get the control to not display the current date highlighted (not the today circle but the blue oval around the current day). When I change months the same day is highlighed on the new month.
The second question is how can I intercept key presses so I can make the HOME and CTRL-HOME keys return the calendar to the current month. I added a check for the WM_KEYDOWN message in the WindowProc but that did not work.
Thanks again for the help with the previous problem,
Hal
up·grade (up'gräd'),
to take out old bugs
and put in new ones.
-
January 11th, 2002, 01:36 PM
#9
Re: CMonthCalCtrl
Hi,
For 'not the today circle but the blue oval around the current day' turn off the No Today Circle property from resource or usebRet = m_MyMonthCal.ModifyStyle(0, MCS_NOTODAYCIRCLE);
TRACE("bRet = %d\n", bRet);
Regards,
Emi
Regards,
Emanuel Vaduva
-
January 11th, 2002, 02:08 PM
#10
Re: CMonthCalCtrl
Now regarding catching the WM_KEYDOWN message all you have to do is to set the focus on your month calendarm_MyMonthCal.SetFocus();
//
LRESULT CMyMonthCal::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_KEYDOWN)
TRACE("WM_KEYDOWN in CMyMonthCal::WindowProc\n");
return CMonthCalCtrl::WindowProc(message, wParam, lParam);
}
Regards,
Emi
Regards,
Emanuel Vaduva
-
January 11th, 2002, 03:47 PM
#11
Re: CMonthCalCtrl
I added the SetFocus() to the OnInitDialog function of the dialog that owns the calendar and added the test for WM_KEYDOWN in the calendar's WindowProc and set a breakpoint on the if statement but it never gets control. Here's the function:
LRESULT CCalendar::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if ((message == WM_LBUTTONDOWN) || (message == WM_LBUTTONUP))
{
int xPos = LOWORD(lParam);
int yPos = HIWORD(lParam);
TRACE("xPos = %d, yPos = %d\n", xPos, yPos);
if (yPos > GetSystemMetrics(SM_CYSIZE))
return 1;
}
if (message == WM_KEYDOWN)
TRACE("WM_KEYDOWN in CCalendar:::WindowProc\n");
return CMonthCalCtrl::WindowProc(message, wParam, lParam);
I also clicked in the calendar to make sure it had the focus.
-----
Regarding the blue oval around the current date, I guess my explanation of what I want to do was confussing. I was afraid that you might think I was referring to the red today circle. What I am trying to do is to remove the blue oval that initially highlights the current day and moves when a new date is selected (not the red today circle). Being that I have disabled the ability to select dates, I thought it would be nice if I could get rid of the highlight.
Sorry for the confusion. Regards,
Hal
up·grade (up'gräd'),
to take out old bugs
and put in new ones.
-
January 11th, 2002, 05:45 PM
#12
Re: CMonthCalCtrl
That's strange. If you want I'll send you a zip files with a small example.
Regards,
Emi
Regards,
Emanuel Vaduva
-
January 12th, 2002, 11:01 PM
#13
Re: CMonthCalCtrl
Please send me a sample. My email address is hal@haldeemar.com
Thanks again,
Hal
up·grade (up'gräd'),
to take out old bugs
and put in new ones.
-
February 25th, 2013, 01:36 AM
#14
Re: CMonthCalCtrl
Hi I am Uday,
I need information on cmonth calender control.
can i have any coding for removing default selected date on that control...????
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|