From: Joseph M. Newcomer on 8 Jun 2010 11:50 See below... On Tue, 8 Jun 2010 05:40:12 -0700, milonass <milonass(a)discussions.microsoft.com> wrote: > >Hi Giovanni, > >Thank you for your answers. I put the "text" (CString) into a message box >and the result is correct. I also now set itemstruc->item.cchTextMax = 0; **** So you are saying the string you have really says "C:"? That's new information, which you did not provide in the original question. Note also that you did not actually tell us what the itemstruc field points to; I don't care what a MessageBox says, I want to know specifically what text is seen in the string. **** > >Always the same result. > >Best regards, >Thomas > > > > > >"Giovanni Dicanio" wrote: > >> On 08/06/2010 09:36, milonass wrote: >> >> One more thing: considering that you are setting the item attributes >> (like the text), I think that you don't need to set the item.cchTextMax >> field (I would clear it to 0): >> >> > itemstruc->item.cchTextMax = 3; >> >> >> Giovanni >> . >> Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
From: milonass on 8 Jun 2010 13:31 Thank you for this answer. The class CFileSystem has no influence on the appearence of the text string in the tree item. This can easily proven by substituting the line text = CString(d); by text = "C:"; The result in the tree item is the same: ":C". I already explained that implicitly by saying that message box displays the text correctly. Regards, Thomas "Joseph M. Newcomer" wrote: > See below... > On Tue, 8 Jun 2010 00:36:32 -0700, milonass <milonass(a)discussions.microsoft.com> wrote: > > >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; > **** > CFileSystem? I cannot find this in the documentation anywhere. If you are using classes > from someplace else, you need to give us a pointer to where you found them > **** > > 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); > **** > Since we have no idea what CFileSystem is or does, showing us a line of code that invokes > an undefined method of an undefined class seems rather pointless. > > Note also that this is obviously a class designed by a beginner, because it does not > require passing the _countof(d) in as a parameter. Therefore, it is not really > trustworthy. > > How do you expect us to analyze code that uses unknown and unfindable classes? I found at > least three completely different classes called "CFileSystem" using google, at which point > I gave up, because you are obviously expecting us to know, possibly by ethereal > vibrations, exactly which of these you are using. And your question can be pretty much > answered by the explanation "GetDriveByNumber is written incorrectly, fix it", so what do > you expect us to do about this? > **** > > text = CString(d); > > if(fs.IsDriveActive(d)==TRUE){ > > itemstruc = new TVINSERTSTRUCTW; > **** > Why do you have this odd mix of Unicode-aware coding (CString, not CStringW) and > Unicode-only code (wchar_t, TVINSERTSTRUCTW, WCHAR *)? Or were you relying on > Intellinonsense to "help" you write code? > > And why, for goodness sake, are you doing a 'new' here? Have you considered just > declaring the structure on the stack? Using a 'new' here is completely silly! > **** > > 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; > **** > On a SetItemState, you do not need to provide the text length, since the string is > NUL-terminated > **** > > itemstruc->item.iImage = 3; > **** > I have no idea what "3" means. Have you ever heard of #define or const int to define > symbolic names? > **** > > itemstruc->item.iSelectedImage = 3; > **** > Ditto > *** > > HTREEITEM item = InsertItem(itemstruc); > **** > You probably used 'new' because the specification of InsertItem wants a > pointer-to-TVINSERTSTRUCT. Have you ever heard of the "&" operator? > > TVINSERTSTRUCT itemstruc; > ... fill in values > HTREEITEM Item = InsertItem(&itemstruc); > **** > > SetItemState(item,TVIS_BOLD,TVIS_BOLD); > > //SetItemState(item,TVIS_SELECTED,TVIS_SELECTED); > > delete itemstruc; > > } > > } > > > >Any ideas are really appreciated. > **** > Single-stepping the GetDriveByNumber code and seeing where it is wrong would be a really > good start. > > If you want help, you have to give us enough information to help you. > joe > **** > > > >Thomas > > > Joseph M. Newcomer [MVP] > email: newcomer(a)flounder.com > Web: http://www.flounder.com > MVP Tips: http://www.flounder.com/mvp_tips.htm > . >
From: Giovanni Dicanio on 8 Jun 2010 13:39 On 08/06/2010 19:31, milonass wrote: > Thank you for this answer. The class CFileSystem has no influence on the > appearence of the text string in the tree item. This can easily proven by > substituting the line > > text = CString(d); > > by > > text = "C:"; > > The result in the tree item is the same: ":C". Have you tried building a simple test app, just with a CTreeCtrl, and see if it happens again? Giovanni
From: milonass on 8 Jun 2010 14:42 ok, i found it. The creation style (of the tree control) TVS_EX_FADEINOUTEXPANDOS which anyway does not work is responsible for this strange behaviour. Thank you for your help. Best regards, Thomas "milonass" wrote: > 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: Mihai N. on 9 Jun 2010 03:51 > ok, i found it. The creation style (of the tree control) > TVS_EX_FADEINOUTEXPANDOS > which anyway does not work is responsible for this strange behaviour. Veird. Without this post I would have said that you run on a right-to-left system. Or the extended style of the control is WS_EX_LAYOUTRTL. The behavior is 100% consistent with that. Try putting C: and Program Files (x86) in Notepad, each on one line, right-click and check "Right to left Reading order" You will see that adding spaces at end will not change things, but adding a letter will do, exactly as you describe. Now, TVS_EX_FADEINOUTEXPANDOS is defined as 0x0040 (in CommCtrl.h) and WS_EX_LAYOUTRTL is defined as 0x00400000L (in WinUser.h) I wonder is there is some extra shifting going on with the extended styles. Maybe this also explains the "anyway does not work" part. Can you put back TVS_EX_FADEINOUTEXPANDOS, fire up Spy++, and give us the hex values of the flags and extended flags for the control? Sure, you don't have to do this. But it would be nice to know the reason, not just "some magic stuff happens" :-) -- Mihai Nita [Microsoft MVP, Visual C++] http://www.mihai-nita.net ------------------------------------------ Replace _year_ with _ to get the real email
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Regression - Instruction Next: Visual 2010 compilation errors |