I need help on this maybe old and long issue of flicker in C Win32 Native programming. Can somebody here help me with it. I've done some googling about it but didn't found perfect answer for my situation.
My application is maybe simple.
It's a window with splitter in-between these two controls:
Left is a Listview control (not flickering anymore).
HWND
CreateListView(HWND hwndParent)
{
RECT rcClient;
GetClientRect(hwndParent, &rcClient);
HWND hWndListView = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, L"",
WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | LVS_REPORT | LVS_EDITLABELS, 0, 0,
rcClient.right - rcClient.left,
rcClient.bottom - rcClient.top,
hwndParent, (HMENU) IDL_LV1, g_hInstance, NULL);
InitListViewColumns(hWndListView);
return (hWndListView);
}
Right is an Edit box control.
HWND
CreateEditView(HWND hwndParent)
{
HDC hdc = GetDC(hwndParent);
// Create Font
const TCHAR* fontName = TEXT("Myanmar Text");
const long nFontSize = 8;
LOGFONT lf = {0};
lf.lfHeight = -MulDiv(nFontSize, GetDeviceCaps(hdc, LOGPIXELSY), 72);
//lf.lfWeight = FW_BOLD;
lstrcpy(lf.lfFaceName, fontName);
HFONT s_hFont = CreateFontIndirect(&lf);
// Create the edit control
// WS_EX_COMPOSITED
HWND hwndEV = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("edit"), NULL,
WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL,
0, 0, 0, 0, hwndParent, (HMENU) IDE_EDIT_VIEW, g_hInstance, NULL);
// Set the font for this control
SendMessage(hwndEV, WM_SETFONT, (WPARAM) s_hFont, (LPARAM) MAKELONG(TRUE, 0));
ReleaseDC(hwndParent, hdc);
return hwndEV;
}
I solved the flicker on the Listview by simple setting it to WS_CLIPCHILDREN style.
Now while moving splitter, I managed to lessen the flicker on Edit box using a trick of a timer and using WS_EX_COMPOSITED on the main window. Though not 100% flicker free, I am ok to settle on the result. However, I noticed something odd on it. When the
main window is on initial state (I mean when the window first load: not resized yet), the flicker trick i did is working good at least in my opinion. However when I started to resize the main window (drag the borders of the window, minimized it, maximized
it), the odd things will happen. Now anytime I move in and out the mouse pointer on the Edit box it flickers. It flickers too now when I move the splitter (after I resized the main window of course). I hope I can show the video of it.
PS: Flicker is noticeable only when there is text(s) on the edit control.
Anyone who can help here is highly appreciated.
Thank you!