15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Header resize notification

Alexander Stigsen -- ccc4864@vip.cybercity.dk
Friday, May 03, 1996

Win95 / VC++ 4.0

How do I recieve notification when the Headers of a CListCtrl is resized?
I need this becourse I have an CListCtrl in Report mode with two columns. And
I would like for these two columns to fill the entire control no matter how
it is resized. The resizing of the control is no problem as I get that takes my
OnSize care of. But when the user resizes one of the Headers I would like to be
able to resize the other accordingly.

Thanks for any help you can give...

Alexander Stigsen




Peter Moss -- pmoss@bbn.com
Thursday, May 09, 1996

>Win95 / VC++ 4.0

>How do I recieve notification when the Headers of a CListCtrl is resized?
>I need this becourse I have an CListCtrl in Report mode with two columns. And
>I would like for these two columns to fill the entire control no matter how
>it is resized. The resizing of the control is no problem as I get that takes 
my
>OnSize care of. But when the user resizes one of the Headers I would like to 
be
>able to resize the other accordingly.

>Thanks for any help you can give...

>Alexander Stigsen
 
I have been bothered by this as well.  I solved the problem by overriding 
OnEraseBkgndas seen 
in the following snippet.

The member variable m_cwidth[] is the array of column widths which I store.  
In OnEraseBkgnd, I test 
to see if the col widths have changed, if so, cflag becomes TRUE and I then 
adjust the width of the last col.

Hope this helps,
Pete Moss
pmoss@bbn.com


/**************************************************************************
*
*  Name: OnEraseBkgnd
*  Func: This is a kludge to assure that the Col widths do not grow or shrink
*   beyond the client rect width. It will adjust the col width of the last
*   col to exactly match the edge of the client rect.
*
***************************************************************************/
BOOL CDSIDListCtrl::OnEraseBkgnd(CDC* pDC) 
{
 int n,twidth;

 // TODO: Add your message handler code here and/or call default
// Test to see if the col posns have changed
 BOOL cflag = FALSE;
 int tcwidth = 0;    // Total computed col width
 
// Get client rect to recompute m_tcwidth (vert scroll bar may change total 
width) 
 CRect LCRect;
 GetClientRect(LCRect);
 int CRWidth = LCRect.Width();
 if (m_tcwidth != CRWidth) {  // Client window has changed: scroll bar 
added/removed
  m_tcwidth = CRWidth;
  cflag = TRUE;    // This will force an adjustment of the last col width
 }

 for (n = 0; n < NUM_COLUMNS; n++) {
  twidth = GetColumnWidth(n);
  if (twidth != m_cwidth[n]) {
   m_cwidth[n] = twidth;
   cflag = TRUE;
  }
  tcwidth += twidth;
 }
 
 if (cflag) {    // User has changed col widths
  if (tcwidth != m_tcwidth) {  // New total width does not fit so adjust 
LAST_COL
   m_cwidth[LAST_COL] -= (tcwidth - m_tcwidth);
   SetColumnWidth(LAST_COL, m_cwidth[LAST_COL]);
  }
 }

 return CListCtrl::OnEraseBkgnd(pDC);
}




| Вернуться в корень Архива |