Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
%IDC_RichEdit = 500
Global hDlg,hRichEdit,pRichEdit,hFont As Dword, FontSize As Long
Function PBMain() As Long
Dialog New Pixels, 0, "Master Pierre",300,300,400,150, %WS_OverlappedWindow To hDlg
LoadLibrary("msftedit.dll")
Control Add "RichEdit50W", hDlg, %IDC_RichEdit, "Pierre",0,0,400,150,%WS_Child Or %WS_ClipSiblings Or %WS_Visible Or %ES_MultiLine _
Or %WS_VScroll Or %ES_AutoVScroll Or %ES_WantReturn Or %ES_NoHideSel Or %WS_TabStop, %WS_Ex_ClientEdge
Control Handle hDlg, %IDC_RichEdit To hRichEdit
FontSize=72
Font New "Tahoma",FontSize,1 To hFont
Control Set Font hDlg, %IDC_RichEdit, hFont
pRichEdit = SetWindowLong(hRichEdit, %GWL_WNDPROC, CodePtr(REProc)) 'subclass
Control Post hDlg, %IDC_RichEdit, %EM_SETSEL, 0,0
Dialog Show Modal hDlg
End Function
Function REProc(ByVal hWnd As Dword, ByVal wMsg As Long, ByVal wParam As Dword, ByVal lParam As Long) As Long
Local ChrRange As CHARRANGE
Function = CallWindowProc(pRichEdit, hWnd, wMsg, wParam, lParam)
Select Case wMsg
Case %WM_SetFocus
CreateCaret(hWnd, ByVal %NULL, 20,1.5*FontSize) 'GoSub CustomCursorCreate
ShowCaret hWnd
Case %WM_KillFocus
DestroyCaret
Case %WM_LButtonDown, %WM_LButtonUp, %WM_KeyDown, %WM_Paint
SendMessage(hWnd, %EM_EXGETSEL, 0, ByVal VarPtr(ChrRange)) 'Get characters selection characters count.
If ChrRange.cpMin = ChrRange.cpMax Then 'Create a caret only if no selection is made.
CreateCaret(hWnd, ByVal %NULL, 20,1.5*FontSize) 'GoSub CustomCursorCreate
ShowCaret hWnd
End If
Case %WM_Destroy
SetWindowLong(hWnd, %GWL_WNDPROC, pRichEdit)
End Select
Exit Function
End Function
http://www.garybeene.com/sw/gbsnippets.htm