Question : SetFont in CListBox

I want to set my CListBox font to "Courier New" 8 points. How to do that?

Answer : SetFont in CListBox

Call SetFont(). Example:

#include "stdafx.h"

class TestWindow : public CFrameWnd
{
  DECLARE_MESSAGE_MAP()
  afx_msg int OnCreate(LPCREATESTRUCT);
 
  CListBox m_listBox;
  CFont    m_listBoxFont;
};

afx_msg int TestWindow::OnCreate (LPCREATESTRUCT)
{
  DWORD dwStyle (WS_CHILD|WS_VISIBLE|WS_VSCROLL);
  CRect rect (10,10,200,75);
  m_listBox.Create (dwStyle, rect, this, 777);
  m_listBox.AddString ("Hello, World");
  m_listBox.AddString ("Beelzebubble");
  m_listBox.AddString ("Mork and Mindy");

  m_listBoxFont.CreatePointFont (150, "Courier New");
  m_listBox.SetFont (&m_listBoxFont);

  return 0;
}

BEGIN_MESSAGE_MAP(TestWindow, CFrameWnd)
    ON_WM_CREATE()
END_MESSAGE_MAP()

Cheers,
Eric

Random Solutions  
 
programming4us programming4us