OnPaint Flickering

OnPaint Flickering

I am a high school student using MS VC++ version 5.0 for my school science project. I am loading bitmaps with the StretchBlt function in the OnPaint function to simulate an object moving. It works, but the object, and any backround Bitmap flicker. How can I avoid this?

There are many places to look for the cause of flickering. The first place to look is within your own paint code. If all you are doing is calling StretchBlt, then it is probably a safe assumption that you are not the cause of the flicker.

Another place to look is at the processing of the WM_ERASEBKGND message. Windows sends this message before WM_PAINT. If a window is created with the CS_VREDRAW and CS_HREDRAW style bytes, the window is automatically cleared before painting.

To override this behavior, you can override OnEraseBkgnd, or you can override PreCreateWindow to change the style bits used to create your window like this:

BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs) {   // Here we create our own class which is registered through MFC   // If we also create our window with no background brush,   // we can avoid the window being cleared prior to OnPaint   if (cs.lpszClass == NULL)      cs.lpszClass = AfxRegisterWndClass(CS_DBLCLKS);   return TRUE;}

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing