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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ZoppoConnect With a Mentor Commented:
Hmmmm, not sure what the answer was, but ok, here it is :o)
0
 
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
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
migelCommented:
Hi!
I do not see ::DeleteObject(tmp) in the your method
0
 
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
All Courses

From novice to tech pro — start learning today.