本文整理汇总了C++中CGridCtrl类的典型用法代码示例。如果您正苦于以下问题:C++ CGridCtrl类的具体用法?C++ CGridCtrl怎么用?C++ CGridCtrl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CGridCtrl类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ImageSize
// Hack for AutoSizeRowEx()...
CSize CGridCellMultiLine::GetCellExtentEx(int width, CDC*pDC)
{
CSize ImageSize(0,0);
int nImage = GetImage();
if (nImage >= 0)
{
CGridCtrl* pGrid = GetGrid();
ASSERT(pGrid);
if (pGrid->GetImageList())
{
IMAGEINFO Info;
if (pGrid->GetImageList()->GetImageInfo(nImage, &Info))
ImageSize = CSize(Info.rcImage.right-Info.rcImage.left+1,
Info.rcImage.bottom-Info.rcImage.top+1);
}
}
CSize size = GetTextExtentEx(width - ImageSize.cx, GetText(), pDC);
CSize retSize(size.cx + ImageSize.cx, max(size.cy, ImageSize.cy));
return retSize;
}
示例2: ASSERT
int CGridTreeCellBase::GetTreeIndent()
// returns: device units to indent within a cell for a tree at this level
{
ASSERT( m_pTreeColumn != NULL);
CGridCtrl* pGridCtrl = GetGrid();
ASSERT( pGridCtrl != NULL);
unsigned char ucLevel = GetLevel();
if( ucLevel == 0)
return 0;
if( !m_pTreeColumn->GetTreeLines() )
ucLevel--;
return (m_pTreeColumn->GetDefTreeIndent() * ucLevel) + (pGridCtrl->GetDefCellMargin() * 2);
}
示例3: GetGrid
int CGridBtnCellBase::RelPointInCtl( const CPoint& arPoint) // Relative point coords
// returns: Index of control that this point is within bounds of or -1 if no control matches
{
CGridCtrl* pGrid = GetGrid();
ASSERT( pGrid);
CRect RectCell;
if( pGrid->GetCellRect( m_iRow,
m_iCol,
&RectCell) )
{
ASSERT( MAX_NBR_CTLS_INCELL > GetDrawCtlNbrMax() ); // whoa!
CRect RectAry[ MAX_NBR_CTLS_INCELL];
if( CalcDrawCtlRects( RectAry, // returns: CRects with coordinates
// last entry has optional leftover rect
// available for text, etc.
MAX_NBR_CTLS_INCELL,// nbr of Rects in above array
RectCell) ) // cell rectangle to work with
{
const int iCtlNbr = GetDrawCtlNbr();
// make point absolute coord
CPoint pointAbs;
pointAbs.x = arPoint.x + RectCell.left;
pointAbs.y = arPoint.y + RectCell.top;
for( int i1=0; i1 < iCtlNbr; i1++)
{
if( pointAbs.x >= RectAry[i1].left
&& pointAbs.x <= RectAry[i1].right
&& pointAbs.y >= RectAry[i1].top
&& pointAbs.y <= RectAry[i1].bottom)
{
return i1; // found it
}
}
}
}
return -1;
}
示例4: RelPointInCtl
void CGridBtnCellCombo::OnClick( CPoint PointCellRelative)
{
// immediately edit if user clicked on scroll down button picture
int iCtlHit = RelPointInCtl( PointCellRelative); // Relative point coords
// returns: Index of control that this point is within bounds of or -1 if no control matches
BOOL bHitScrollDown = FALSE;
if( iCtlHit >= 0)
{
// if user clicked on scroll down button picture, then show
// the drop-down, too
UINT uiType = GetDrawCtlType( iCtlHit);
UINT uiState = GetDrawCtlState( iCtlHit);
bHitScrollDown = ( uiType == DFC_SCROLL)
&& uiState & DFCS_SCROLLDOWN;
}
if( bHitScrollDown)
{
// invoke the edit, now -- similar to CGridCtl::OnEditCell() logic
CGridCtrl* pGrid = GetGrid();
ASSERT( pGrid != NULL);
CRect rect;
if (!pGrid->GetCellRect( m_iRow, m_iCol, rect))
return;
SendMessageToParent(m_iRow, m_iCol, GVN_BEGINLABELEDIT);
Edit( m_iRow, m_iCol, rect, PointCellRelative, IDC_INPLACE_CONTROL, VK_LBUTTON);
return;
}
CGridBtnCell::OnClick( PointCellRelative);
}
示例5: GetGrid
// EFW - Various changes to make it draw cells better when using alternate
// color schemes. Also removed printing references as that's now done
// by PrintCell() and fixed the sort marker so that it doesn't draw out
// of bounds.
BOOL CGridCellBase::Draw(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBkgnd /*=TRUE*/)
{
// Note - all through this function we totally brutalise 'rect'. Do not
// depend on it's value being that which was passed in.
//Used for merge cells
//by Huang Wei
if( m_Hide && !IsMerged())
{
return TRUE;
}
CGridCtrl* pGrid = GetGrid();
ASSERT(pGrid);
if (!pGrid || !pDC)
return FALSE;
if( rect.Width() <= 0 || rect.Height() <= 0) // prevents imagelist item from drawing even
return FALSE; // though cell is hidden
//TRACE3("Drawing %scell %d, %d\n", IsFixed()? _T("Fixed ") : _T(""), nRow, nCol);
int nSavedDC = pDC->SaveDC();
pDC->SetBkMode(TRANSPARENT);
// Get the default cell implementation for this kind of cell. We use it if this cell
// has anything marked as "default"
CGridDefaultCell *pDefaultCell = (CGridDefaultCell*) GetDefaultCell();
if (!pDefaultCell)
return FALSE;
// Set up text and background colours
COLORREF TextClr, TextBkClr;
TextClr = (GetTextClr() == CLR_DEFAULT)? pDefaultCell->GetTextClr() : GetTextClr();
if (GetBackClr() == CLR_DEFAULT)
TextBkClr = pDefaultCell->GetBackClr();
else
{
bEraseBkgnd = TRUE;
TextBkClr = GetBackClr();
}
// Draw cell background and highlighting (if necessary)
if ( IsFocused() || IsDropHighlighted() )
{
// Always draw even in list mode so that we can tell where the
// cursor is at. Use the highlight colors though.
if(GetState() & GVIS_SELECTED)
{
TextBkClr = ::GetSysColor(COLOR_HIGHLIGHT);
TextClr = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
bEraseBkgnd = TRUE;
}
rect.right++; rect.bottom++; // FillRect doesn't draw RHS or bottom
if (bEraseBkgnd)
{
TRY
{
CBrush brush(TextBkClr);
pDC->FillRect(rect, &brush);
}
CATCH(CResourceException, e)
{
//e->ReportError();
}
END_CATCH
}
// Don't adjust frame rect if no grid lines so that the
// whole cell is enclosed.
if(pGrid->GetGridLines() != GVL_NONE)
{
rect.right--;
rect.bottom--;
}
if (pGrid->GetFrameFocusCell())
{
// Use same color as text to outline the cell so that it shows
// up if the background is black.
TRY
{
CBrush brush(TextClr);
pDC->FrameRect(rect, &brush);
}
CATCH(CResourceException, e)
{
//e->ReportError();
}
END_CATCH
}
pDC->SetTextColor(TextClr);
// Adjust rect after frame draw if no grid lines
//.........这里部分代码省略.........
示例6: GetDrawCtlNbrMax
/*****************************************************************************
Called during all the mouse events associated with clicking a control
embedded within a cell. Override to have more elaborate handling like
implementing radio button logic.
*****************************************************************************/
BOOL CGridBtnCellBase::ClickedCellCtl( UINT uMsg, // Command that invoked. e.g. WM_LBUTTONDOWN
int aiWhich) // zero-based index of image to draw
// returns: T=redraw occurred / F=no redraw
{
if( aiWhich < 0
|| aiWhich >= GetDrawCtlNbrMax() )
{
ASSERT( FALSE);
return FALSE;
}
UINT uiState = GetDrawCtlState( aiWhich);
if( uiState & DFCS_INACTIVE)
return FALSE; // button is inactive -- don't do anything
m_sLastCtlClicked = (short)aiWhich;
UINT iType = GetDrawCtlType( aiWhich);
switch( uMsg)
{
case WM_LBUTTONDOWN:
// appears pushed in
uiState |= DFCS_PUSHED;
SetDrawCtlState( aiWhich, uiState);
break;
case WM_LBUTTONUP:
case WM_LBUTTONDBLCLK:
// appears pushed out
uiState &= (~DFCS_PUSHED);
// auto check / uncheck controls, too
if( iType == DFC_BUTTON )
{
BOOL bIsMbrRadioGrp = GetDrawCtlIsMbrRadioGrp( aiWhich);
if( uiState & DFCS_BUTTONRADIO
|| bIsMbrRadioGrp )
{
// radio buttons or any button flagged as being part
// of a radio group will be made to look pressed down
// while pushing-up / unchecking all other members
// of the radio group
const int iCtlNbr = GetDrawCtlNbr();
UINT uiStateRadio;
for( int i1=0; i1 < iCtlNbr; i1++)
{
if( i1 != aiWhich)
{
uiStateRadio = GetDrawCtlState( i1);
bIsMbrRadioGrp = GetDrawCtlIsMbrRadioGrp( i1);
if( uiStateRadio & DFCS_BUTTONRADIO
|| bIsMbrRadioGrp )
{
uiStateRadio &= (~( DFCS_PUSHED | DFCS_CHECKED) );
// push out and uncheck
SetDrawCtlState( i1, uiStateRadio);
}
}
}
uiState |= DFCS_CHECKED; // check
if( !(uiState & DFCS_BUTTONRADIO) )
uiState |= DFCS_PUSHED; // press in if not real radio button
}
else if( !( uiState & ALL_BUT_BTN_CHK) )
{
// not a pushbutton -- it's a check box
// (can't check for DFCS_BUTTONCHECK directly since it is bit 0)
if( uiState & DFCS_CHECKED)
uiState &= (~DFCS_CHECKED); // uncheck
else
uiState |= DFCS_CHECKED; // check
}
}
SetDrawCtlState( aiWhich, uiState);
break;
default:
ASSERT( FALSE); // gotta handle new message
return FALSE;
}
CGridCtrl* pGrid = GetGrid();
ASSERT( pGrid);
pGrid->RedrawCell( m_iRow, m_iCol);
return TRUE;
}
示例7: GetGrid
// This hack allows you to determine the height that a cell should be in order to display
// stuff properly in the given width.
CSize CGridCellMultiLine::GetTextExtentEx(int width, LPCTSTR szText, CDC* pDC /*= NULL*/)
{
CGridCtrl* pGrid = GetGrid();
ASSERT(pGrid);
BOOL bReleaseDC = FALSE;
if (pDC == NULL)
{
pDC = pGrid->GetDC();
if (!pDC)
{
CGridDefaultCell* pDefCell = (CGridDefaultCell*) GetDefaultCell();
ASSERT(pDefCell);
return CSize(pDefCell->GetWidth(), pDefCell->GetHeight());
}
bReleaseDC = TRUE;
}
CFont *pOldFont = NULL,
*pFont = GetFontObject();
if (pFont)
pOldFont = pDC->SelectObject(pFont);
CSize size;
int nFormat = GetFormat();
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
int textWidth = width - (4*GetMargin ());
// corrects the bug if resizing column gives a text width smaller than (4*Getmargin())
if (textWidth <= 0)
{
textWidth = 1;
}
// If the cell is a multiline cell, then use the width of the cell
// to get the height
if ((nFormat & DT_WORDBREAK) && !(nFormat & DT_SINGLELINE))
{
CRect rect;
rect.SetRect(0, 0, textWidth, 0);
pDC->DrawText(szText, -1, rect, nFormat | DT_CALCRECT);
size.cx = rect.Width ();
size.cy = rect.Height ();
}
else
size = pDC->GetTextExtent(szText, _tcslen(szText));
size.cx += (tm.tmOverhang);
if (pOldFont)
pDC->SelectObject(pOldFont);
size += CSize(4*GetMargin(), 2*GetMargin());
// Kludge for vertical text
LOGFONT *pLF = GetFont();
if (pLF->lfEscapement == 900 || pLF->lfEscapement == -900)
{
int nTemp = size.cx;
size.cx = size.cy;
size.cy = nTemp;
size += CSize(0, 4*GetMargin());
}
if (bReleaseDC)
pGrid->ReleaseDC(pDC);
return size;
}
示例8: SetAverageItem
BOOL CSListView::SetAverageItem( CGridCtrl &grid, CStockContainer & container, BOOL bRedraw )
{
if( grid.GetColumnCount() <= 0 )
return FALSE;
container.Lock();
// Get LPARAM
CUIntArray anParams;
anParams.SetSize( 0, grid.GetColumnCount() );
for( int nCol=0; nCol < grid.GetColumnCount(); nCol ++ )
{
LPARAM lParam = grid.GetItemData( 0, nCol );
anParams.Add( lParam );
}
// Set Average
CStockInfo & infoAve = container.GetAverage( );
CStockInfo & infoWAve = container.GetWeightAverage( );
int iRowAve=0, iRowWAve=0;
if( grid.GetRowCount() >= 3
&& grid.GetItemData(grid.GetRowCount()-2,0) == (LPARAM)ID_STOCKCNTN_AVERAGE
&& grid.GetItemData(grid.GetRowCount()-1,0) == (LPARAM)ID_STOCKCNTN_WEIGHTAVERAGE )
{
// get item id
iRowAve = grid.GetRowCount()-2;
iRowWAve = grid.GetRowCount()-1;
}
else
{
// Insert item
iRowAve = grid.InsertRow( infoAve.GetStockName() );
grid.SetItemData( iRowAve, 0, (LPARAM)ID_STOCKCNTN_AVERAGE );
iRowWAve = grid.InsertRow( infoWAve.GetStockName() );
grid.SetItemData( iRowWAve, 0, (LPARAM)ID_STOCKCNTN_WEIGHTAVERAGE );
}
// Set Average
for( nCol=0; nCol<anParams.GetSize(); nCol++ )
{
grid.SetItemText( iRowAve, nCol, AfxGetVariantDispString(anParams[nCol], infoAve, NULL) );
grid.SetItemBkColour( iRowAve, nCol, AfxGetProfile().GetColor(CColorClass::clrSListBK) );
grid.SetItemFgColour( iRowAve, nCol, AfxGetVariantColor( anParams[nCol], infoAve ) );
}
// Set Weight Average
for( nCol=0; nCol<anParams.GetSize(); nCol++ )
{
grid.SetItemText( iRowWAve, nCol, AfxGetVariantDispString(anParams[nCol], infoWAve, NULL) );
grid.SetItemBkColour( iRowWAve, nCol, AfxGetProfile().GetColor(CColorClass::clrSListBK) );
grid.SetItemFgColour( iRowWAve, nCol, AfxGetVariantColor( anParams[nCol], infoWAve ) );
}
// Set Param which is
// SLH_MARKETVALUE, SLH_MARKETVALUEA, SLH_MARKETVALUEB and etc, and more than SLH_USERDEFINE_BEGIN
for( nCol=0; nCol < anParams.GetSize(); nCol ++ )
{
UINT lParam = anParams[nCol];
if( SLH_DIFF == lParam || SLH_DIFFPERCENT == lParam || SLH_SCOPE == lParam
|| SLH_DIFFPERCENT_MIN5 == lParam || SLH_PE == lParam
|| SLH_PMAININCOME == lParam || SLH_RATIO_PCASH == lParam
|| SLH_RATIO_CURRENCY == lParam || SLH_RATIO_CHANGEHAND == lParam
|| SLH_RATIO_VOLUME == lParam || SLH_RS == lParam
|| SLH_MARKETVALUE == lParam || SLH_MARKETVALUEA == lParam
|| SLH_MARKETVALUEB == lParam || lParam >= SLH_USERDEFINE_BEGIN )
{
double dc = 0., average = 0.;
double wsum = 0.0001, waverage = 0., w = 0.;
for( int iRow=1; iRow<grid.GetRowCount(); iRow++ )
{
if( iRow == iRowAve || iRow == iRowWAve )
continue;
int id = grid.GetItemData(iRow,0);
if( id < 0 || id > container.GetSize() )
continue;
CStockInfo & info = container.ElementAt(id);
w = info.m_fShare_count_total;
double dValue = 0.;
if( !AfxGetVariantValue( lParam, info, &dValue, &container ) )
continue;
average = (average * dc + dValue)/(dc+1);
waverage = (waverage * wsum + dValue * w)/(wsum+w);
dc += 1;
wsum += w;
}
CString strText;
if( SLH_MARKETVALUE == lParam || SLH_MARKETVALUEA == lParam || SLH_MARKETVALUEB == lParam )
{
strText.Format( "%u", (DWORD)average );
grid.SetItemText( iRowAve, nCol, strText );
grid.SetItemText( iRowWAve, nCol, "-" );
}
else
{
//.........这里部分代码省略.........