//建立拖動image
cimagelist *cmylist::makedragimage(int item)
{
cimagelist *ilist = new cimagelist; // create a new image-list
crect rc;
getitemrect(item, &rc, lvir_bounds); // get the complete row
rc.offsetrect(-rc.left, -rc.top); // make it (0, 0)-aligned
rc.right = getcolumnwidth(0); // just want the 1st columne
ilist->create(rc.width(), rc.height(), ilc_color24 | ilc_mask, 1, 1);
cdc *pdc = getdc(); // get device-context
if(pdc) {
// create a memory-dc for the image and attach a bitmap to it
cdc drawdc;
drawdc.createcompatibledc(pdc);
cbitmap drawmap;
drawmap.createcompatiblebitmap(pdc, rc.width(), rc.height());
cbitmap *old = drawdc.selectobject(&drawmap);
// erase the background../di2001.jpgd draw the item into the device context
drawdc.fillsolidrect(rc, getsyscolor(color_window));
drawitemstruct dis;
dis.hdc = drawdc.m_hdc; // device-context to draw in
dis.rcitem = rc; // the item rectangle
dis.itemid = item; // the item's id
dis.itemstate = ods_default; // or ods_selected
drawitem(&dis); // draw item into the dc
drawdc.selectobject(old); // switch back to old bitmap
// create a memory-dc for the mask and attach a bitmap to it. to make
// the bitmap just one bit depth, we make it compatible to the memory-
// dc instead of the screen-dc as above
cdc maskdc;
maskdc.createcompatibledc(pdc);
cbitmap maskmap;
maskmap.createcompatiblebitmap(&maskdc, rc.width(), rc.height());
old = maskdc.selectobject(&maskmap);
// erase the background../di2001.jpgd draw the item into the device context
maskdc.fillsolidrect(rc, getsyscolor(color_window));
dis.hdc = maskdc.m_hdc; // device-context to draw in
dis.rcitem = rc; // the item rectangle
dis.itemid = item; // the item's id
dis.itemstate = ods_default; // or ods_selected
drawitem(&dis); // draw into the dc
maskdc.selectobject(old); // switch back to old bitmap
// add the image (and mask) to the image-list
ilist->add(&drawmap, &maskmap);
releasedc(pdc);
}
return ilist;
}