I have studied carefully the code from your previous answer and managed to handle WM_WINDOWPOSCHANGED properly for multiple windows but I can not handle slight flickering.
What is causing the flicker is the way the listbox draws each item you need to do you own drawing to solve the problem there are plenty of articles on listbox flicker and solving it.
Ok to do the font simply attach the font if you need to the window .. so lets look at specific code.
First make a text string we are going to call the property in out case "FONT"
#define TEXTPROP TEXT("FONT")
Next handle WM_FONT
case WM_SETFONT:
LOGFONT lf;
HFONT OldFont, Newfont;
GetObject((HFONT)wParam, sizeof(lf), &lf);
if (lf.lfQuality != NONANTIALIASED_QUALITY){
lf.lfQuality = NONANTIALIASED_QUALITY;
Newfont = CreateFontIndirect(&lf);
OldFont = (HFONT) GetProp(hwnd, TEXTPROP);
if (OldFont != 0) DeleteObject(OldFont);
SetProp(hwnd, TEXTPROP, (HANDLE)Newfont);
} else Newfont = (HFONT) wParam;
return ::DefSubclassProc( hwnd, WM_SETFONT, (WPARAM)Newfont, lParam);
Your responsibility to delete any font WM_SETFONT created in NCDESTROY
case WM_NCDESTROY:
HFONT Font = (HFONT) GetProp(hwnd, TEXTPROP);
if (Font != 0) DeleteObject(Font);
RemoveProp(hwnd, TEXTPROP);
::RemoveWindowSubclass(hwnd, TreeProc, 0 );
return ::DefSubclassProc( hwnd, message, wParam, lParam);
It now handles the WM_FONT like any normal window.
Finally I put all the creation stuff into a helper function
HWND CreateListBox (HWND parent,
TCHAR* title,
int x, int y,
int cx, int cy,
int id,
HFONT hFont) {
DWORD dwStyle;
HWND TreeView;
TreeView = CreateWindowEx(0, WC_TREEVIEW, title,
WS_VISIBLE | WS_CHILD | WS_BORDER
| TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT,
x, y, cx, cy, parent, (HMENU)id, 0, NULL);
dwStyle = GetWindowLong( TreeView , GWL_STYLE);
dwStyle |= TVS_CHECKBOXES;
SetWindowLongPtr( TreeView , GWL_STYLE, dwStyle );
SetWindowSubclass( TreeView, TreeProc, 0, 0 );
TreeView_SetBkColor(TreeView, RGB(0xFF, 0, 0xFF));
if (hFont == 0) hFont = (HFONT) SendMessage(TreeView, WM_GETFONT, 0, 0);
SendMessage(TreeView, WM_SETFONT, (WPARAM)hFont, FALSE);
return (TreeView);
};
Your creation now looks this simple
HWND TreeView = CreateListBox(hwnd, (TCHAR*)TEXT("Tree View"),
50, 10, 200, 200, ID_LISTBOX, 0);