Re: How to adjust Columns of Vsflexgrid8 control in VC++
"RAG" wrote:
You are the only source I gor to ask question and get
reply for flex
grid. I have not got how to convert the pixels to twips
and implement
it for the flexgrid column.I want to adjust all the column
width
according to the width of the window Do you have any code
sample to do
that or give me sequence of steps to do that.
Actually, I don't have any documentation for VsFlexFrid. I
just found VsFlexFrid v7.0 Light control installed on my
machine as a part of other product. Then I opened it with
OLE/COM Object Viewr utility in order to discover its
methods and properties. Then I tried to instantiate it with
ActiveX Control Test Container utility and called a couple
of its methods.
Certainly version 8.0 of VsFlexFrid control has more
features. You should read its documentation in order to use
it to the full extent. It can be that the solution I
provided below exists in version 8.0 already. Anyway, here's
the possible implementaion of WM_SIZE handler of VsFlexFrid
container window and some other functions:
CChildView - container window
m_wndGrid - CVSFlexGrid instance
CVSFlexGrid class is generated by MFC wizard
---------------------------------------------------------
int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
CRect rcClient;
GetClientRect(rcClient);
m_wndGrid.Create(NULL, WS_CHILD | WS_VISIBLE,
rcClient, this, 100);
// Enable smooth scrolling.
m_wndGrid.put_ScrollTrack(TRUE);
// Compensate inexact total column width.
m_wndGrid.put_ExtendLastCol(TRUE);
// Retrieve the current number of pixels per
// inch, which is resolution-dependent.
HDC hDC = ::GetDC(NULL);
m_nPixPerInchX = ::GetDeviceCaps(hDC, LOGPIXELSX);
m_nPixPerInchY = ::GetDeviceCaps(hDC, LOGPIXELSY);
::ReleaseDC(NULL, hDC);
return 0;
}
const int TWIPSPERINCH = 1440;
void CChildView::ConvertPixelsToTwips(
double& cx, double& cy)
{
cx = (cx / m_nPixPerInchX) * TWIPSPERINCH;
cy = (cy / m_nPixPerInchY) * TWIPSPERINCH;
}
// Copy & Paste from VsFlexGrid type library
typedef enum {
flexScrollBarNone = 0,
flexScrollBarHorizontal = 1,
flexScrollBarVertical = 2,
flexScrollBarBoth = 3
} ScrollBarsSettings;
void CChildView::OnSize(UINT nType, int cx, int cy)
{
// Calculation are in double's in order to
// minimize rounding error.
double cxTwips = cx;
double cyTwips = cy;
long nScrollBars = m_wndGrid.get_ScrollBars();
if(nScrollBars & flexScrollBarVertical)
{
cxTwips -= ::GetSystemMetrics(SM_CXVSCROLL);
}
ConvertPixelsToTwips(cxTwips, cyTwips);
const long nColCount = m_wndGrid.get_Cols();
const long nColWidth = cxTwips / nColCount;
for(long i = 0; i < nColCount; ++i)
{
m_wndGrid.put_ColWidth(i, nColWidth);
}
m_wndGrid.put_ScrollBars(
nScrollBars & ~flexScrollBarHorizontal);
m_wndGrid.MoveWindow(0, 0, cx, cy,
/*bRepaint=*/FALSE);
}
---------------------------------------------------------
HTH
Alex