WM_PAINT seems not working
-
Hi guys, i've been writing a simple app that draws a bitmap held in resource. The idea Was to move a bitmap from x1 to x2 - simple animation. I have never met such a problem with WM_PAINT / UpdateWindow, the animation can be seen only when i drag another application over my form (it refreshes then) - it looks there is a problem with WM_PAINT in my app, can't get it working - any ideas? Normally 99.9% of my apps (where some drawings are done) are refreshed using: SendMessage(hWnd,WM_PAINT,0,0); And after that call, everything is fine, but this time it doesn't work - any tip ?
-
Hi guys, i've been writing a simple app that draws a bitmap held in resource. The idea Was to move a bitmap from x1 to x2 - simple animation. I have never met such a problem with WM_PAINT / UpdateWindow, the animation can be seen only when i drag another application over my form (it refreshes then) - it looks there is a problem with WM_PAINT in my app, can't get it working - any ideas? Normally 99.9% of my apps (where some drawings are done) are refreshed using: SendMessage(hWnd,WM_PAINT,0,0); And after that call, everything is fine, but this time it doesn't work - any tip ?
You should NEVER update your window using the above method... Instead use: InvalidateRect(hWnd, NULL, TRUE);
-
Hi guys, i've been writing a simple app that draws a bitmap held in resource. The idea Was to move a bitmap from x1 to x2 - simple animation. I have never met such a problem with WM_PAINT / UpdateWindow, the animation can be seen only when i drag another application over my form (it refreshes then) - it looks there is a problem with WM_PAINT in my app, can't get it working - any ideas? Normally 99.9% of my apps (where some drawings are done) are refreshed using: SendMessage(hWnd,WM_PAINT,0,0); And after that call, everything is fine, but this time it doesn't work - any tip ?
You should never send WM_PAINT message. This should be invoked by using Invalidate or InvalidateRect. Use timer and make change of a drawing bitmap here. After that call Invalidate. For example: Bitmaps and index value are declared in header file:
CBitmap m_Bitmap[2]; UINT m_uiIndx;
In OnInitDialog bitmaps (array of 2) are loaded and timer set up.BOOL CSomeDlg::OnInitDialog() { CDialog::OnInitDialog(); m_Bitmap[0].LoadBitmap(IDB_BITMAP1); m_Bitmap[1].LoadBitmap(IDB_BITMAP2); SetTimer(23, 600, NULL); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
Timer sets index of a bitmap and calls Invalidate.void CSomeDlg::OnTimer(UINT nIDEvent) { if(++m_uiIndx > 1) //change bitmap index { m_uiIndx = 0; } Invalidate(); CDialog::OnTimer(nIDEvent); }
In OnPaint proper bitmap is displayedvoid CSomeDlg::OnPaint() { CPaintDC dc(this); // device context for painting CDC memDC; memDC.CreateCompatibleDC(&dc); BITMAP bm; m_Bitmap[m_uiIndx].GetBitmap(&bm); CBitmap *pOld = memDC.SelectObject(&m_Bitmap[m_uiIndx]); dc.BitBlt(15, 15, bm.bmWidth, bm.bmHeight, &memDC, 0, 0, SRCCOPY); memDC.SelectObject(pOld); }
JohnCz -
You should never send WM_PAINT message. This should be invoked by using Invalidate or InvalidateRect. Use timer and make change of a drawing bitmap here. After that call Invalidate. For example: Bitmaps and index value are declared in header file:
CBitmap m_Bitmap[2]; UINT m_uiIndx;
In OnInitDialog bitmaps (array of 2) are loaded and timer set up.BOOL CSomeDlg::OnInitDialog() { CDialog::OnInitDialog(); m_Bitmap[0].LoadBitmap(IDB_BITMAP1); m_Bitmap[1].LoadBitmap(IDB_BITMAP2); SetTimer(23, 600, NULL); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
Timer sets index of a bitmap and calls Invalidate.void CSomeDlg::OnTimer(UINT nIDEvent) { if(++m_uiIndx > 1) //change bitmap index { m_uiIndx = 0; } Invalidate(); CDialog::OnTimer(nIDEvent); }
In OnPaint proper bitmap is displayedvoid CSomeDlg::OnPaint() { CPaintDC dc(this); // device context for painting CDC memDC; memDC.CreateCompatibleDC(&dc); BITMAP bm; m_Bitmap[m_uiIndx].GetBitmap(&bm); CBitmap *pOld = memDC.SelectObject(&m_Bitmap[m_uiIndx]); dc.BitBlt(15, 15, bm.bmWidth, bm.bmHeight, &memDC, 0, 0, SRCCOPY); memDC.SelectObject(pOld); }
JohnCz