Results 1 to 5 of 5

Thread: Strange behavior in richtextbox

  1. #1

    Thread Starter
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    Strange behavior in richtextbox

    Good morning gentlemen. I have a component that inserts a richtext32-based richtextbox.

    The problem that sometimes when I'm going to type a text, instead of the text being on top of the control, it is moved to the end and the feces to the middle. Has anyone ever experienced this?
    Attached Images Attached Images   

  2. #2

    Thread Starter
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    Re: Strange behavior in richtextbox

    One more detail, I have been working and updating this control for 12 years, or more, and this has always happened since the version of winXP.

  3. #3

    Thread Starter
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    Re: Strange behavior in richtextbox

    It is good to have a memory of things. As far as I remember this problem started when I entered the property to justify the text through ...

    SendMessageLong m_Settings.Hwnd, EM_SETTYPOGRAPHYOPTIONS, TO_ADVANCEDTYPOGRAPHY, ByVal _
    TO_ADVANCEDTYPOGRAPHY

    When I remove this API message the strange behavior disappears ...

  4. #4

    Thread Starter
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    Re: Strange behavior in richtextbox

    The complete code:

    Code:
    Private Sub InitializeRichEditBox()
       Dim dwStyle As Long
       Dim dwMask  As Long
       Dim dwLang As Long
       Dim dwExStyle As Long
       Const WS_EX_TRANSPARENT = &H20&
       Const EM_SETLANGOPTIONS As Long = WM_USER + 120&
       Const IMF_SPELLCHECKING As Long = &H800&
       Const IMF_TKBPREDICTION As Long = &H1000&
       Const IMF_TKBAUTOCORRECTION As Long = &H2000&
       'dwStyle
       dwStyle = WS_CHILD Or WS_CLIPCHILDREN Or WS_CLIPSIBLINGS
       dwStyle = dwStyle Or WS_TABSTOP
       dwStyle = dwStyle Or ES_MULTILINE Or ES_WANTRETURN
       dwStyle = dwStyle Or ES_AUTOVSCROLL
       dwStyle = dwStyle Or ES_NOHIDESEL Or ES_SAVESEL
       'dwExStyle
       dwExStyle = WS_EX_TRANSPARENT
       'dwMask
       dwMask = ENM_KEYEVENTS Or ENM_MOUSEEVENTS
       dwMask = dwMask Or ENM_SELCHANGE
       dwMask = dwMask Or ENM_DROPFILES
       dwMask = dwMask Or ENM_UPDATE
       dwMask = dwMask Or ENM_CHANGE
       dwMask = dwMask Or ENM_LINK
       dwMask = dwMask Or ENM_PROTECTED
       dwMask = dwMask Or ENM_SCROLLEVENTS
       dwMask = dwMask Or ENM_SCROLL
       'dwLang
       dwLang = IMF_SPELLCHECKING Or IMF_TKBPREDICTION 'Or IMF_TKBAUTOCORRECTION
       m_Settings.HLib = LoadLibrary("Riched20.dll") ' MsftEdit.dll, riched20.dll, RICHED32.DLL
       m_Settings.Hwnd = CreateWindowEX(dwExStyle, "RICHEDIT", vbNullString, dwStyle, 0, 0, _
       PageText.Width \ Screen.TwipsPerPixelX, PageText.Height \ Screen.TwipsPerPixelY, _
       PageText.Hwnd, 0, App.hInstance, ByVal 0&) 'RichEditD2D, RICHEDIT50W, RICHEDIT, RichEdit20A
       If (m_Settings.Hwnd <> 0) Then
          EnableWindow m_Settings.Hwnd, False
          ShowWindow m_Settings.Hwnd, SW_NORMAL
          SendMessageLong m_Settings.Hwnd, EM_SETTYPOGRAPHYOPTIONS, TO_ADVANCEDTYPOGRAPHY, ByVal _
          TO_ADVANCEDTYPOGRAPHY
          SendMessageLong m_Settings.Hwnd, EM_SETTARGETDEVICE, 0, 0 'wordwrap
          SendMessageLong m_Settings.Hwnd, EM_SETMARGINS, EC_LEFTMARGIN Or EC_RIGHTMARGIN, 0 And (0)
          SendMessageLong m_Settings.Hwnd, EM_EXLIMITTEXT, 0, CONTENT_MAX_LONG
          SendMessageLong m_Settings.Hwnd, EM_SETEVENTMASK, 0, dwMask
          SendMessageLong m_Settings.Hwnd, EM_SETLANGOPTIONS, 0, dwLang 'incluido para ortografia
          pStyleChanged
       End If
    End Sub

  5. #5

    Thread Starter
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    Re: Strange behavior in richtextbox

    Code:
    Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryW" (ByVal lpLibFileName As Long) As Long
    
    Public Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExW" (ByVal dwExStyle As Long, ByVal lpClassName As Long, ByVal lpWindowName As Long, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, ByRef lpParam As Any) As Long
    I replaced LoadLibraryA and CreateWindowExA with LoadLibraryW and CreateWindowExW, and so far it looks like it solved the problem ... I'll do more testing this month and come back here to report something ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width