2008年12月 8日 (月)

ステータスバーのペインの幅調整

void AdjustStatusBarPane(CCmdUI *pCmdUI, LPCTSTR pText)
{
  CStatusBar* pBar = (CStatusBar*)pCmdUI->m_pOther;
  UINT nID, nStyle;
  int cxWidth;
  pBar->GetPaneInfo(pCmdUI->m_nIndex, nID, nStyle, cxWidth);
  CDC* pDC = pBar->GetDC();
  CFont *pOldFont = pDC->SelectObject(pBar->GetFont());
  CSize size = pDC->GetTextExtent(pText);
  pDC->SelectObject(pOldFont);
  pBar->ReleaseDC(pDC);
  pBar->SetPaneInfo(pCmdUI->m_nIndex, nID, nStyle, size.cx);
}

|

2005年11月 8日 (火)

CListBox の水平スクロールバーの調整

void AdjustListBox(CListBox* plb)
{
  CString str;
  CSize size;
  int dx = 0;
  CDC* pDC = plb->GetDC();
  CFont *pOldFont = pDC->SelectObject(plb->GetFont());
  int c = plb->GetCount();
  for (int i = 0; i < c; i++)
  {
    plb->GetText(i, str);
    size = pDC->GetTextExtent(str + _T(' '));
    if (size.cx > dx) dx = size.cx;
  }
  plb->SetHorizontalExtent(dx);
  pDC->SelectObject(pOldFont);
  plb->ReleaseDC(pDC);
}

|