How can I set the number of spaces a tab is in a CRichEditView?
How can I set the number of spaces a tab is in a CRichEditView? By default a tab is 6 spaces.. how can I make it so it is 4 spaces?
sample code appreciated!!
Thanks!
[183 byte] By [
lab1] at [2007-11-18 1:37:37]

# 1 Re: How can I set the number of spaces a tab is in a CRichEditView?
PARAFORMAT pf ;
pf.cbSize = sizeof(PARAFORMAT);
pf.dwMask = PFM_TABSTOPS ;
pf.cTabCount = MAX_TAB_STOPS;
// Set tab stops every inch (=1440 twip)
for( int itab = 0 ; itab < pf.cTabCount ; itab++ )
pf.rgxTabs[itab] = (itab+1) * 1440 ;
SetParaFormat( pf );
from http://www.dev-archive.com/richedit/tab_stops.shtml
# 2 Re: How can I set the number of spaces a tab is in a CRichEditView?
I tried that exact code.. I put it in my CRichEditView derived class in the OnInitialUpdate() function and it didnt do anything! How can I make it be just like VC++ text?
thanks!
lab1 at 2007-11-10 8:54:56 >

# 3 Re: How can I set the number of spaces a tab is in a CRichEditView?
I tried that exact code.. I put it in my CRichEditView derived class in the OnInitialUpdate() function and it didnt do anything! How can I make it be just like VC++ text?
thanks!
lab1 at 2007-11-10 8:56:05 >

# 4 Re: How can I set the number of spaces a tab is in a CRichEditView?
The above code works on the selected text only. Call CRichEditCtrl::SetSel(0,-1). This will select all the text then do the code above.
Hope this helps.
-Ben
bmacri at 2007-11-10 8:56:59 >

# 5 Re: How can I set the number of spaces a tab is in a CRichEditView?
but how do I make it so it always indents 4 spaces instead of 6? because in the code later I call many SetSel()'s so will this change the tab spacing for the document?
Thanks!
lab1 at 2007-11-10 8:58:09 >

