Displaying a bitmap?
-
-
Hope some one can help me out here. What is the simplest way to display a bitmap in your client area? For example if I have created a bitmap with the resource editor eg IDB_BITMAP. How would I bitblt this to my client area? Thanks in advance, Paddy
Let say you have bitmap CBitmap m_bitmap; 1) Create temporary DC 2) Select new bitmap into it 3) BitBlt from temp into controlDC OnPaint { CDC dc( this); CDC tempDC; if (tempDC.CreateCompatibleDC(&dc)) { if (m_bitmap.GetSafeHandle()) { CBitmap* pOldBM = tempDC.SelectObject(&m_bitmap); BITMAP BM; m_bitmap.GetBitmap(&BM); dc.BitBlt(0, 0, BM.bmWidth, BM.bmHeight, &tempDC, 0, 0, SRCCOPY); tempDC.SelectObject(pOldBM); } }
-
Let say you have bitmap CBitmap m_bitmap; 1) Create temporary DC 2) Select new bitmap into it 3) BitBlt from temp into controlDC OnPaint { CDC dc( this); CDC tempDC; if (tempDC.CreateCompatibleDC(&dc)) { if (m_bitmap.GetSafeHandle()) { CBitmap* pOldBM = tempDC.SelectObject(&m_bitmap); BITMAP BM; m_bitmap.GetBitmap(&BM); dc.BitBlt(0, 0, BM.bmWidth, BM.bmHeight, &tempDC, 0, 0, SRCCOPY); tempDC.SelectObject(pOldBM); } }
-
Thanks for the help Brian. I forgot to mention I'm not using MFC but I presume you use the same process anyway? 1) Create temporary DC 2) Select new bitmap into it 3) BitBlt from temp into controlDC Or is it different do you know? Paddy
HDC hTempDC, hClientDC; HBITMAP hBmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1)), oldBmp; //hInst is the HISTNACE of the application hTempDC = CreateCompatibleDC(NULL); oldBmp = (HBITMAP)SelectObject(hTempDC, hBmp); hClientDC = ::GetDC(hClientWnd); //hClientWnd is the handle of the client window BITMAP BM; GetObject(hBmp, sizeof(BITMAP), &BM); BitBlt(hClientDC, 0, 0, BM.bmWidth, BM.bmHeight, hTempDC, 0, 0, SRCCOPY); ReleaseDC(hClientWnd, hClientDC); SelectObject(hTempDC, oldBmp); DeleteObject(hBmp); DeleteDC(hTempDC);
-
HDC hTempDC, hClientDC; HBITMAP hBmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1)), oldBmp; //hInst is the HISTNACE of the application hTempDC = CreateCompatibleDC(NULL); oldBmp = (HBITMAP)SelectObject(hTempDC, hBmp); hClientDC = ::GetDC(hClientWnd); //hClientWnd is the handle of the client window BITMAP BM; GetObject(hBmp, sizeof(BITMAP), &BM); BitBlt(hClientDC, 0, 0, BM.bmWidth, BM.bmHeight, hTempDC, 0, 0, SRCCOPY); ReleaseDC(hClientWnd, hClientDC); SelectObject(hTempDC, oldBmp); DeleteObject(hBmp); DeleteDC(hTempDC);