CDateTimeCtrl::SetMonthCalFont

void SetMonthCalFont(HFONT hFont, BOOL bRedraw = TRUE);

参数:
hFont要设置的字体的句柄。
bRedraw指定控件是否立即在设置字体时重新绘制。这个参数设置为TRUE引起控件重画自身。

说明:
与联机文档“平台SDK”中描述的一样,这个成员函数实现Win32消息DTM_SETMCFONT的功能。

示例:
// The following code example creates a font
// (Arial, 10 pixels high) and if successful,
// stores the result in m_pMonthFont. SetMonthCalFont
// is then called passing in the new font, causing
// the month calendar control to display all
// text and dates with an Arial font.

BOOL CYourDialog::OnInitDialog()
{
   CDialog::OnInitDialog();

   // ... other code here ...

   //initializing the necessary members of the LOGFONT
   // structure

   m_pMonthFont = new CFont;
   LOGFONT lf;
   memset(&lf, 0, sizeof(lf));
   lf.lfHeight = 10;
   strcpy(lf.lfFaceName, "Arial");

   if (m_pMonthFont->CreateFontIndirect(&lf))
   {
      // if successful, grab the month calendar control from
      // our dialog and set the font

      CMonthCalCtrl* pCtrl = (CMonthCalCtrl*) GetDlgItem(IDC_DATETIME1);
      ASSERT(pCtrl != NULL);
      pCtrl->SetMonthCalFont(m_pMonthFont);
   }
   else
   {
      // if not successful, clean up the font pointer and
      // set equal to NULL

      delete m_pMonthFont;
      m_pMonthFont = NULL;
   }

   // ... other code here ...
}

CYourDialog::CYourDialog(CWnd* pParent /*=NULL*/) : CDialog(CYourDialog::IDD, pParent)
{
   // ... other code here ...
   m_pMonthFont = NULL;
   // ... other code here ...
}

CYourDialog::~CYourDialog()
{
   // ... other code here ...
   delete m_pMonthFont;
   // ... other code here ...
}

注意:
如果使用这段代码,可以产生CFont类型的m_pMonthFont,是一个CDialog派生类的成员。

请参阅:CDateTimeCtrl::GetMonthCalFont