Screen won't update

Hi:
I have a function somewhat like this:
void CDrawWnd::Draw(CDC& dc, int nWidth, int nHeight, int pref)
{
      CDC nCompat;
      nCompat.CreateCompatibleDC(&dc);
   HBITMAP tmp;
    if(pref ==1 )
      {
      tmp = (HBITMAP) LoadImage(NULL, "C:\\Windows\\Desktop\\Cami.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    }
      else
      {
      tmp = (HBITMAP) LoadImage(NULL, "C:\\Windows\\Desktop\\Cami2.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    }
      ASSERT(tmp);
      m_CamiImage = CBitmap::FromHandle(tmp);
      CBitmap*  pOld = nCompat.SelectObject(m_CamiImage);
      BITMAP bmInfo;
      m_CamiImage->GetBitmap(&bmInfo);
      srand( (unsigned) time(NULL));
      dc.BitBlt(nWidth/4, nHeight, bmInfo.bmWidth, bmInfo.bmHeight, &nCompat, 0, 0, SRCCOPY);
      ncompat.SelectObject(pOld);
}

In the initial setup I call pref of 1, and in my OnTimer function I call pref of 2. I know my OnTimer function is getting called, but for some reason, the bitmap doesn't change to the new one...as far as I can tell nothing is different.


Can you please help me? Thank you.
LVL 1
jwilcoxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZoppoCommented:
How did you create the dc passed to the Draw() function? Can you post code of your OnTimer() function where you call this Draw() function? I think it would be better to move the call for Draw() to a WM_PAINT handler (e.g. OnDraw()) and in the OnTimer() just call Invalidate() to force redrawing the window. Therefor you'll have to store the 'pref' as a member of you window-class and set it in constructor to 1 and in OnTimer() to 2.

ZOPPO
0
akalmaniCommented:
hi !!
  Try using with this CreateCompatibleBitmap() may be that is the problem
0
migelCommented:
Hi!
I do not see ::DeleteObject(tmp) in the your method
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

jwilcoxAuthor Commented:
Zoppo:
  Put your comment back in as a answer, and I'll gladly accept it!
0
jwilcoxAuthor Commented:
Zoppo:
  Put your comment back in as a answer, and I'll gladly accept it!
0
ZoppoCommented:
Hmmmm, not sure what the answer was, but ok, here it is :o)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.