RichEdit - Keep Selection III When Lose Focus - Dominic

Category: Controls - RichEdit

Date: 02-16-2022

Return to Index


 
'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(hRichEdit, %GWL_WndProc, CodePtr(NewProc))  'subclass
      Case %WM_Destroy
         SetWindowLong hRichEdit, %GWL_WNDPROC, OldProc&   'un-subclass
   End Select
End Function
 
Function NewProc(ByVal hWnd As LongByVal Msg As LongByVal wParam As LongByVal lParam As LongAs Long
   Local lRet As Long
   Select Case Msg
      Case %WM_GETDLGCODE
         ' If the control type is being queried
         If lParam = %NULL Then
            ' Ensure that the edit control does not select its contents on receiving the focus
            lRet = CallWindowProc(OldProc&, hWnd, Msg, wParam, lParam)
            Function = lRet Xor %DlgC_HasSetSel
            Exit Function
         End If
   End Select
   Function = CallWindowProc(OldProc&, hWnd, Msg, wParam, lParam)
End Function
 
'gbs_01072
'Date: 03-10-2012
   


created by gbSnippets
http://www.garybeene.com/sw/gbsnippets.htm