Const EM_FORMATRANGE = (WM_USER + 57)
Сообщение EM_FORMATRANGE форматирует текст в rich edit control для заданного устройства
Сообщение возвращает индекс последнего символа в регионе плюс 1
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 Private Const WM_USER = &H400 Private Const EM_FORMATRANGE = (WM_USER + 57) Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Type CHARRANGE char_before As Long char_after As Long End Type Private Type FORMATRANGE hdc As Long target_hdc As Long target_area As RECT entire_area As RECT char_range As CHARRANGE End Type ' Overlay the text on the PictureBox inside ' the specified rectangle (in twips). Private Sub OverlayText(ByVal pic As PictureBox, ByVal rch As RichTextBox, ByVal xmin As Single, ByVal xmax As Single, ByVal ymin As Single, ByVal ymax As Single) Dim format_range As FORMATRANGE ' Подготовим структуры FORMATRANGE With format_range .hdc = pic.hdc .target_hdc = pic.hdc With .entire_area .Left = 0 .Right = pic.ScaleX(pic.ScaleWidth, pic.ScaleMode, vbTwips) .Top = 0 .Bottom = pic.ScaleY(pic.ScaleHeight, pic.ScaleMode, vbTwips) End With With .target_area .Left = xmin .Right = xmax .Top = ymin .Bottom = ymax End With With .char_range .char_before = 0 .char_after = -1 End With End With ' Display as much text as will fit. ' Setting wParam = True makes the RichTextBox ' display the text instead of just measuring it. SendMessage rch.hwnd, _ EM_FORMATRANGE, True, format_range ' Clear resources allocated by the RichTextBox. SendMessage rch.hwnd, EM_FORMATRANGE, False, ByVal 0& End Sub Private Sub Form_Load() RichTextBox1 = "Русский_Проект: Пример сообщения EM_FORMATRANGE" ' Overlay the text on the picture. ' Leave a 10 percent margin. picCanvas.ScaleMode = vbTwips picCanvas.AutoRedraw = True OverlayText picCanvas, RichTextBox1, _ picCanvas.ScaleWidth * 0.1, _ picCanvas.ScaleWidth * 0.9, _ picCanvas.ScaleHeight * 0.1, _ picCanvas.ScaleHeight * 0.9 ' Display the form. Show End Sub