From: milonass on
I build a file browser like tree with CTreeCtrl. Now, if the control has to
display a drive like "C:", it instead displays ":C". The same happens with
"Program Files (x86)" which is displayed as ")Program Files (x86". So, it
seems that if the the last character is a special character, it becomes the
first character in display name.
Is this a unicode problem? Anyway, very strange.

Here is my coding:

CFileSystem fs;
wchar_t d[3];
LPTVINSERTSTRUCTW itemstruc = NULL;
CString text;


//Load static images
m_FileViewImages.Create(IDB_FILE_VIEW, 16, 0, RGB(0,0,0));
//Set image list
this->SetImageList(&m_FileViewImages, TVSIL_NORMAL);
//Set 24 bit bitmaps for static images
this->ChangeVisualStyle( );

int num = fs.GetNumberDrives( );
for(int j = 1; j<num+1; j++){
//Get drive name
fs.GetDriveByNumber(j,d);
text = CString(d);
if(fs.IsDriveActive(d)==TRUE){
itemstruc = new TVINSERTSTRUCTW;
itemstruc->hParent = NULL;
//Set item mask
itemstruc->item.mask = TVIF_CHILDREN|TVIF_HANDLE|TVIF_IMAGE|
TVIF_STATE|TVIF_TEXT|TVIF_SELECTEDIMAGE;
//Set state mask
itemstruc->item.stateMask = TVIS_BOLD|TVIS_OVERLAYMASK|TVIS_SELECTED;
itemstruc->item.cChildren = 1;
itemstruc->item.pszText = (WCHAR*)text.GetBuffer( );
itemstruc->item.cchTextMax = 3;
itemstruc->item.iImage = 3;
itemstruc->item.iSelectedImage = 3;
HTREEITEM item = InsertItem(itemstruc);
SetItemState(item,TVIS_BOLD,TVIS_BOLD);
//SetItemState(item,TVIS_SELECTED,TVIS_SELECTED);
delete itemstruc;
}
}

Any ideas are really appreciated.

Thomas


From: Giovanni Dicanio on
On 08/06/2010 09:36, milonass wrote:

> CFileSystem fs;
> wchar_t d[3];

> for(int j = 1; j<num+1; j++){
> //Get drive name
> fs.GetDriveByNumber(j,d);

I'm not sure about this CFileSystem class and its GetDriveByNumber method...
However: is 'd' big enough to store the drive name, including the
terminating NUL (\0) ?


> text = CString(d);

> itemstruc->item.pszText = (WCHAR*)text.GetBuffer( );

You called GetBuffer, but I see no call to ReleaseBuffer in your code.
Maybe you just want to access the raw TCHAR string in 'text'?
You may want to try:

...->item.pszText = static_cast<TCHAR *>(text.GetString());

GetString() method returns a 'const TCHAR *', and the static_cast safely
removes the 'const' attribute.

> Any ideas are really appreciated.

HTH,
Giovanni

From: Giovanni Dicanio on
On 08/06/2010 10:43, Giovanni Dicanio wrote:

> ...->item.pszText = static_cast<TCHAR *>(text.GetString());
>
> GetString() method returns a 'const TCHAR *', and the static_cast safely
> removes the 'const' attribute.

Sorry for the typo: I meant const_cast:

...->item.pszText = const_cast<TCHAR *>( text.GetString() );


Giovanni

From: milonass on
Hi Giovanni,

thank you for your answer. Unfortunately, the result is the same. The
strange thing is, that the problem only occurs, when a special character at
the end of the string occurs.

Regards,
Thomas

"Giovanni Dicanio" wrote:

> On 08/06/2010 10:43, Giovanni Dicanio wrote:
>
> > ...->item.pszText = static_cast<TCHAR *>(text.GetString());
> >
> > GetString() method returns a 'const TCHAR *', and the static_cast safely
> > removes the 'const' attribute.
>
> Sorry for the typo: I meant const_cast:
>
> ...->item.pszText = const_cast<TCHAR *>( text.GetString() );
>
>
> Giovanni
>
> .
>
From: Giovanni Dicanio on
On 08/06/2010 11:51, milonass wrote:

> The
> strange thing is, that the problem only occurs, when a special character at
> the end of the string occurs.

Using the debugger, have you checked that the string stored in the
CString instance is well formed?

Also, I would be curious to know what happens if you put a space ' '
after the "special character"...

Giovanni