Announcement

Collapse
No announcement yet.

AutoURLDetect On/Off - Fail

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • AutoURLDetect On/Off - Fail

    Several years ago I think I posted a RichEdit example of turning the AutoURLDetect feature on or off.

    I was playing around with it tonight and noticed that just sending the EM_AutoURLDetect message alone, with %True or %False, won't show/hide the link formatting. I actually have to clear the RichEdit control and then put the text back in.

    I tried a dialog and control redraw, but that did not make any difference.

    Code:
    'Compilable Example:
    'In this example, a button is used to toggle the display of active URLs.
    #Compiler PBWin 10
    #Compile Exe
    #Dim All
    %Unicode=1
    #Include "win32api.inc"
    #Include "RichEdit.inc"
    Global hDlg As Dword, hRichEdit As Dword
    %ID_RichEdit = 500 : %IDC_Button = 501
    
    Function PBMain() As Long
       Dialog New Pixels, 0, "URL Test",300,300,200,200, %WS_OverlappedWindow To hDlg
       RichEditCreate
       Control Add Button, hDlg, %IDC_Button, "Toggle URL Detect", 30,10,140,20
       Dialog Show Modal hDlg Call DlgProc
    End Function
    
    CallBack Function DlgProc() As Long
       Select Case Cb.Msg
          Case %WM_Command
             If Cb.Ctl = %IDC_Button And Cb.CtlMsg = %BN_Clicked Then
                Static EnableURL&
                EnableURL& = EnableURL& Xor 1
                If EnableURL& Then
                   Control Send hDlg, %ID_RICHEDIT, %EM_AUTOURLDETECT, %True, 0
    '               Control Set Text hDlg, %ID_RichEdit, "URL detect is on!" + $CrLf + $CrLf + " http://www.garybeene.com/"  '<-- won't work without this
                Else
                   Control Send hDlg, %ID_RICHEDIT, %EM_AUTOURLDETECT, %False, 0
    '               Control Set Text hDlg, %ID_RichEdit, "URL detect is off!" + $CrLf + $CrLf + " http://www.garybeene.com/" '<-- won't work without this
                End If
                Dialog ReDraw hDlg                  '<-- have no affect
                Control ReDraw hDlg, %ID_RichEdit   '<-- have no affect
             End If
          Case %WM_Notify
             If Cb.NmId = %ID_RichEdit And Cb.NmCode = %EN_Link Then
                RichEditHyperLink(hDlg, Cb.LParam)
             End If
       End Select
    End Function
    
    Sub RichEditCreate
       LoadLibrary("riched32.dll")
       Call InitCommonControls
       Control Add "RichEdit", hDlg, %ID_RichEdit, "", 20, 50, 160, 140, _
          %WS_Child Or %WS_Visible Or %ES_MultiLine Or %WS_VScroll Or %ES_AutoHScroll _
          Or %WS_HScroll Or %ES_AutoVScroll Or %ES_WantReturn Or %ES_NoHideSel Or %WS_TabStop, _
          %WS_Ex_ClientEdge
       Control Handle hDlg, %ID_RichEdit To hRichEdit
       Control Set Text hDlg, %ID_RichEdit, "URL detect is off!" + $CrLf + $CrLf + " http://www.garybeene.com/"
       SendMessage hRichEdit, %EM_SETEVENTMASK, 0, %ENM_SELCHANGE Or %ENM_CHANGE Or %ENM_LINK
    End Sub
    
    Function RichEditHyperLink(ByVal hWnd As Dword, ByVal lpLink As Dword) As Long
       Local enlinkPtr As ENLINK Ptr, tr As TEXTRANGE, linkText As String
       enlinkPtr    = lpLink
       tr.chrg      = @enLinkPtr.chrg
       linkText     = Space$(tr.chrg.cpMax - tr.chrg.cpMin + 2)
       tr.lpstrText = StrPtr(linkText)
       Control Send hWnd, %ID_RICHEDIT, %EM_GETTEXTRANGE, 0, VarPtr(tr)
       Select Case @enLinkPtr.Msg
          Case %WM_LButtonUp
             ShellExecute(%NULL, "open", ByCopy linkText, "", "", %SW_Show)
             Function = %True                    ' Signal that we processed this
       End Select
    End Function
    
    'gbs_00225
    'Date: 03-10-2012
Working...
X