Objective Grid: Resizing the client area of a grid to fit the width and height of the grid

Article ID: 497
Last updated: 16 Apr, 2018
Article ID: 497
Last updated: 16 Apr, 2018
Revision: 3
Views: 2243
Posted: 12 Jan, 2001
by Meltreger B.
Updated: 16 Apr, 2018
by Meltreger B.

Problem


How do I resize the client area of a grid view to fit the width or height of the grid?


Cause



Action


The following function will calculate the grid's width and height and resize the parent frame accordingly. You can call this function from your OnInitialUpdate() routine.

void C1stGridView::FitToSize()
{
UpdateFontMetrics();
CFrameWnd* pFrame = GetParentFrame();
CMDIChildWnd* pMDIChild = NULL;
CWnd* pMDIClient = NULL;
CRect oClientRect;

if (pFrame && pFrame->IsKindOf(RUNTIME_CLASS(CMDIChildWnd)))
{

pMDIChild = (CMDIChildWnd*) pFrame;
pMDIClient = pFrame->GetParent();
pMDIChild->MDIRestore();
pMDIClient->GetClientRect(&oClientRect);


int colTotalWidth = CalcSumOfColWidths(0,GetColCount(), oClientRect.Width());

int colTotalHeight = CalcSumOfRowHeights(0,GetRowCount(), oClientRect.Height());

// Check if the calculated value
// is more than the default
// client area of the grid.
if (colTotalHeight >= oClientRect.Height())

colTotalWidth += ::GetSystemMetrics(SM_CXVSCROLL);
colTotalWidth += 7*(::GetSystemMetrics(SM_CXEDGE));

if (colTotalWidth >= oClientRect.Width())

colTotalHeight += ::GetSystemMetrics( SM_CYHSCROLL);
colTotalHeight += 7*(::GetSystemMetrics(SM_CYEDGE));

// Add the window title bar to the height
colTotalHeight+=::GetSystemMetrics(SM_CYCAPTION);
colTotalHeight = min(colTotalHeight, oClientRect.Height());
colTotalWidth = min(colTotalWidth, oClientRect.Width());

pFrame->SetWindowPos(NULL, 0, 0, colTotalWidth,colTotalHeight, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER);

}
}

This article was:   Helpful | Not helpful
Report an issue
Article ID: 497
Last updated: 16 Apr, 2018
Revision: 3
Views: 2243
Posted: 12 Jan, 2001 by Meltreger B.
Updated: 16 Apr, 2018 by Meltreger B.

Others in this category