Hi i'm a student and have problem with moving bitmap. I must load it in the center of client area and after there moving using keys but it doesn't work :( Can you help me this is the code:

CKursovaView::CKursovaView()
{

	size=CSize(50,50);
	
 
	// TODO: add construction code here

}

CKursovaView::~CKursovaView()
{
}

BOOL CKursovaView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CKursovaView drawing

void CKursovaView::OnDraw(CDC* pDC)
{
	CKursovaDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
		HBITMAP hBmp;
	hBmp= (HBITMAP)::LoadImage(AfxGetResourceHandle(),MAKEINTRESOURCE(IDB_BITMAP1),IMAGE_BITMAP,0,0,
    LR_CREATEDIBSECTION);
		
	CBitmap bmp;
	bmp.Attach(hBmp);
   
   CDC bmDC;
   bmDC.CreateCompatibleDC(pDC);
   CBitmap *pOldbmp = bmDC.SelectObject(&bmp);
   CWnd *wnd=pDC->GetWindow();
   wnd->GetWindowRect(rect);
   new_rect.left =(rect.Width()/2)-(size.cx/2);
   new_rect.top = (rect.Height()/2)-(size.cy/2);
  
   pt.x=new_rect.left;
   pt.y=new_rect.top; 
   pDC->BitBlt(pt.x,pt.y,size.cx,size.cy,&bmDC,0,0,SRCCOPY);
   bmDC.SelectObject(pOldbmp);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CKursovaView printing

BOOL CKursovaView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CKursovaView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CKursovaView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CKursovaView diagnostics

#ifdef _DEBUG
void CKursovaView::AssertValid() const
{
	CView::AssertValid();
}

void CKursovaView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CKursovaDoc* CKursovaView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CKursovaDoc)));
	return (CKursovaDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CKursovaView message handlers

void CKursovaView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
		switch(nChar)
	{
		case (VK_RIGHT):
		{
			pt.x++;
			Invalidate();
			break;
		}
			case (VK_LEFT):
		{
			pt.x--;
			Invalidate();
			break;
		}
		case (VK_UP):
		{
			pt.y--;
			Invalidate();
			break;
		}
		case (VK_DOWN):
		{
			pt.y++;
			Invalidate();
			break;
		}
	}

I must load it in the center of client area and after there moving using keys but it doesn't work

Just quickly commenting on this keyboard ineffectivity, what do the following lines do?

pt.x=new_rect.left;
pt.y=new_rect.top;
This article has been dead for over six months. Start a new discussion instead.