Hi,
I got a small question.
I try to duplicate a line in an Rich Text Box but there is something strange
Case %IDM_EDIT_DUPLICATE_LINE
SendMessage(hEdit, %EM_EXGETSEL, 0, VarPtr(cRange)) '---Pass the simulated structure pointer
SelStart = cRange.cpMin
CurLine = SendMessage(hEdit, %EM_EXLINEFROMCHAR, 0, SelStart) 'line number
StartOfLine = SendMessage(hEdit, %EM_LINEINDEX, CurLine, 0) 'Start of line
EndOfLine = SendMessage(hEdit, %EM_LINEINDEX, CurLine + 1, 0) 'end of line
crange.cpMin = StartOfLine
crange.cpMax = EndOfLine
SendMessage(hEdit, %EM_EXSETSEL, 0, VarPtr(cRange))
SendMessage(hEdit, %WM_COPY, 0, 0)
SendMessage(hEdit, %WM_PASTE, 0, 0)
SendMessage(hEdit, %WM_PASTE, 0, 0)
I have to send "SendMessage(hEdit, %WM_PASTE, 0, 0) " twice before he duplicate the line.
Is there a reason for.
Regards
Patrick
Hi
the rich text control operations are extremely complex by nature.
but i have this code i have adapted long time ago from Eros example somewhere. write some text and select some words then press the button colorize selected , and the procedure will colorize and copy the selected text.
and now if you place the cursor somewhere in the rich edit area and press the button paste selected, the text will be pasted. and i have used SendMessage(hEdit, %WM_PASTE, 0, 0) once.
Uses "UI"
#INCLUDE "%APP_INCLUDEPATH%\RichEdit32.inc"
Begin Const
%ID_TEXT_CurLine = 100
%ID_TEXT_CurPos
%ID_TEXT_BufSize
%ID_TEXT_BufPos
%ID_TEXT_BufLines
%ID_TEXT_SelStart
%ID_TEXT_SelEnd
%ID_TEXT_SelText
%ID_TEXT_LineStart
%ID_TEXT_LineEnd
%ID_TEXT_LineText
%ID_RICHEDIT
%IDBTN_RUN
%IDBTN_PASTE
End Const
Global hEdit As DWord
Function TBMain()
Dim hDlg As Long '---Handle of the main window
Dialog New 0, "RichEdit control example", 100, 50, 500, 300, _
%WS_DLGFRAME Or _
%DS_CENTER Or _
%WS_CAPTION Or _
%WS_SYSMENU Or _
%WS_OVERLAPPEDWINDOW , _
0 To hDlg
Dim lx, ly, wx, hy As Long
Dialog Get Size hDlg To lx, ly
Dialog Get Client hDlg To wx, hy
Dialog Get Client hDlg To wx, hy
wx = 350
hY = hY - 30
Control Add RTF_GetClass, hDlg, %ID_RICHEDIT, "", 0, 0, wx, hy, _
%WS_CHILD Or _
%WS_CLIPCHILDREN Or _
%WS_VISIBLE Or _
%ES_MULTILINE Or _
%WS_VSCROLL Or _
%WS_HSCROLL Or _
%ES_AUTOVSCROLL Or _
%ES_AUTOHSCROLL Or _
%ES_WANTRETURN , _
%WS_EX_CLIENTEDGE
Control Add Button, hDlg, %IDBTN_RUN , "&colorize selected..", 355, 3, 60, 20, %BS_PUSHLIKE
Control Add Button, hDlg, %IDBTN_PASTE , "&paste selected..", 355, 30, 60, 20, %BS_PUSHLIKE
Control Set Resize hDlg, %ID_RICHEDIT, 1, 0, 1, 1
'---Return a window handle for the specified control ID
Control Handle hDlg, %ID_RICHEDIT To hEdit
'---Must set the event mask, so we can pick up a few events from Richedit
SendMessage(hEdit, %EM_SETEVENTMASK, 0, %ENM_SELCHANGE Or %ENM_CHANGE Or %ENM_UPDATE Or %ENM_KEYEVENTS Or %ENM_MOUSEEVENTS)
SendMessage(hEdit, %EM_SETLIMITTEXT, &H100000, 0) 'make it accept text > 32767 bytes &H100000&
'DIM hFont AS DWORD = createfont(60,30,0,0,0,0,0,0,0,0,0,0,0,"Courier")
Dim hFont As DWord Resource = Font_Create("Courier New", 10)
SendMessage hEdit, %WM_SETFONT, hFont, 0
'---Show dialog in MODAL state
Dialog Show Modal hDlg, Call dlgCallback
End Function
CallBack Function dlgCallback() As Long
Dim sBuffer As String
Dim lColor As Long
'---Now test the message
Select Case CBMSG
Case %WM_COMMAND
Select Case CBCTL
Case %ID_RICHEDIT 'Some Richedit events, just to
RichEdit_UpdateInfo(CBHNDL, hEdit)
Case %IDBTN_RUN
RTF_SetFGColor(CBHNDL, %ID_RICHEDIT, Rgb(255,0,0))
SendMessage(hEdit, %WM_COPY, 0, 0)
'SendMessage(hEdit, %WM_PASTE, 0, 0)
Case %IDBTN_PASTE
SendMessage(hEdit, %WM_PASTE, 0, 0)
End Select
End Select
End Function
'-----------------------------------------------------------------------------
' Update information about rich edit
'-----------------------------------------------------------------------------
Function RichEdit_UpdateInfo(ByVal hWnd As Long, ByVal hEdit As Long) As Long
Dim lCR As CHARRANGE
Dim lTR As TEXTRANGE
Dim sBigBuffer As String
Dim SelStart, SelEnd, SelNBytes As Long
Dim BufSize As Long
Dim CurLine, CurPos, LineStart, LineLen As Long
'---Selection informations
'---Selection start/end
SendMessage(hEdit, %EM_EXGETSEL, 0, VarPtr(lCR)) '---
SelStart = lCR.cpMin '---
SelEnd = lCR.cpMax
sBigBuffer = String$((SelEnd - SelStart + 1) * 2, Chr$(0))
Control Send hWnd, %ID_RICHEDIT, %EM_GETSELTEXT, 0, StrPtr(sBigBuffer) To SelNBytes
If SelNBytes > 0 Then
If IsUnicode(sBigBuffer) Then
' Control Set Text hWnd, %ID_TEXT_SelText, LEFT$(Acode$(sBigBuffer), SelNBytes)
'PrintL LEFT$(Acode$(sBigBuffer), SelNBytes)
Else
'CONTROL SET TEXT hWnd, %ID_TEXT_SelText, left$(sBigBuffer, SelNBytes)
Control Set Text hWnd, %ID_TEXT_SelText, LEFT$(sBigBuffer, SelNBytes)
End If
Else
Control Set Text hWnd, %ID_TEXT_SelText, ""
End If
'PrintL SelStart
'Control Set Text hWnd, %ID_TEXT_SelStart, SelStart
'Control Set Text hWnd, %ID_TEXT_SelEnd , SelEnd
End Function
Thanks Zak,
I will check it out.
Let you know the results.
Regards
Patrick
Hi Zak,
Its not what i wanted to accomplish.
My goal is when iam on a line somewhere in the RTF control then when i select a menuitem the complete line where the cursor is has to copied to the clipboard and then paste back into the RTF.
example : lets say the cursor is somewhere in the first line
this is a line
This is another line
Then i push on a menu (for duplica line) then the text would look like this.
this is a line
this is a line
This is another line
thats all.
The code above in thread is ok it works but i have put to 2 times "SendMessage(hEdit, %WM_PASTE, 0, 0) ". And that is my problem.
Regards
Patrick