CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14

Thread: CMonthCalCtrl

  1. #1
    Join Date
    Feb 2001
    Location
    AZ
    Posts
    201

    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.

  2. #2
    Join Date
    May 2000
    Location
    Toronto, ON, Canada
    Posts
    3,573

    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

  3. #3
    Join Date
    Feb 2001
    Location
    AZ
    Posts
    201

    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.

  4. #4
    Join Date
    May 2000
    Location
    Toronto, ON, Canada
    Posts
    3,573

    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

  5. #5
    Join Date
    May 2000
    Location
    Toronto, ON, Canada
    Posts
    3,573

    Re: CMonthCalCtrl

    if (yPos > GetSystemMetrics(SM_CYSIZE))
    return 1;
    // change to this




    Regards,

    Emi
    Regards,

    Emanuel Vaduva

  6. #6
    Join Date
    Feb 2001
    Location
    AZ
    Posts
    201

    Re: CMonthCalCtrl

    Perfect.

    Thanks,
    Hal

    up·grade (up'gräd'),
    to take out old bugs
    and put in new ones.

  7. #7
    Join Date
    May 2000
    Location
    Toronto, ON, Canada
    Posts
    3,573

    Re: CMonthCalCtrl

    You're welcome.

    Regards,

    Emi
    Regards,

    Emanuel Vaduva

  8. #8
    Join Date
    Feb 2001
    Location
    AZ
    Posts
    201

    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.

  9. #9
    Join Date
    May 2000
    Location
    Toronto, ON, Canada
    Posts
    3,573

    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

  10. #10
    Join Date
    May 2000
    Location
    Toronto, ON, Canada
    Posts
    3,573

    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

  11. #11
    Join Date
    Feb 2001
    Location
    AZ
    Posts
    201

    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.

  12. #12
    Join Date
    May 2000
    Location
    Toronto, ON, Canada
    Posts
    3,573

    Re: CMonthCalCtrl

    That's strange. If you want I'll send you a zip files with a small example.

    Regards,

    Emi
    Regards,

    Emanuel Vaduva

  13. #13
    Join Date
    Feb 2001
    Location
    AZ
    Posts
    201

    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.

  14. #14
    Join Date
    Dec 2012
    Posts
    5

    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
  •  





Click Here to Expand Forum to Full Width

Featured