CBitmap
-
I have a CBitmap derrived class, and have my own Draw function. However, When it is displayed, it its overlapped by other controls. Is there a way to make a CBitmap on top of all controls? thanks..
Set the z-order of the button properly in the dialog design window
-prakash
-
Set the z-order of the button properly in the dialog design window
-prakash
Hello Prakash, I have declared CBitmap in this, CMyBitmap mybitmap; mybitmap.LoadBitmap(IDB_MYBMP); mybitmap.DrawTransparent(GetDC(),20,50,RGB(255,0,255)); Sorry I was not clear enough in the first place. CMyBitmap is derrived from CBitmap, I have to subclass because i need to make the bitmap transparent. Please help me How I could bring this on top of other controls. Anyway here is the detail of DrawTransparentFunction.(Just research this detail from other articles but it didnt bring the bitmap on top. Its weakness is when there are other control because it is overlapped.) void CMyBitmap::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); // // Create a memory DC (dcImage) and select the bitmap into it. // CDC dcImage; dcImage.CreateCompatibleDC (pDC); CBitmap* pOldBitmapImage = dcImage.SelectObject (this); //dcImage.SetMapMode (pDC->GetMapMode ()); // // Create a second memory DC (dcAnd) and in it create an AND mask. // CDC dcAnd; dcAnd.CreateCompatibleDC (pDC); //dcAnd.SetMapMode (pDC->GetMapMode ()); 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); // // Create a third memory DC (dcXor) and in it create an XOR mask. // CDC dcXor; dcXor.CreateCompatibleDC (pDC); //dcXor.SetMapMode (pDC->GetMapMode ()); 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); // // Copy the pixels in the destination rectangle to a temporary // memory DC (dcTemp). // CDC dcTemp; dcTemp.CreateCompatibleDC (pDC); //dcTemp.SetMapMode (pDC->GetMapMode ()); 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); // // Genera
-
Hello Prakash, I have declared CBitmap in this, CMyBitmap mybitmap; mybitmap.LoadBitmap(IDB_MYBMP); mybitmap.DrawTransparent(GetDC(),20,50,RGB(255,0,255)); Sorry I was not clear enough in the first place. CMyBitmap is derrived from CBitmap, I have to subclass because i need to make the bitmap transparent. Please help me How I could bring this on top of other controls. Anyway here is the detail of DrawTransparentFunction.(Just research this detail from other articles but it didnt bring the bitmap on top. Its weakness is when there are other control because it is overlapped.) void CMyBitmap::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); // // Create a memory DC (dcImage) and select the bitmap into it. // CDC dcImage; dcImage.CreateCompatibleDC (pDC); CBitmap* pOldBitmapImage = dcImage.SelectObject (this); //dcImage.SetMapMode (pDC->GetMapMode ()); // // Create a second memory DC (dcAnd) and in it create an AND mask. // CDC dcAnd; dcAnd.CreateCompatibleDC (pDC); //dcAnd.SetMapMode (pDC->GetMapMode ()); 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); // // Create a third memory DC (dcXor) and in it create an XOR mask. // CDC dcXor; dcXor.CreateCompatibleDC (pDC); //dcXor.SetMapMode (pDC->GetMapMode ()); 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); // // Copy the pixels in the destination rectangle to a temporary // memory DC (dcTemp). // CDC dcTemp; dcTemp.CreateCompatibleDC (pDC); //dcTemp.SetMapMode (pDC->GetMapMode ()); 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); // // Genera
I dont think it is a problem with your drawing, The problem is probably with the placement of the controls. If the controls are overlaping that means, you have placed them like that. or is the bitmap drawing beyond your required place. or if you want the bitmap to be drawn over other contorls, consider making thouse contorls invisible.
-prakash