# 6 Re: How can I set the number of spaces a tab is in a CRichEditView?
It all depends on what's happing in the control. From my understanding if you select all and change the paragraph style to have certain tabs then this will stay that way until:
1) The user changes the paragraph style by using one of the hotkeys that are supplied through RichEdit.
2) You change the paragraph style.
Here's an example. Let say you have an empty control and select all and set the tabs. Now you can type or add text(as long as it is just text and not formatted text) and the tabs should stay the same. The whole thing about the tabs only applying to the selection is that if you only selected half the text and changed the tabs then only that selection would change(not always if the start or end of the selection was in the middle of a paragraph).
The key is applying the changes to the end of paragraph marker. That last little part that can be selected but never deleted. You can check out ITextRange for a good explaination. But if that is changed then everything added to it will have that paragraph style(UNLESS IT'S FORMATTED TEXT).
Does that make sense? If not I'll try again.
-Ben
bmacri at 2007-11-10 8:59:07 >

# 7 Re: How can I set the number of spaces a tab is in a CRichEditView?
makes sense.. so maybe you can explain why this doesnt do anything?:
long lOldX;
long lOldY;
CRichEditCtrl &EditControl = GetRichEditCtrl();
EditControl.GetSel(lOldX, lOldY);
EditControl.HideSelection(TRUE, FALSE);
EditControl.SetSel(0, -1); // Full selection
PARAFORMAT pf;
pf.cbSize = sizeof(PARAFORMAT);
pf.dwMask = PFM_TABSTOPS;
pf.cTabCount = MAX_TAB_STOPS;
for(int i = 0; i < pf.cTabCount; i++)
pf.rgxTabs[i] = (i + 1) * 1440;
SetParaFormat(pf);
EditControl.SetSel(lOldX, lOldY);
EditControl.HideSelection(FALSE, FALSE);
I have this code in my OnInitialUpdate() method in my CRichEditView derived class.
now I change the "1440" to various number including up to 8000 and no matter what, the tab is always the same length(6 spaces)
what might I be doing wrong?
Thanks!
lab1 at 2007-11-10 9:00:11 >

# 8 Re: How can I set the number of spaces a tab is in a CRichEditView?
My first thought is what version of the Rich Edit are you using? I'm not sure it will work in v1.0. Take a look at this for changing versions.http://www.dev-archive.com/richedit/RichEdit20.shtml
What if you used PARAFORMAT2 instead of PARAFORMAT?
What about changing the paragraph style after some text has been entered? Maybe make a menu item that will select all and change the tabs and try it at different times and see what happens.
The last thought I have is what about setting the width of the view with CRichEditView::SetPaperSize though I don't think this will matter.
If I get some time I'll try a sample project and see if I can get it working. Good luck.
-Ben
bmacri at 2007-11-10 9:01:12 >

# 9 Re: How can I set the number of spaces a tab is in a CRichEditView?
Check this sample out. I used the code you posted and it seems to work fine. At first the tabs are set to 1/2 and inch. I also have two menu items defined under the edit menu. One changes the tab to 1 inch and the other to 2 inches. This sample also includes the code you need to make sure you are using the Riched20.dll. Check it out and let me know if you have any questions.
Hope this helps.
-Ben
bmacri at 2007-11-10 9:02:08 >

# 10 Re: How can I set the number of spaces a tab is in a CRichEditView?
Well yours definitly works.. I tried using your exact code, and no luck with mine.. I mean the lines were the same in OnInitialUpdate and PreCreateWindow()... so now im wondering if I am doing something else that interferes with that? I know I change the font and a few other things, but I tried commenting all my extra code out, and still no luck..
any ideas?
lab1 at 2007-11-10 9:03:09 >

# 11 Re: How can I set the number of spaces a tab is in a CRichEditView?
One think to check is when you run in debug mode check for these lines in the debug tab.
Loaded 'C:\WINNT\system32\riched32.dll', no matching symbolic information found.
Loaded 'C:\WINNT\system32\riched20.dll', no matching symbolic information found.
If the riched20.dll isn't in there then Rich Edit 2.0 isn't being loaded.
I think the real way of checking is to add a menu item or a button somewhere and put code in there to change the tab size(like the sample). This way you can try that command and only that command and see if anything changes.
Do you ever set the ReadOnly flag or set text to protected? If you do that might be the problem.
That's about all I can think of. Let me know if any of those work or ring a bell.
-Ben
bmacri at 2007-11-10 9:04:06 >

# 12 Re: How can I set the number of spaces a tab is in a CRichEditView?
OK I got it to work off a menu button, but not in initial update... any ideas why not? I also got it to work with 1.0 on the menu button...
OnInitialUpdate() seems the ideal place to have it.. since I want to hide it form the user..
Thanks!
Curtis
lab1 at 2007-11-10 9:05:14 >

# 13 Re: How can I set the number of spaces a tab is in a CRichEditView?
I'm glad it's kind of working. Now we can narrow it down. I agree that OnInitialUpdate() seems like the best place to put it and it works that way in the sample so I would think that something is happening after OnIntialUpdate().
Are you loading text in at all or are you just allowing the user to start typing?
I almost assume that you're pasting text in because of that other problem you posted. If that's the case I would think that the formatting is coming along with the text. After pasting, change the paragraph style on the text after it is brought in. See if that works.
Since the tabs are being set at the beginning then they will only change if you change the paragraph style or text that is brought in has a different paragrah style. Are there any places that you change the paragraph style?
If all else fails then I say pray to the Rich Edit guru Simon666 and hope he provides an answer. If your reading this do you have any thoughts?
-Ben
bmacri at 2007-11-10 9:06:10 >

# 14 Re: How can I set the number of spaces a tab is in a CRichEditView?
Originally posted by bmacri
If all else fails then I say pray to the Rich Edit guru Simon666 and hope he provides an answer. If your reading this do you have any thoughts?
-Ben
Actually I have been reading this thread with great interest. I'm surprised you call me guru, I may have 2000+ posts but so does Xeon. :D I have tested your project once Ben and indeed it works. I used the code once in my project and found out it didn't work. I've already found out what lines of code caused it. The problem is in my case caused because I call
GetRichEditCtrl().Clear();
in my view's OnUpdate function. I use thatover there to clear the contents before placing the (new) text in the richedit control. Actually, calling GetRichEditCtrl().ReplaceSel("Whatever"); causes the same effect, no matter what you seem to put after it. Another thing I noticed is that the location of the Clear or ReplaceSel is not important either, if you put it anywhere in a function that gets executed after OnInitialUpdate the format of the tabs goes lost. Problem is I don't know yet how to solve it. :( :rolleyes: I'll look into this tomorrow.
# 15 Re: How can I set the number of spaces a tab is in a CRichEditView?
That is why I consider you a guru. When it comes to Rich Edit stuff you always seem to find an answer. I don't have the stuff at home to try it out but I'll give it a shot on Monday.
Thanks!
-Ben
bmacri at 2007-11-10 9:08:18 >

# 16 Re: How can I set the number of spaces a tab is in a CRichEditView?
Sorry, it was late yesterday. I checked it out the "solution" I posted yesterday in Ben's test program and there the code seemed to work. However, so did his original code, even when you placed GetRichEditCtrl().Clear() or ReplaceSel() after it. In my original program, that code still doesn't work when you do a Clear or ReplaceSel. Apparently all that was necessary to make it work was to use Ben's PreCreateWindow function too. Then it all worked fine. Could you explain perhaps Ben why this could make a difference? I have RichEd20.DLL on my system and I thought this was automatically loaded when you use a richeditview?
BOOL C***View::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style |= WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_WANTRETURN | ES_NOHIDESEL;
BOOL ret = CRichEditView::PreCreateWindow(cs);
HMODULE hMod = LoadLibrary("RICHED20.DLL");
if(!hMod)
{
AfxMessageBox("Riched20.dll is missing or not correctly registered.", MB_OK | MB_ICONSTOP );
return FALSE;
}
cs.lpszClass = "RichEdit20A";
return ret;
}
void C***View::OnInitialUpdate()
{
CRichEditView::OnInitialUpdate();
PARAFORMAT pf;
pf.cbSize = sizeof(PARAFORMAT);
pf.dwMask = PFM_TABSTOPS;
pf.cTabCount = MAX_TAB_STOPS;
for(int i = 0; i < pf.cTabCount; i++)
pf.rgxTabs[i] = (i + 1) * 120;
SetParaFormat(pf);
// Just testing
GetRichEditCtrl().Clear();
}
# 17 Re: How can I set the number of spaces a tab is in a CRichEditView?
From my understanding even if you have or load the riched20.dll doesn't mean you're using it. For some strange reason Microsoft hardcoded the type of class to use. By default when creating a CRichEditView or CRichEditCtrl they always set
cs.lpszClass = "RichEdit"
which uses Rich Edit version 1. To be able to use version 2 or higher you have to set
cs.lpszClass = "RichEdit20A"
or change it in the .rc file.
I'm not sure why it wouldn't work with Rich Edit version 1. Maybe they changed something to fix that problem. I'll play around with it on Monday and see what I can come up with.
-Ben
bmacri at 2007-11-10 9:10:18 >

# 18 Re: How can I set the number of spaces a tab is in a CRichEditView?
Well im still hanging in there.. I use some Clear()'s and ReplaceSel()'s in my RichEditView class after my OnInitialUpdate() function.. so maybe this is my problem? Would it be an idea to try to create a method that calls the same code as we have in OnInitialUpdate() after every call to a Clear() or ReplaceSel()?
Thanks!
lab1 at 2007-11-10 9:11:21 >

# 19 Re: How can I set the number of spaces a tab is in a CRichEditView?
Originally posted by lab1
Would it be an idea to try to create a method that calls the same code as we have in OnInitialUpdate() after every call to a Clear() or ReplaceSel()?
I tried that already and it did not work for me. Did the PreCreateWindow function not help you? It did for me.
# 20 Re: How can I set the number of spaces a tab is in a CRichEditView?
I have also tried this using richedit 2.0 and 1.0, neither seems to make a difference.
Thanks.
lab1 at 2007-11-10 9:13:19 >

# 21 Re: How can I set the number of spaces a tab is in a CRichEditView?
Yeah, I tried the PreCreate stuff and it did nothing more to help me. I stepped through it to make sure there wasnt an error loading the DLL and there wasnt.
Any ideas?
lab1 at 2007-11-10 9:14:15 >

# 22 Re: How can I set the number of spaces a tab is in a CRichEditView?
Originally posted by lab1
Any ideas?
Nope. Out of ideas. You could still attach a (sample) project containing the richedit view displaying that behaviour so we could take a look.
# 23 Re: How can I set the number of spaces a tab is in a CRichEditView?
ok well I set up a SetTabs() method and put the OnInitialUpdate() code there and I call it from just about every function in my RichEditView.. this works.. probably not a real smooth fix.. but it seems to be working and doing what I need it to do.
I would provide you with a sample code to show you my problem, but my code is way too complex to tone it down for a sample.. it would take me forever to do it!!!
Thanks for your help!
lab1 at 2007-11-10 9:16:23 >
