Maybe I am just trying to make this harder than it really is but this is starting to bug me.

I have a richedit and I would like to set the tab stops to something simple like 4 characters per tab. Now normally this wouldnt be possible I grant you, but I am using the simple style which makes it behave like a normal edit control (single font only) but I think thats still the only function I have available to set the tab stops...

Is there an easy way or am I going to have to do something like GetCharExtent for the pixel width, find the number of pixels / inch and convert to twips... (if you *can* find the pixels / inch.

Arrrggghhh :confused:
Posted on 2002-04-23 14:23:12 by Graebel

Maybe I am just trying to make this harder than it really is


Nope. Microsoft has outdone themselves making this a pain. :)

Is there an easy way or am I going to have to do something like GetCharExtent for the pixel width, find the number of pixels / inch and convert to twips... (if you *can* find the pixels / inch.


If you're using a fixed-spaced font, select the font and call GetTextMetrics, and use TEXTMETRIC.tmAveCharWidth. That's going to be in logical units.

Here is where Microsoft really shines, you know? A "logical unit" is defined as "Physical or virtual device addressable through a SCSI target device". *sigh*. Morons. Look up mapping modes instead, because that's what they really mean. Look up GetMapMode & SetMapMode to convert between logical units and dialog units.

Ah, dialog units! Those are what EM_SETTABSTOPS is looking for.

Looking for a quick, cheap, dirty hack? TabStops are initially set to 32 dialog units. See what that translates to in your font, and then munge it accordingly. You didn't hear that from me. ;)

Cheers,

-Chalain
Posted on 2002-04-23 17:02:41 by Chalain
Hi Graebel

This is what I use to set tabstops in a richedit.

;########################################################################


GetFontWt proc hWin:HWND,hFnt:DWORD
LOCAL hDC:HDC
LOCAL tm:TEXTMETRIC

invoke GetDC,hWin
mov hDC,eax
invoke SelectObject,hDC,hFnt
push eax
invoke GetTextMetrics,hDC,addr tm
pop eax
invoke SelectObject,hDC,eax
invoke ReleaseDC,hWin,hDC
mov eax,tm.tmHeight
mov fntht,eax
mov eax,tm.tmAveCharWidth
mov fntwt,eax
ret

GetFontWt endp

SetFormat proc hWin:DWORD,hFnt:DWORD
LOCAL lpchr1:CHARRANGE
LOCAL lpchr2:CHARRANGE
LOCAL pf:PARAFORMAT2
LOCAL tp:DWORD

invoke SendMessage,hWin,EM_GETMODIFY,0,0
push eax
invoke SendMessage,hWin,EM_EXGETSEL,0,addr lpchr1
invoke SendMessage,hWin,EM_HIDESELECTION,TRUE,0
mov lpchr2.cpMin,0
mov lpchr2.cpMax,-1
invoke SendMessage,hWin,EM_EXSETSEL,0,addr lpchr2
mov pf.cbSize,sizeof pf
mov pf.dwMask,PFM_TABSTOPS
mov pf.cTabCount,MAX_TAB_STOPS
;Get tab width
invoke GetFontWt,hWin,hFnt
mov ecx,TabSize
mul ecx
;Convert to twips
mov ecx,15
mul ecx
mov tp,eax
mov eax,0
mov edx,0
mov ecx,32
@@:
add eax,tp
mov dword ptr pf.rgxTabs[edx],eax
add edx,4
loop @b
invoke SendMessage,hWin,EM_SETPARAFORMAT,0,addr pf
invoke SendMessage,hWin,WM_SETFONT,hFnt,0
invoke SendMessage,hWin,EM_EXSETSEL,0,addr lpchr1
pop eax
invoke SendMessage,hWin,EM_SETMODIFY,eax,0
invoke SendMessage,hWin,EM_HIDESELECTION,FALSE,0
ret

SetFormat endp

;########################################################################



KetilO
Posted on 2002-04-23 18:02:45 by KetilO