CImageList::add() and CDC
George Voronoff -- george@island.com Wednesday, June 26, 1996 --=====================_835841907==_ Content-Type: text/plain; charset="us-ascii" --=====================_835841907==_ Content-Type: text/plain; charset="us-ascii" Content-Disposition: attachment; filename="imagelist" ENVIRONMENT: VC++ 4.0 NT 3.51 I am creating CImageList from an array of CBitmaps. I would like to use the top left corner of each bitmap as the mask color. What I wanted to do was: CImageList* init(CBitmap bmp[], UINT n, UINT cx, UINT cy) { CIwnImageList* il = new CImageList; il->Create(cx, cy, TRUE, n, FALSE); CDC dc; dc.CreateCompatibleDC(NULL); CBitmap *obmp = dc.GetCurrentBitmap(); for ( UINT i = 0; i < n; i++ ) { COLORREF c; dc.SelectObject(&bmp[i]); c = dc.GetPixel(0,0); il->Add(&bmp[i], c); } dc.SelectObject(obmp); return il; } But this did not work at all. The resulting bitmaps were all black. Then I tried: CImageList* init(CBitmap bmp[], UINT n, UINT cx, UINT cy) { CIwnImageList* il = new CImageList; il->Create(cx, cy, TRUE, n, FALSE); CDC dc; dc.CreateCompatibleDC(NULL); CBitmap *obmp = dc.GetCurrentBitmap(); for ( UINT i = 0; i < n; i++ ) { COLORREF c; dc.SelectObject(&bmp[i]); c = dc.GetPixel(0,0); dc.SelectObject(obmp); il->Add(&bmp[i], c); } return il; } This worked. The only diffrence between the to functions is that i select the original bitmap (obmp) before I add the current CBitmap to the CImageList. Based on this, I'm assuming that a CBitmap can not be added to a CImageList while the CBitmap is selected on a DC. Is this correct? If so, where on MSDN could I have found this info. Thanx. --=====================_835841907==_--
Vilas Patil -- vilasp@rpsadf.atlantaga.ncr.com Tuesday, July 02, 1996 Hi George: You got it right secondtime... You can not allow a bitmap to be selected in two DCs at a time... Therefore, when you try to add image to list which is already selected into dc the Cimagelist::add() simply adds image info ie height width but no image.. So you see black one . Bye.. ---------- From: owner-mfc-l To: mfc-l Cc: george Subject: CImageList::add() and CDC Date: Wednesday, June 26, 1996 12:18PM --=====================_835841907==_ Content-Type: text/plain; charset="us-ascii" --=====================_835841907==_ Content-Type: text/plain; charset="us-ascii" Content-Disposition: attachment; filename="imagelist" ENVIRONMENT: VC++ 4.0 NT 3.51 I am creating CImageList from an array of CBitmaps. I would like to use the top left corner of each bitmap as the mask color. What I wanted to do was: CImageList* init(CBitmap bmp[], UINT n, UINT cx, UINT cy) { CIwnImageList* il = new CImageList; il->Create(cx, cy, TRUE, n, FALSE); CDC dc; dc.CreateCompatibleDC(NULL); CBitmap *obmp = dc.GetCurrentBitmap(); for ( UINT i = 0; i < n; i++ ) { COLORREF c; dc.SelectObject(&bmp[i]); c = dc.GetPixel(0,0); il->Add(&bmp[i], c); } dc.SelectObject(obmp); return il; } But this did not work at all. The resulting bitmaps were all black. Then I tried: CImageList* init(CBitmap bmp[], UINT n, UINT cx, UINT cy) { CIwnImageList* il = new CImageList; il->Create(cx, cy, TRUE, n, FALSE); CDC dc; dc.CreateCompatibleDC(NULL); CBitmap *obmp = dc.GetCurrentBitmap(); for ( UINT i = 0; i < n; i++ ) { COLORREF c; dc.SelectObject(&bmp[i]); c = dc.GetPixel(0,0); dc.SelectObject(obmp); il->Add(&bmp[i], c); } return il; } This worked. The only diffrence between the to functions is that i select the original bitmap (obmp) before I add the current CBitmap to the CImageList. Based on this, I'm assuming that a CBitmap can not be added to a CImageList while the CBitmap is selected on a DC. Is this correct? If so, where on MSDN could I have found this info. Thanx. --=====================_835841907==_--
| Вернуться в корень Архива |