A common cause of flickering is when the background of a window is painted again. You can avoid it in classical C programming with these three lines in your message loop:
Code:
      case WM_ERASEBKGND:
         return(1); // Prevent erasing the background to reduce flickering
         break;