[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


Paint problem

Posted on 2003-11-15
Medium Priority
Last Modified: 2010-04-02

Iam using StretchDiBits to convert the DIB bitmap to Device context of

my window. It has some problem , sometimes it fails to paint the form DC

whenever i move the mouse over it get repainted.

I even tried using SetDIBitsToDevice , but it didn't  help

Is there i need to do , make this work , here is the code

Question by:Manjesh
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

georgiek50 earned 400 total points
ID: 9790532
I am not sure if this is what you are talking about but I have a routine in my code that reads a bitmap and then cuts it up into the desired squares getting bitmap handles for each (this is after I've called LoadImage for the DIB)

void cMainSkin::LoadPartialBitmap(void)
      // Function to get a handle for each button bmp

      HDC hdcMain, hdcMem, hdcMem2;
      // Get main window DC and create a memory DC
      hdcMain = GetDC(hwndMain);
      hdcMem  = CreateCompatibleDC(hdcMain);
      hdcMem2 = CreateCompatibleDC(hdcMain);

      // Run a loop seven times for each button
      for (int i = 0; i < 7; i++)
            // Create a compatible bitmap
            hButtonPartialBitmap[i] = CreateCompatibleBitmap(hdcMain, iButtonWidth[i][0],

            // Select the bitmap into the second memory DC
            SelectObject(hdcMem2, hButtonPartialBitmap[i]);

            // Select the button bitmap into the first memory DC
            SelectObject(hdcMem, hButtonBitmap);

            // Copy the desired part of the bitmap into the second memory DC
            BitBlt(hdcMem2, 0, 0, iButtonWidth[i][0], iButtonHeight[i][0],
                     hdcMem, iButtonSourceX[i][0], iButtonSourceY[i][0],

      // Release DC
      ReleaseDC(hwndMain, hdcMain);

      // Delete memory DC

Expert Comment

ID: 10249233
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: georgiek50 {http:#9790532}

Please leave any comments here within the next seven days.

EE Cleanup Volunteer

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question