HexEdit/GridCtrl_src/GridCtrl.cpp
CImageList* CGridCtrl::CreateDragImage(CPoint *pHotSpot)
{
    CDC* pDC = GetDC();
    if (!pDC)
        return NULL;

    CRect rect;
    CCellID cell = GetFocusCell();
    if (!GetCellRect(cell.row, cell.col, rect))
        return NULL;

    // Translate coordinate system
    rect.BottomRight() = CPoint(rect.Width(), rect.Height());
    rect.TopLeft()     = CPoint(0, 0);
    *pHotSpot = rect.BottomRight(); 

    // Create a new imagelist (the caller of this function has responsibility
    // for deleting this list)
    CImageList* pList = new CImageList;
    if (!pList || !pList->Create(rect.Width(), rect.Height(), ILC_MASK, 1, 1))
    {
        if (pList)
            delete pList;
        return NULL;
    }

    // Create mem DC and bitmap
    CDC MemDC;
    CBitmap bm;
    MemDC.CreateCompatibleDC(pDC);
    bm.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
    CBitmap* pOldBitmap = MemDC.SelectObject(&bm);
    MemDC.SetWindowOrg(0, 0);

    // Draw cell onto bitmap in memDC
    CGridCellBase* pCell = GetCell(cell.row, cell.col);
    if (pCell)
        pCell->Draw(&MemDC, cell.row, cell.col, rect, FALSE);

    // Clean up
    MemDC.SelectObject(pOldBitmap);
    ReleaseDC(pDC);

    // Add the bitmap we just drew to the image list.
    pList->Add(&bm, GetDefaultCell(FALSE, FALSE)->GetBackClr());
    bm.DeleteObject();

    return pList;
}
// This is no longer needed since I've changed to OLE drag and drop - but it's
// still cool code. :)

This is no longer needed since I've changed to OLE drag and drop - but it's
still cool code.
This is no longer needed since I ' ve changed to OLE drag and drop - but it ' s still cool code .
CImageList* CGridCtrl::CreateDragImage(CPoint *pHotSpot)
{
    CDC* pDC = GetDC();
    if (!pDC)
        return NULL;
    CRect rect;
    CCellID cell = GetFocusCell();
    if (!GetCellRect(cell.row, cell.col, rect))
        return NULL;
    rect.BottomRight() = CPoint(rect.Width(), rect.Height());
    rect.TopLeft()     = CPoint(0, 0);
    *pHotSpot = rect.BottomRight(); 
    CImageList* pList = new CImageList;
    if (!pList || !pList->Create(rect.Width(), rect.Height(), ILC_MASK, 1, 1))
    {
        if (pList)
            delete pList;
        return NULL;
    }
    CDC MemDC;
    CBitmap bm;
    MemDC.CreateCompatibleDC(pDC);
    bm.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
    CBitmap* pOldBitmap = MemDC.SelectObject(&bm);
    MemDC.SetWindowOrg(0, 0);
    CGridCellBase* pCell = GetCell(cell.row, cell.col);
    if (pCell)
        pCell->Draw(&MemDC, cell.row, cell.col, rect, FALSE);
    MemDC.SelectObject(pOldBitmap);
    ReleaseDC(pDC);
    pList->Add(&bm, GetDefaultCell(FALSE, FALSE)->GetBackClr());
    bm.DeleteObject();
    return pList;
}
CImageList * CGridCtrl :: CreateDragImage ( CPoint * pHotSpot ) { CDC * pDC = GetDC ( ) ; if ( ! pDC ) return NULL ; CRect rect ; CCellID cell = GetFocusCell ( ) ; if ( ! GetCellRect ( cell . row , cell . col , rect ) ) return NULL ; rect . BottomRight ( ) = CPoint ( rect . Width ( ) , rect . Height ( ) ) ; rect . TopLeft ( ) = CPoint ( 0 , 0 ) ; * pHotSpot = rect . BottomRight ( ) ; CImageList * pList = new CImageList ; if ( ! pList || ! pList -> Create ( rect . Width ( ) , rect . Height ( ) , ILC_MASK , 1 , 1 ) ) { if ( pList ) delete pList ; return NULL ; } CDC MemDC ; CBitmap bm ; MemDC . CreateCompatibleDC ( pDC ) ; bm . CreateCompatibleBitmap ( pDC , rect . Width ( ) , rect . Height ( ) ) ; CBitmap * pOldBitmap = MemDC . SelectObject ( & bm ) ; MemDC . SetWindowOrg ( 0 , 0 ) ; CGridCellBase * pCell = GetCell ( cell . row , cell . col ) ; if ( pCell ) pCell -> Draw ( & MemDC , cell . row , cell . col , rect , FALSE ) ; MemDC . SelectObject ( pOldBitmap ) ; ReleaseDC ( pDC ) ; pList -> Add ( & bm , GetDefaultCell ( FALSE , FALSE ) -> GetBackClr ( ) ) ; bm . DeleteObject ( ) ; return pList ; }
This is no longer needed since I've changed to OLE drag and drop - but it's
still cool code.
This is no longer needed since I ' ve changed to OLE drag and drop - but it ' s still cool code .
// Translate coordinate system
 // Create a new imagelist (the caller of this function has responsibility
 // for deleting this list)
 // Create mem DC and bitmap
 // Draw cell onto bitmap in memDC
 // Clean up
 // Add the bitmap we just drew to the image list.
