rainstormmaster的blog
rainstormmaster的blog

        随着vb6几个补丁的退出,事实上richtextbox正悄悄发生变化,它已经支持richedit2.0了,所以我们可以设置结构体PARAFORMAT2的dyLineSpacing成员,然后将PARAFORMAT2结构体作为lparam参数,对richtextbox发送EM_SETPARAFORMAT消息,即可实现我们的要求,具体代码如下:
Option Explicit

Private Declare Function SendMessage& Lib "user32" Alias "SendMessageA" _
    (ByVal hwnd As Long, ByVal wMsg As Long, _
    ByVal wParam As Long, lParam As Any)

Private Const WM_USER& = &H400
Private Const EM_GETPARAFORMAT = (WM_USER + 61)
Private Const EM_SETPARAFORMAT = (WM_USER + 71)
Private Const MAX_TAB_STOPS = 32&

Private Type PARAFORMAT2
    'Los primeros campos coinciden con PARAFORMAT y se usan igual
    cbSize As Integer
    wPad1 As Integer
    dwMask As Long
    wNumbering As Integer
    wEffects As Integer 'No usado en PARAFORMAT
    dxStartIndent As Long
    dxRightIndent As Long
    dxOffset As Long
    wAlignment As Integer
    cTabCount As Integer
    lTabStops(0 To MAX_TAB_STOPS - 1) As Long
    ' Desde aquí lo a?adido por PARAFORMAT2
    dySpaceBefore As Long '/* Vertical spacing before para */
    dySpaceAfter As Long '/* Vertical spacing after para */
    dyLineSpacing As Long '/* Line spacing depending on Rule */
    sStyle As Integer ' /* Style handle */
    bLineSpacingRule As Byte '/* Rule for line spacing (see tom.doc) */
    bOutlineLevel As Byte '/* Outline Level*/'antes bCRC As Byte
    wShadingWeight As Integer '/* Shading in hundredths of a per cent */
    wShadingStyle As Integer '/* Byte 0: style, nib 2: cfpat, 3: cbpat*/
    wNumberingStart As Integer '/* Starting value for numbering */
    wNumberingStyle As Integer ' /* Alignment, Roman/Arabic, (), ), ., etc.*/
    wNumberingTab As Integer '/* Space bet 1st indent and 1st-line text*/
    wBorderSpace As Integer ' /* Border-text spaces (nbl/bdr in pts) */
    wBorderWidth As Integer '/* Pen widths (nbl/bdr in half twips) */
    wBorders As Integer '/* Border styles (nibble/border) */
End Type

' /* PARAFORMAT mask values */
Private Const PFM_STARTINDENT = &H1&
Private Const PFM_RIGHTINDENT = &H2&
Private Const PFM_OFFSET = &H4&
Private Const PFM_ALIGNMENT = &H8&
Private Const PFM_TABSTOPS = &H10&
Private Const PFM_NUMBERING = &H20&
Private Const PFM_OFFSETINDENT = &H80000000

' /* PARAFORMAT numbering options */
Private Const PFN_BULLET = &H1&

' /* PARAFORMAT alignment options */
Private Const PFA_LEFT = &H1&
Private Const PFA_RIGHT = &H2&
Private Const PFA_CENTER = &H3&

'/* PARAFORMAT 2.0 masks */
Private Const PFM_SPACEBEFORE = &H40&
Private Const PFM_SPACEAFTER = &H80&
Private Const PFM_LINESPACING = &H100&
Private Const PFM_STYLE = &H400&
Private Const PFM_NUMBERINGSTYLE = &H2000& ' /* RE 3.0 */
Private Const PFM_NUMBERINGTAB = &H4000& ' /* RE 3.0 */
Private Const PFM_NUMBERINGSTART = &H8000& ' /* RE 3.0 */
Private Const PFM_TABLE = &HC0000000 ' /* RE 3.0 */
'// The following three properties are read only
Private Const PFM_COLLAPSED = &H1000000 '/* RE 3.0 */
Private Const PFM_OUTLINELEVEL = &H2000000 '/* RE 3.0 */
Private Const PFM_BOX = &H4000000 '/* RE 3.0 */

'/* PARAFORMAT2 wNumbering options (see also PFN_BULLET) */
Private Const PFN_ARABIC = 2 '/* tomListNumberAsArabic: 0, 1, 2, ...*/
Private Const PFN_LCLETTER = 3 '/* tomListNumberAsLCLetter: a, b, c, ...*/
Private Const PFN_UCLETTER = 4 '/* tomListNumberAsUCLetter: A, B, C, ...*/
Private Const PFN_LCROMAN = 5 '/* tomListNumberAsLCRoman: i, ii, iii, ...*/
Private Const PFN_UCROMAN = 6 '/* tomListNumberAsUCRoman: I, II, III, ...*/

'/* PARAFORMAT2 wNumberingStyle options */
Private Const PFNS_PAREN = &H0 '/* default, e.g., 1) */
Private Const PFNS_PARENS = &H100 '/* tomListParentheses/256, e.g., (1) */
Private Const PFNS_PERIOD = &H200 '/* tomListPeriod/256, e.g., 1. */
Private Const PFNS_PLAIN = &H300 '/* tomListPlain/256, e.g., 1 */
Private Const PFNS_NONUMBER = &H400 '/* Used for continuation w/o number

Private Sub Form_Load()
    Dim pf As PARAFORMAT2
    With pf
    .cbSize = LenB(pf)
    pf.dwMask = PFM_LINESPACING
    .bLineSpacingRule = 4
    .dyLineSpacing = 40 * 15
    End With
    Dim i As Long
    i = SendMessage(RichTextBox1.hwnd, EM_SETPARAFORMAT, 0, ByVal VarPtr(pf))
End Sub

 

posted on 2006-02-20 03:02  学剑学诗两不成  阅读(3869)  评论(0编辑  收藏  举报