Specifying the Tab spacing in a Memo

You can adjust the tabulation spacing in Memo controls by sending it the EM_SETTABSTOPS message.  The WParam member specifies the number of tab stops contained in the LParam member.  If the WParam is set to zero, the long parameter is ignored and default tab stops are set at every 32 dialog box units.  If set to one, "tab stops are set at every n dialog box units, where n is the distance pointed to by the ldpwTabs parameter."

What this means is that for most situations, you'd specify "1" as the WParam, and a calculated LParam member using the GetDialogBaseUnits() API function.
 

KEYWORDS:  EM_SETTABSTOPS,  GetDialogBaseUnits()
 

 

//---------------------------------------------------------------------------
//in source...

 int TabWidth = 9;  //new tab width (9 spaces)
 TabWidth = LOWORD(GetDialogBaseUnits()) * TabWidth * 0.5;
 SendMessage(Memo1->Handle, EM_SETTABSTOPS, (WPARAM)1, (LPARAM)&TabWidth);
 
 

 


 
 

One thing to note is that some the handle of the Memo or RichEdit will be destoyed/recreated by changing some properties.  These include WordWrap, ScrollBars, and HideScrollBars, among possibly others.  As such, change all relevant properties first, then set the tab widths. (This is in general for any edit control messages).