Programming Tips - Why are my TreeView checkboxes working?

Date: 2010may18 OS: Windows Platform: Windows Language: C/C++ Q. Why are my TreeView checkboxes working? A. MSDN says:
If you want to use this style, you must set the TVS_CHECKBOXES style with SetWindowLong after you create the treeview control, and before you populate the tree. Otherwise, the checkboxes might appear unchecked, depending on timing issues.
So even if you set it in .rc file that isn't enough! My practice is to never set it in the .rc file (since it only half works) and suggests that it is working. In MFC:
In win32:
void EnableCheckboxes(HWND hwndTreeView) { DWORD dwStyle = GetWindowLong(hwndTreeView, GWL_STYLE); dwStyle |= TVS_CHECKBOXES; SetWindowLong(hwndTreeView, GWL_STYLE, dwStyle); }