lsb
April 28th, 1999, 10:48 AM
Hello.
I Want to use bitmap background in CFormView.
Please Show me the way.
Bye.
I Want to use bitmap background in CFormView.
Please Show me the way.
Bye.
|
Click to See Complete Forum and Search --> : Bitmap Background in CFormView lsb April 28th, 1999, 10:48 AM Hello. I Want to use bitmap background in CFormView. Please Show me the way. Bye. PeterK April 30th, 1999, 02:09 PM Several methods will need to change. Here is an example: These member variables will be needed: int m_bitmapLeft; int m_bitmapTop; CBitmap m_bitmap; void CFormcntlView::OnInitialUpdate() { CView::OnInitialUpdate(); int tmpNum; int statusBarHeight=0; // screen resolution RECT tmpRec; // window area minus task bar SystemParametersInfo( SPI_GETWORKAREA, 0, &tmpRec, 0); WINDOWPLACEMENT wndPlace; wndPlace.length = sizeof(WINDOWPLACEMENT); CMainFrame* pFrame = (CMainFrame*)GetParent(); pFrame->m_wndStatusBar.GetWindowPlacement(&wndPlace); statusBarHeight = wndPlace.rcNormalPosition.bottom - wndPlace.rcNormalPosition.top; // status bar positions not set yet statusBarHeight = 18; m_bitmap.LoadBitmap(IDB_MYBITMAPRESOURCE); BITMAP bm; m_bitmap.GetBitmap(&bm); tmpNum = tmpRec.bottom - tmpRec.top; // not sure why it needs to be times 3 but it works that way tmpNum -= (statusBarHeight * 3); if ( 0 > (tmpNum - bm.bmHeight)) { m_bitmapTop = 0; } else { m_bitmapTop = (tmpNum - bm.bmHeight) / 2; } // width of bitmap tmpNum = tmpRec.right - tmpRec.left; if ( 0 > (tmpNum - bm.bmWidth)) { m_bitmapLeft = 0; } else { m_bitmapLeft = (tmpNum - bm.bmWidth) / 2; } } void CFormcntlView::OnDraw(CDC* pDC) { CFormcntlDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here CDC dc; dc.CreateCompatibleDC(pDC); CBitmap* pBitmap = dc.SelectObject(&m_bitmap); int xValue, yValue; xValue = GetSystemMetrics(SM_CXSCREEN); yValue = GetSystemMetrics(SM_CYSCREEN); pDC->BitBlt(m_bitmapLeft, m_bitmapTop, xValue, yValue, &dc, 0, 0, SRCAND); dc.SelectObject(pBitmap); } BOOL CFormcntlView::OnEraseBkgnd(CDC* pDC) { // TODO: Add your message handler code here and/or call default CRect clientRct; pDC->GetClipBox(&clientRct); RECT rct; BITMAP bm; m_bitmap.GetBitmap(&bm); rct.left = m_bitmapLeft; rct.top = m_bitmapTop; rct.right = m_bitmapLeft + bm.bmWidth; rct.bottom = m_bitmapTop + bm.bmHeight; CBrush brushBack(RGB(192,192,192)); // Gray CBrush* pOldBrush = pDC->SelectObject(&brushBack); pDC->PatBlt(clientRct.left, clientRct.top, clientRct.Width(), clientRct.Height(), PATCOPY); CBrush brushWhiteBack(RGB(255,255,255)); // White CRgn bitmapRegion; bitmapRegion.CreateRectRgnIndirect(&rct); pDC->FillRgn(&bitmapRegion, &brushWhiteBack); pDC->SelectObject(pOldBrush); return(TRUE); } codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |