Re: How can i set the style of a CTreeCtrl within a CTreeView ?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



They didn't. This is a documentation error, and I will add it to my list of documentation
errors.
joe

On Wed, 14 May 2008 10:40:01 -0700, PRMARJORAM <PRMARJORAM@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:

Exactly,

i was looking for a method something like SetStyle, then looking at the msdn
documentation for using CTreeCtrl, stated had to use SetWindowLong

I could not believe they had left something so fundamental out of the class
interface, they had not...


"Joseph M. Newcomer" wrote:

See below...
On Wed, 14 May 2008 08:01:02 -0700, PRMARJORAM <PRMARJORAM@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:

Im using a MFC CTreeView which fits nicely with what im trying to do. I need
to change the style of the nested CTreeCtrl.

There is no easy way to do this, the documentation points to using
SetWindowLong.

void CMyTreeView::OnInitialUpdate()

{

CTreeView::OnInitialUpdate();

CTreeCtrl& tree = GetTreeCtrl();

HTREEITEM root_item = tree.InsertItem(CString("MyProject"));
HTREEITEM init_request = tree.InsertItem(CString("Item 1"), root_item);
HTREEITEM doc_package = tree.InsertItem(CString("Item 2"), root_item);

ASSERT(tree.GetSafeHwnd() != NULL );

::SetWindowLong(tree.GetSafeHwnd(),GWL_STYLE,TVS_HASLINES |TVS_LINESATROOT);
****
(a) this is not good style for setting styles. You have cleared ALL the style bits,
EXCEPT the two you set. At the VERY MINIMUM this code should say

DWORD style = tree.GetStyle();
style |= TVS_HASLINES | TVS_LINESATROOT;
::SetWindowLong(tree.GetSafeHwnd(), GWL_STYLE, style);

but why go through all that work? Instead, just call

tree.ModifyStyle(0, TVS_HASLINES | TVS_LINESATROOT);

which should be sufficient (no need to get the old style, etc.)
joe
****
}

Iv tried using this to set the styles as in the above code, but the program
gets corrupted.

How can i set the style of a CTreeCtrl nested in a CTreeView?




Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: if !defined and #pragma once
    ... Very good points Joe! ... discussion of _MSC_VER, is merely incompetent documentation. ... is it -really- MS's intent to replace technical documents with blogs? ... VS5 was such crap that not only didn't it work very well, ...
    (microsoft.public.vc.mfc)
  • Re: Exporting from dll - Why do I need "extern C"?
    ... Thanks Joe... ... The documentation should have mentioned this... ... which will change from time to time depending on the compiler ... The warning must be new in VS 2005, ...
    (microsoft.public.vc.mfc)
  • Re: CSingleLock same-thread double-access problem.
    ... Because I get code written for Win2K pre-SP1 that has a ... The documentation lobotimization also started with the infamous "See your ... I AM MY SITE ADMINISTRATOR AND I NEED ...
    (microsoft.public.vc.mfc)
  • Re: CSingleLock same-thread double-access problem.
    ... I seriously worry about the degradation in the quality of the documentation; ... Usually, there is a germ of truth in most MSDN docs, ...
    (microsoft.public.vc.mfc)
  • Re: Reentrancy issue
    ... Joe, who has lots of experience and value the importance of documentation, ... having never read a documentation that clearly stated to not use CString ... instances without the cast. ...
    (microsoft.public.vc.mfc)