Date: 02-16-2022
Return to Index
created by gbSnippets
'Compiler Comments:
'This code is written to compile with PBWin10. To compile with PBWin9,
'add these lines:
#Include "CommCtrl.inc"
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
#Include "RichEdit.inc"
%IDC_RichEdit = 500
%IDC_Button = 501
Global hDlg,hRichEdit As Dword, OldProc&, CR As CharRange
Function PBMain() As Long
Local style&, buf$
buf$ = "This is sample" + $CrLf + "text for the" + $CrLf + "rich edit control."
style& = %WS_Child Or %WS_Visible Or %ES_MultiLine Or %WS_VScroll Or %ES_AutoHScroll _
Or %WS_HScroll Or %ES_AutoVScroll Or %ES_WantReturn Or %WS_TabStop 'or %ES_NoHideSel
Dialog New Pixels, 0, "Test Code",300,300,200,150, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Push", 30,10,140,20
LoadLibrary("riched32.dll") : InitCommonControls
Control Add "RichEdit", hDlg, %IDC_RichEdit, buf$,20,40,160,100, style&
Control Handle hDlg, %IDC_RichEdit To hRichEdit
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
OldProc& = SetWindowLong(GetDlgItem(hDlg, 500), %GWL_WndProc, CodePtr(REProc)) 'subclass
Case %WM_Destroy
SetWindowLong hRichEdit, %GWL_WNDPROC, OldProc& 'un-subclass
End Select
End Function
Function REProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Local iResult As Long
Static CR As CharRange, TopLine As Long
Select Case wMsg
Case %WM_SetFocus
iResult = SendMessage (hRichEdit, %EM_GetFirstVisibleLine, 0,0) 'current top line
SendMessage hRichEdit, %EM_ExSetSel, 0,VarPtr(CR) '<--- restore selection boundary (changes topline to last line of selection)
SendMessage hRichEdit, %EM_LineScroll, 0, TopLine - iResult '1st time (takes 2)
iResult = SendMessage (hRichEdit, %EM_GetFirstVisibleLine, 0,0)
SendMessage hRichEdit, %EM_LineScroll, 0, TopLine - iResult '2nd time (takes 2)
Case %WM_KillFocus
TopLine = SendMessage(hRichEdit, %EM_GetFirstVisibleLine,0,0) 'visible line# at top of control
SendMessage hRichEdit, %EM_ExGetSel,0,VarPtr(CR) '<--- save selection boundary
End Select
REProc = CallWindowProc(OldProc&, hWnd, wMsg, wParam, lParam)
End Function
'gbs_01071
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm