hi, I was looking for this for sometime, and finally found it.
Though I now search in the forum, then I do find it posted in one two threads. I posted it here in this Code-Bank section, because I think this one is really handy.
Usage:
SetAlignment RichTextBox1.HWND, ercParaJustifyVB Code:
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal HWND As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal HWND As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Const WM_USER = &H400 Const EM_SETTYPOGRAPHYOPTIONS = WM_USER + 202 Const TO_ADVANCEDTYPOGRAPHY = 1 Const EM_SETPARAFORMAT = WM_USER + 71 Private Const PFA_LEFT = 1 Private Const PFA_RIGHT = 2 Private Const PFA_CENTER = 3 Private Const PFA_JUSTIFY = &H4 Const MAX_TAB_STOPS = 32 Private Type PARAFORMAT2 cbSize As Long dwMask As Long wNumbering As Integer wEffects As Integer dxStartIndent As Long dxRightIndent As Long dxOffset As Long wAlignment As Integer cTabCount As Integer rgxTabs(MAX_TAB_STOPS - 1) As Long dySpaceBefore As Long dySpaceAfter As Long dyLineSpacing As Long sStyle As Integer bLineSpacingRule As Byte bOutlineLevel As Byte wShadingWeight As Integer wShadingStyle As Integer wNumberingStart As Integer wNumberingStyle As Integer wNumberingTab As Integer wBorderSpace As Integer wBorderWidth As Integer wBorders As Integer End Type Public Enum ERECParagraphAlignmentConstants ercParaLeft = PFA_LEFT ercParaCentre = PFA_CENTER ercParaRight = PFA_RIGHT ercParaJustify = PFA_JUSTIFY End Enum Private Const PFM_ALIGNMENT = &H8& Private Function SetAlignment(lHwnd As Long, ByVal eAlign As ERECParagraphAlignmentConstants) Dim tP2 As PARAFORMAT2 Dim lR As Long tP2.dwMask = PFM_ALIGNMENT tP2.cbSize = Len(tP2) tP2.wAlignment = eAlign lR = SendMessageLong(lHwnd, EM_SETTYPOGRAPHYOPTIONS, TO_ADVANCEDTYPOGRAPHY, TO_ADVANCEDTYPOGRAPHY) lR = SendMessage(lHwnd, EM_SETPARAFORMAT, 0, tP2) End Function




Reply With Quote