Jump to content
Tuts 4 You

[solved] Subclass label(static text) to avoid flickering


alaphate

Recommended Posts

I subclassed a label(static text) control to avoid text flicking,

and dealed with WM_SETTEXT of label's message,

however, the bitblt function didn't work.

Thank you. Attachment is the c++ source.


//label's subclass wndProc
char szBuf[512]={0};
HDC hdc, hdcMem;
if(message == WM_SETTEXT) {
strcpy(szBuf, (char *)lParam);
lParam = 0;
hdc = GetDC(hLabel);
hdcMem = CreateCompatibleDC(hdc);
SetTextColor(hdcMem, RGB(255,0,0));
TextOut(hdcMem, 0, 0, szBuf, strlen(szBuf));
BitBlt(hdc, 0, 0, 300, 300, hdcMem, 0, 0, SRCCOPY);
DeleteDC(hdcMem);
ReleaseDC(hLabel, hdc);
return 0;
}

flickerLabel.zip

Edited by alaphate
Link to comment

Hmm,

I don't know about the flicker... Maybe you should handle the WM_CTLCOLORSTATIC message.

Look here for an example of how to do that...

Greetings,

Mr. eXoDia

Link to comment

Mr. eXoDia,

Thank you for the example, WM_CTLCOLORSTATIC is used to change

Static Text or readonly Edit Box's font color and background.

To avoid text blinking when it is updated very frequently, double buffer HDC

should be used.

The problem is that I couldn't make BitBlt take effect.

Link to comment

If I select a bitmap to hdcMem and draw text on it, BitBlt will work.

It's resolved :cowboy:

Edited by alaphate
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...