Announcement

Collapse

Maintenance

The forum could be offline for 30-60 minutes in the very near future for maintenance (said 3pm Pacific). I was behind on getting this notice. I do apologize.
See more
See less

Rich Edit: height/width

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

  • Rich Edit: height/width

    Folks --
    there is a way to retrieve necessary (minimum) height and width to display multiline text in RichEdit ?

  • #2
    I'm not sure this will work, but if you send an EM_REQUESTRESIZE
    message to the control, you will get an EN_REQUESTRESIZE notification
    message back in the parent's WM_NOTIFY, containing a pointer to a
    REQRESIZE structure, that has a RECT member.

    This is the part I'm not sure about, but I think this RECT member
    should contain the necessary width and height.


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

    Comment


    • #3
      Semen,

      I have found that if you try and create a rich edit control at
      zero size that the CreateWindowEx fails. What I do is create it
      at a size like 100 x 100 pixels and then size it with MoveWindow(),
      usually in the WM_SIZE message to what ever size I need after that.

      regards,

      hutch[email protected]

      ------------------
      hutch at movsd dot com
      The MASM Forum

      www.masm32.com

      Comment


      • #4
        I think Semen is asking how to resize the edit control to the size
        of the shortest line. In this case you need two bits of information.
        The RECT and the average width and height of the font used.

        I have an example somewhere in my pile of books/source, I'll try
        to dig it up for you when I get home.

        Regards, Jules
        [email protected]
        Best regards
        Jules
        www.rpmarchildon.com

        Comment


        • #5
          Thanks, guys, for suggestions.
          Just now I want to explain exactly, what I need.
          I want to display custom tooltip.
          It's not a problem to calculate size of plain multiline text and to show borders around it (in current moment I use DrawText).
          But to make text better, I want to use RTF (of course, without scroll bars).




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

          Comment


          • #6
            Semen,

            This is not proven technique, just psuedo code...

            Assume you have the strings in memory some place and the strings
            include a CR for each line, then use

            '---
            GetTextMetrics() and calculate your line spacing
            i.e. line_spacing = tm.tmHeight + tm.InternalLeading.
            total height = nLines * line_spacing


            '---
            GetTextExtentPoint32() and calculate the width required
            width = nChars * tm.tmAveCharWidth.

            With this info you can now calucate your RECT and resize the edit
            control to snuggly fit all the text.

            HTH,
            Jules
            Best regards
            Jules
            www.rpmarchildon.com

            Comment


            • #7
              Jules --
              Unlike plain text (where really more simple), this method can't be used for RTF (different fonts).

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

              Comment


              • #8
                Semen, this is getting more difficult as the dialog continues.

                The above will still apply.

                Assume that each line is of a different height then you will need to
                calculate the height of each line and add them to get your total height.
                For your width, use your longest line.

                Also, I have an old VC++ 1.5 code, self-extracting 29kb, that resizes
                a normal edit control to fit the text. This can be used as your
                starting point for your multiple Font RTF project.

                Send me an email, I will send it to you.


                Regards, mailto:[email protected][email protected]</A>


                Edited:
                Forget the code I have! it does the same thing you are all ready doing,
                by using DrawText to get your RECT. Stick with the TextMetrics method.

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


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

                Comment


                • #9
                  Semen, if you download Wincab/freeddt from my site, and you see the mouse above the link, is this what you need?

                  Let me know!


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

                  Comment


                  • #10
                    I ran across this code at www.planetsourcecode.com and I don't know if this will help you or not but its a VB source but it might have some idea. Hope it works. If the link doesn't work email me mailto:[email protected][email protected]</A>

                    http://www.planetsourcecode.com/vb/s...txtCodeId=8894

                    ------------------
                    -Greg
                    -Greg
                    [email protected]
                    MCP,MCSA,MCSE,MCSD

                    Comment


                    • #11
                      A small "auto-height" sample provided in the source code forum.


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

                      Comment


                      • #12
                        Borje --
                        It's exactly, what I need. Perhaps, not optimal, because in additional it's necessary to use "auto-width" algorithm (increasing width from minimum to maximum until it's possible to reduce height), but works fine.

                        Thanks a lot.


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

                        Comment

                        Working...
                        X