Bring CBitmap to top windows
-
Hello, I have a CBitmap and load it. CBitmap mybmp; mybmp.Load(IDB_TEST); However, my listbox overlaps the CBitmap. How can i make CBitmap on top of other controls? Thanks a lot.
-
NewVCbie wrote: How can i make CBitmap on top of other controls? What are you doing after
mybmp.Load(IDB_TEST);
with your bitmap ? Can you post some code ? Which listbox are you talking about ? ~RaGE();actually i create a class CMyBitmap derived from CBitmap, void DrawTransparent (CDC* pDC, int x, int y, COLORREF clrTransparency); void Draw (CDC* pDC, int x, int y); The actual call is CMyBitmap bmpheader; bmpheader.LoadBitmap(IDB_LISTHHISTORY); bmpheader.DrawTransparent(GetDC(),24,85,RGB(255,0,255)); My bitmap is long and it hit some area where listbox is, but what happens is that the hit area appears that my bitmap is behind the listbox, i wanted the opposite. I wanted my bitmap to be on top of whatever control it encounter on its area.. Thanks... Below is the Code: void CDTGBitmap::Draw(CDC *pDC, int x, int y) { BITMAP bm; GetBitmap (&bm); CPoint size (bm.bmWidth, bm.bmHeight); pDC->DPtoLP (&size); CPoint org (0, 0); pDC->DPtoLP (&org); CDC dcMem; dcMem.CreateCompatibleDC (pDC); CBitmap* pOldBitmap = dcMem.SelectObject (this); pDC->BitBlt (x, y, size.x, size.y, &dcMem, org.x, org.y, SRCCOPY); dcMem.SelectObject (pOldBitmap); } void CDTGBitmap::DrawTransparent(CDC *pDC, int x, int y, COLORREF clrTransparency) { BITMAP bm; GetBitmap (&bm); CPoint size (bm.bmWidth, bm.bmHeight); pDC->DPtoLP (&size); CPoint org (0, 0); pDC->DPtoLP (&org); CDC dcImage; dcImage.CreateCompatibleDC (pDC); CBitmap* pOldBitmapImage = dcImage.SelectObject (this); CDC dcAnd; dcAnd.CreateCompatibleDC (pDC); CBitmap bitmapAnd; bitmapAnd.CreateBitmap (bm.bmWidth, bm.bmHeight, 1, 1, NULL); CBitmap* pOldBitmapAnd = dcAnd.SelectObject (&bitmapAnd); dcImage.SetBkColor (clrTransparency); dcAnd.BitBlt (org.x, org.y, size.x, size.y, &dcImage, org.x, org.y, SRCCOPY); CDC dcXor; dcXor.CreateCompatibleDC (pDC); CBitmap bitmapXor; bitmapXor.CreateCompatibleBitmap (&dcImage, bm.bmWidth, bm.bmHeight); CBitmap* pOldBitmapXor = dcXor.SelectObject (&bitmapXor); dcXor.BitBlt (org.x, org.y, size.x, size.y, &dcImage, org.x, org.y, SRCCOPY); dcXor.BitBlt (org.x, org.y, size.x, size.y, &dcAnd, org.x, org.y, 0x220326); CDC dcTemp; dcTemp.CreateCompatibleDC (pDC); CBitmap bitmapTemp; bitmapTemp.CreateCompatibleBitmap (&dcImage, bm.bmWidth, bm.bmHeight); CBitmap* pOldBitmapTemp = dcTemp.SelectObject (&bitmapTemp); dcTemp.BitBlt (org.x, org.y, size.x, size.y, pDC, x, y, SRCCOPY); dcTemp.BitBlt (org.x, org.y, size.x, size.y, &dcAnd, org.x, org.y,SRCAND); dcTemp.BitBlt (org.x, org.y, size.x, size.
-
actually i create a class CMyBitmap derived from CBitmap, void DrawTransparent (CDC* pDC, int x, int y, COLORREF clrTransparency); void Draw (CDC* pDC, int x, int y); The actual call is CMyBitmap bmpheader; bmpheader.LoadBitmap(IDB_LISTHHISTORY); bmpheader.DrawTransparent(GetDC(),24,85,RGB(255,0,255)); My bitmap is long and it hit some area where listbox is, but what happens is that the hit area appears that my bitmap is behind the listbox, i wanted the opposite. I wanted my bitmap to be on top of whatever control it encounter on its area.. Thanks... Below is the Code: void CDTGBitmap::Draw(CDC *pDC, int x, int y) { BITMAP bm; GetBitmap (&bm); CPoint size (bm.bmWidth, bm.bmHeight); pDC->DPtoLP (&size); CPoint org (0, 0); pDC->DPtoLP (&org); CDC dcMem; dcMem.CreateCompatibleDC (pDC); CBitmap* pOldBitmap = dcMem.SelectObject (this); pDC->BitBlt (x, y, size.x, size.y, &dcMem, org.x, org.y, SRCCOPY); dcMem.SelectObject (pOldBitmap); } void CDTGBitmap::DrawTransparent(CDC *pDC, int x, int y, COLORREF clrTransparency) { BITMAP bm; GetBitmap (&bm); CPoint size (bm.bmWidth, bm.bmHeight); pDC->DPtoLP (&size); CPoint org (0, 0); pDC->DPtoLP (&org); CDC dcImage; dcImage.CreateCompatibleDC (pDC); CBitmap* pOldBitmapImage = dcImage.SelectObject (this); CDC dcAnd; dcAnd.CreateCompatibleDC (pDC); CBitmap bitmapAnd; bitmapAnd.CreateBitmap (bm.bmWidth, bm.bmHeight, 1, 1, NULL); CBitmap* pOldBitmapAnd = dcAnd.SelectObject (&bitmapAnd); dcImage.SetBkColor (clrTransparency); dcAnd.BitBlt (org.x, org.y, size.x, size.y, &dcImage, org.x, org.y, SRCCOPY); CDC dcXor; dcXor.CreateCompatibleDC (pDC); CBitmap bitmapXor; bitmapXor.CreateCompatibleBitmap (&dcImage, bm.bmWidth, bm.bmHeight); CBitmap* pOldBitmapXor = dcXor.SelectObject (&bitmapXor); dcXor.BitBlt (org.x, org.y, size.x, size.y, &dcImage, org.x, org.y, SRCCOPY); dcXor.BitBlt (org.x, org.y, size.x, size.y, &dcAnd, org.x, org.y, 0x220326); CDC dcTemp; dcTemp.CreateCompatibleDC (pDC); CBitmap bitmapTemp; bitmapTemp.CreateCompatibleBitmap (&dcImage, bm.bmWidth, bm.bmHeight); CBitmap* pOldBitmapTemp = dcTemp.SelectObject (&bitmapTemp); dcTemp.BitBlt (org.x, org.y, size.x, size.y, pDC, x, y, SRCCOPY); dcTemp.BitBlt (org.x, org.y, size.x, size.y, &dcAnd, org.x, org.y,SRCAND); dcTemp.BitBlt (org.x, org.y, size.x, size.
It seems like you are just drawing the bitmap in the parent window, so any child control (e.g., the listbox) will be drawn on top of it. I suggest creating a static control with the SS_OWNERDRAW style. Put this control at the top of the children z-order and use CDTGBitmap to do the drawing in the parent's handler for the WM_DRAWITEM message. -- jlr http://jlamas.blogspot.com/[^]