![]() |
#2
吹水佬2022-03-13 22:10
PARAFORMAT2
MSASM定义 ![]() PARAFORMAT2 STRUCT cbSize DWORD ? dwMask DWORD ? wNumbering WORD ? wEffects WORD ? dxStartIndent DWORD ? dxRightIndent DWORD ? dxOffset DWORD ? wAlignment WORD ? cTabCount WORD ? rgxTabs DWORD MAX_TAB_STOPS dup(?) dySpaceBefore DWORD ? dySpaceAfter DWORD ? dyLineSpacing DWORD ? sStyle WORD ? bLineSpacingRule BYTE ? bOutlineLevel BYTE ? wShadingWeight WORD ? wShadingStyle WORD ? wNumberingStart WORD ? wNumberingStyle WORD ? wNumberingTab WORD ? wBorderSpace WORD ? wBorderWidth WORD ? wBorders WORD ? PARAFORMAT2 ENDS CPP定义 ![]() typedef struct _paraformat2 { UINT cbSize; DWORD dwMask; WORD wNumbering; WORD wReserved; LONG dxStartIndent; LONG dxRightIndent; LONG dxOffset; WORD wAlignment; SHORT cTabCount; LONG rgxTabs[MAX_TAB_STOPS]; LONG dySpaceBefore; /* Vertical spacing before para */ LONG dySpaceAfter; /* Vertical spacing after para */ LONG dyLineSpacing; /* Line spacing depending on Rule */ SHORT sStyle; /* Style handle */ BYTE bLineSpacingRule; /* Rule for line spacing (see tom.doc) */ BYTE bOutlineLevel; /* Outline Level */ WORD wShadingWeight; /* Shading in hundredths of a per cent */ WORD wShadingStyle; /* Byte 0: style, nib 2: cfpat, 3: cbpat*/ WORD wNumberingStart; /* Starting value for numbering */ WORD wNumberingStyle; /* Alignment, Roman/Arabic, (), ), ., etc.*/ WORD wNumberingTab; /* Space bet 1st indent and 1st-line text*/ WORD wBorderSpace; /* Border-text spaces (nbl/bdr in pts) */ WORD wBorderWidth; /* Pen widths (nbl/bdr in half twips) */ WORD wBorders; /* Border styles (nibble/border) */ } PARAFORMAT2; |
(先发句牢骚:我好像还从未在VFP代码中成功传递过struct参数!)
我们知道,VFP的Editbox控件十分简陋,在Windows 7/10/11中显示文字密密麻麻的,用户体验很难受。而RichTextBox控件相对好一些,在文字排版方面添加了许多选项,不过若想要调整行距,也得历经千辛万苦!因为没有现成的“行距”属性,必须借助SendMessage()调用API才能够更改。
百度一下:“调整RichEdit行间距”,于是找到这样一段C代码:
//======================
void __fastcall TForm1::Button1Click(TObject *Sender)
{undefined
PARAFORMAT2 pf;
pf.cbSize=sizeof(PARAFORMAT2); //识别paraformat与paraformat2
pf.dwMask=PFM_LINESPACING;
pf.dyLineSpacing=300; //行距在此设置
pf.bLineSpacingRule=4;
SendMessage(RzRichEdit1->Handle,EM_SETPARAFORMAT,0,LPARAM(&pf));
...
//======================
赶紧查资料!我们可以“翻译”出调用这个API所需的VFP代码是:
SendMessage(Handle, EM_SETPARAFORMAT, 0, @pf)
其中涉及的参数是:
#define WM_USER 0x0400
#define EM_SETPARAFORMAT (WM_USER + 71)
sizeof(PARAFORMAT) = 156
sizeof(PARAFORMAT2) = 188
typedef struct _paraformat {
UINT cbSize;
DWORD dwMask;
WORD wNumbering;
union {
WORD wReserved;
WORD wEffects;
};
LONG dxStartIndent;
LONG dxRightIndent;
LONG dxOffset;
WORD wAlignment;
SHORT cTabCount;
LONG rgxTabs[MAX_TAB_STOPS];
} PARAFORMAT;
struct PARAFORMAT2 : _paraformat {
LONG dySpaceBefore;
LONG dySpaceAfter;
LONG dyLineSpacing;
SHORT sStyle;
BYTE bLineSpacingRule;
BYTE bOutlineLevel;
WORD wShadingWeight;
WORD wShadingStyle;
WORD wNumberingStart;
WORD wNumberingStyle;
WORD wNumberingTab;
WORD wBorderSpace;
WORD wBorderWidth;
WORD wBorders;
};
需传递的struct PARAFORMAT2,只用到了其中这4个字段:
cbSize = 0x000000BC(4字节:其值为结构体总长度 = 十进制188)
dwMask = 0x00000100(4字节:其值为修改行距所对应的Mask = 十进制256)
dyLineSpacing = 0x0000012C(4字节:其值为自己设置的行距值 = 十进制300,单位为twips)
bLineSpacingRule = 0x04(1字节:其值意思是确定改行距的单位为twips)
关键是如何创建一个188字节的字符串,来模拟这个PARAFORMAT2结构体。
我试了半天,一直无法成功,鼓捣成下边这个样子,却一直被VFP报错:
*----------------------
*设置行距
#define WM_USER 0x0400
#define EM_SETPARAFORMAT (WM_USER + 71)
pf = 0hBC000000 + 0h00010000 + REPLICATE(CHR(0), 156) + 0h2C010000 + 0h0000 + CHR(4) + REPLICATE(CHR(0), 17)
SendMessage(this.Hwnd, EM_SETPARAFORMAT, 0, @pf)
*----------------------
C语言的“大端、小端”已搞得我头晕脑胀、一头雾水……
急急求助:怎么破?