HexEdit/GridCtrl_src/GridCtrl.cpp
void CGridCtrl::ExpandColumnsToFit(BOOL bExpandFixed /*=TRUE*/)
{
    if (bExpandFixed)
	{
		if (GetColumnCount() <= 0) return;
	} 
	else
	{
		if (GetColumnCount() <= GetFixedColumnCount()) return;
	}

    EnableScrollBars(SB_HORZ, FALSE);

    CRect rect;
    GetClientRect(rect);

    int nFirstColumn = (bExpandFixed)? 0 : GetFixedColumnCount();

    int nNumColumnsAffected = 0;
    for (int col = nFirstColumn; col < GetColumnCount(); col++)
    {
        if (m_arColWidths[col] > 0)
            nNumColumnsAffected++;
    }

    if (nNumColumnsAffected <= 0)
        return;

    long virtualWidth = GetVirtualWidth();
    int nDifference = rect.Width() -(int) virtualWidth;
    int nColumnAdjustment = nDifference / nNumColumnsAffected;

    for (int col = nFirstColumn; col < GetColumnCount(); col++)
    {
        if (m_arColWidths[col] > 0)
            m_arColWidths[col] += nColumnAdjustment;
    }

    if (nDifference > 0)
    {
        int leftOver = nDifference % nNumColumnsAffected;
        for (int nCount = 0, col = nFirstColumn; 
             (col < GetColumnCount()) && (nCount < leftOver); col++, nCount++)
        {
            if (m_arColWidths[col] > 0)
                m_arColWidths[col] += 1;
        }
    }
    else 
    {
        int leftOver = (-nDifference) % nNumColumnsAffected;
        for (int nCount = 0, col = nFirstColumn; 
             (col < GetColumnCount()) && (nCount < leftOver); col++, nCount++)
        {
            if (m_arColWidths[col] > 0)
                m_arColWidths[col] -= 1;
        }
    }

    Refresh();

    ResetScrollBars();
}
// Expands the columns to fit the screen space. If bExpandFixed is FALSE then fixed 
// columns will not be affected

Expands the columns to fit the screen space. If bExpandFixed is FALSE then fixed
columns will not be affected
Expands the columns to fit the screen space . If bExpandFixed is FALSE then fixed columns will not be affected
void CGridCtrl::ExpandColumnsToFit(BOOL bExpandFixed )
{
    if (bExpandFixed)
	{
		if (GetColumnCount() <= 0) return;
	} 
	else
	{
		if (GetColumnCount() <= GetFixedColumnCount()) return;
	}
    EnableScrollBars(SB_HORZ, FALSE);
    CRect rect;
    GetClientRect(rect);
    int nFirstColumn = (bExpandFixed)? 0 : GetFixedColumnCount();
    int nNumColumnsAffected = 0;
    for (int col = nFirstColumn; col < GetColumnCount(); col++)
    {
        if (m_arColWidths[col] > 0)
            nNumColumnsAffected++;
    }
    if (nNumColumnsAffected <= 0)
        return;
    long virtualWidth = GetVirtualWidth();
    int nDifference = rect.Width() -(int) virtualWidth;
    int nColumnAdjustment = nDifference / nNumColumnsAffected;
    for (int col = nFirstColumn; col < GetColumnCount(); col++)
    {
        if (m_arColWidths[col] > 0)
            m_arColWidths[col] += nColumnAdjustment;
    }
    if (nDifference > 0)
    {
        int leftOver = nDifference % nNumColumnsAffected;
        for (int nCount = 0, col = nFirstColumn; 
             (col < GetColumnCount()) && (nCount < leftOver); col++, nCount++)
        {
            if (m_arColWidths[col] > 0)
                m_arColWidths[col] += 1;
        }
    }
    else 
    {
        int leftOver = (-nDifference) % nNumColumnsAffected;
        for (int nCount = 0, col = nFirstColumn; 
             (col < GetColumnCount()) && (nCount < leftOver); col++, nCount++)
        {
            if (m_arColWidths[col] > 0)
                m_arColWidths[col] -= 1;
        }
    }
    Refresh();
    ResetScrollBars();
}
void CGridCtrl :: ExpandColumnsToFit ( BOOL bExpandFixed ) { if ( bExpandFixed ) { if ( GetColumnCount ( ) <= 0 ) return ; } else { if ( GetColumnCount ( ) <= GetFixedColumnCount ( ) ) return ; } EnableScrollBars ( SB_HORZ , FALSE ) ; CRect rect ; GetClientRect ( rect ) ; int nFirstColumn = ( bExpandFixed ) ? 0 : GetFixedColumnCount ( ) ; int nNumColumnsAffected = 0 ; for ( int col = nFirstColumn ; col < GetColumnCount ( ) ; col ++ ) { if ( m_arColWidths [ col ] > 0 ) nNumColumnsAffected ++ ; } if ( nNumColumnsAffected <= 0 ) return ; long virtualWidth = GetVirtualWidth ( ) ; int nDifference = rect . Width ( ) - ( int ) virtualWidth ; int nColumnAdjustment = nDifference / nNumColumnsAffected ; for ( int col = nFirstColumn ; col < GetColumnCount ( ) ; col ++ ) { if ( m_arColWidths [ col ] > 0 ) m_arColWidths [ col ] += nColumnAdjustment ; } if ( nDifference > 0 ) { int leftOver = nDifference % nNumColumnsAffected ; for ( int nCount = 0 , col = nFirstColumn ; ( col < GetColumnCount ( ) ) && ( nCount < leftOver ) ; col ++ , nCount ++ ) { if ( m_arColWidths [ col ] > 0 ) m_arColWidths [ col ] += 1 ; } } else { int leftOver = ( - nDifference ) % nNumColumnsAffected ; for ( int nCount = 0 , col = nFirstColumn ; ( col < GetColumnCount ( ) ) && ( nCount < leftOver ) ; col ++ , nCount ++ ) { if ( m_arColWidths [ col ] > 0 ) m_arColWidths [ col ] -= 1 ; } } Refresh ( ) ; ResetScrollBars ( ) ; }
Expands the columns to fit the screen space.
Expands the columns to fit the screen space .
/*=TRUE*/