Announcement

Collapse
No announcement yet.

Tab setting in Richedit control

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

  • Tab setting in Richedit control

    I'm using a richedit control in the freeware SDK visual designer
    and am trying to add the option of allowing the user to set the
    spacing for tabs. So far I have had no luck. Here is the
    function I am using:

    Code:
    FUNCTION setRichTextTabs(BYVAL hEdit AS LONG, BYVAL tabStops AS LONG) AS LONG
    	LOCAL pf AS PARAFORMAT, pd AS CHARRANGE, Events AS LONG
    	
    	'Disable the event mask, for better speed
    	Events = SendMessage(hEdit, %EM_GETEVENTMASK, 0, 0)
    	SendMessage hEdit, %EM_SETEVENTMASK, 0, 0
    	' Hide the selection to eliminate flickering
    	SendMessage hEdit, %EM_HIDESELECTION, 1, 0
    	' Select the entire text
    	pd.cpmin = 0
    	pd.cpMax = -1
    	SendMessage hEdit, %EM_EXSETSEL, 0, VARPTR(pd)
    
    	pf.cbSize      = SIZEOF(pf)
    	pf.dwMask      = %PFM_TABSTOPS
    	pf.cTabCount = %MAX_TAB_STOPS
    	For i& = 0 To %MAX_TAB_STOPS - 1
    		pf.rgxTabs(i&) = i& * tabStops * 144
    	Next i&
    
    	n& = SendMessage(hEdit, %EM_SETPARAFORMAT, 0, VARPTR(pf))
    	' Deselect the text
    	pd.cpmin = 0
    	pd.cpMax = 0
    	SendMessage hEdit, %EM_EXSETSEL, 0, VARPTR(pd)
    	' Turn selection back on
    	SendMessage hEdit, %EM_HIDESELECTION, 0, 0
    	' Reset the event mask
    	IF Events THEN
    		SendMessage hEdit, %EM_SETEVENTMASK, 0, Events
    	End If
    
    	FUNCTION = n&
    END FUNCTION ' setRichTextTabs
    The SendMessage(hEdit, %EM_SETPARAFORMAT, 0, VARPTR(pf)) always
    returns 0, which indicates failure. I pass the function the
    handle to the edit control and the number of characters to use
    for the tab interval. Anyone have any ideas as to what I am
    doing wrong??
    TIA... Ed

    ------------------

  • #2
    Ed,

    I think there is a typo "144" should be "1440" ? (1 inch tabs?)

    Code:
    For i& = 0 To %MAX_TAB_STOPS - 1
        pf.rgxTabs(i&) = i& * tabStops * 1440	
    Next i&
    The other thing I read, is if you are in Plain Textmode(EM_SETTEXTMODE,TM_PLAINTEXT),
    the EM_SETPARAFORMAT message will return 0(failure).

    HTH
    Regards, Jules




    [This message has been edited by Jules Marchildon (edited September 06, 2000).]
    Best regards
    Jules
    www.rpmarchildon.com

    Comment


    • #3
      Hi Jules,
      Thanks for responding. No, it's not a typo. I want to be able
      to set small tab increments. 144 is 1/10th of an inch, which is
      fairly close to a character width. To set the tab approx. 4
      characters, I would send the function a tabstops value of 4.
      The textmode never occured to me. I'll check it out and see if
      it has an effect.
      Thanks... Ed

      ------------------

      Comment


      • #4
        I have checked the related UDT's and equates, still can't find
        the solution to this problem. Does anybody know what is wrong?
        Maybe a style needs to be added to the RichEdit control?

        Calling Dr. RichEdit Control ?? (That's you Borje.)

        Regards, Jules

        Best regards
        Jules
        www.rpmarchildon.com

        Comment


        • #5
          I my IDE, I subclassed the RichEdit control, to insert a proper TAB character - Chr$(9),

          I had to pass it along from the WM_KEYDOWN > VK_TAB message.

          Regards,


          ------------------
          Kev G Peel
          KGP Software, Bridgwater, UK.
          www.go.to/kgpsoftware
          kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

          Comment


          • #6
            Hi Kev!

            So are you saying you could not set the tabs using the above method?

            Regards, Jules


            Best regards
            Jules
            www.rpmarchildon.com

            Comment


            • #7
              Jules,
              I tried EM_SETTABSTOPS and could not get it to work, so I gave up and did what I mentioned earlier,

              I haven't tried that other code yet.

              Regards,


              ------------------
              Kev G Peel
              KGP Software, Bridgwater, UK.
              www.go.to/kgpsoftware
              kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

              Comment


              • #8
                The PARAFORMAT structure in RichEdit.inc seems to be too long.
                If you change the member "rgxTabs(%MAX_TAB_STOPS) AS LONG"
                to "rgxTabs(%MAX_TAB_STOPS - 1) AS LONG" in RichEdit.inc, it
                will work fine. (Tom, are you listening?)

                The reason is probably because it otherwise creates an array
                of 33 elements - 0 to 32, you know..

                The following should work (removed " * tabStops"):
                Code:
                        pf.cTabCount = %MAX_TAB_STOPS
                        For i& = 0 To %MAX_TAB_STOPS - 1
                           pf.rgxTabs(i&) = i& * 144
                        Next i&
                        n& = SendMessage(hEdit, %EM_SETPARAFORMAT, 0, VARPTR(pf))
                ------------------

                Comment


                • #9
                  Thanks Borje!

                  You are definetly the Doctor of RichEdit controls!

                  Regards, Jules

                  Best regards
                  Jules
                  www.rpmarchildon.com

                  Comment


                  • #10
                    Borje, You were right (naturally!)
                    It works like a charm!

                    Jules, thanks again. And you are right too... Borje is the
                    Doctor of Richedit controls.

                    Thanks guys

                    ------------------

                    Comment

                    Working...
                    X