Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. WM_PAINT seems not working

WM_PAINT seems not working

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelpquestionlearning
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    int01hh
    wrote on last edited by
    #1

    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 ?

    B J 2 Replies Last reply
    0
    • I int01hh

      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 ?

      B Offline
      B Offline
      beerboy_22
      wrote on last edited by
      #2

      You should NEVER update your window using the above method... Instead use: InvalidateRect(hWnd, NULL, TRUE);

      1 Reply Last reply
      0
      • I int01hh

        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 ?

        J Offline
        J Offline
        JohnCz
        wrote on last edited by
        #3

        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 displayed void 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

        I 1 Reply Last reply
        0
        • J 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 displayed void 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

          I Offline
          I Offline
          int01hh
          wrote on last edited by
          #4

          Big thanks for Your help guys. InvalidateRect(hWnd, NULL, TRUE); Did the thing. Grtz.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups