Jump to content
  • Advertisement
Sign in to follow this  
RonHiler

Rich Edit - Calculating height with a given width

This topic is 2138 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a rich edit control, but in certain cases I need to resize it.

 

Basically, it comes down to this. I know the contents of the control. I know the width. Given those, I need to calculate the height.

 

I've played with all kinds of variations of EN_REQUESTRESIZE, but no matter the width of the window I pass in, it doesn't recalculate the height properly (I even deliberately set the window height to something ridiculous (5) to force a recalculation of the height of the REQRESIZE fuction, but it always comes back with the same values in rc->top and rc->bottom (0 and 825 to be exact)), so I think I need to do a more manual recalculation of the height of the window.

 

It seems like this should be something you ought to be able to do, but there doesn't seem to be an obvious way to do it.

 

Here is the code I am using:

 

        case WM_NOTIFY:
            {
            ostringstream ss;
            if (wParam == TTW_TOOLTIPTEXT)
                {
                if (((NMHDR*)lParam)->code == EN_REQUESTRESIZE)
                    {
                    GetWindowRect(ConfiningWindow, &ConfiningRect);
                    ReqResize = (REQRESIZE*)lParam;
                    GetCursorPos(&CursorPoint);
                    X = CursorPoint.x + 10;
                    Y = CursorPoint.y + 10;
                    //don't fall off the bottom of the confining window
                    if (Y + (ReqResize->rc.bottom - ReqResize->rc.top) +15 > ConfiningRect.bottom)
                        Y = ConfiningRect.bottom - (ReqResize->rc.bottom - ReqResize->rc.top) - 15;
                    //also, don't go past the right side of the main window
                    if (X + (ReqResize->rc.right - ReqResize->rc.left) +15 > ConfiningRect.right)
                        X = CursorPoint.x - (ReqResize->rc.right - ReqResize->rc.left) - 15;
                    //at this point we should be entirely inside the window, unless the text is so large the tooltip is higher than the entire window itself.
                    if (Y < ConfiningRect.top)
                        {
                        ss << "Retry: X,Y: " << X << "," << Y << "    ReqResize: " << ReqResize->rc.left << "," << ReqResize->rc.right << "," << ReqResize->rc.top << "," << ReqResize->rc.bottom << "    Confining: " << ConfiningRect.left << "," << ConfiningRect.right << "," << ConfiningRect.top << "," << ConfiningRect.bottom << "\r\n";
                        OutputDebugString(ss.str().c_str());
                        ReqResize->rc.right += 50;
                        SetWindowPos(ToolTipWindow, HWND_TOPMOST, X, Y, ReqResize->rc.right - ReqResize->rc.left+8, ReqResize->rc.bottom - ReqResize->rc.top+8, SWP_HIDEWINDOW);
                        SetWindowPos(ToolTipText, HWND_TOP, 0, 0, ReqResize->rc.right - ReqResize->rc.left, ReqResize->rc.bottom - ReqResize->rc.top, SWP_HIDEWINDOW);
                        SendMessage(ReqResize->nmhdr.hwndFrom, EM_REQUESTRESIZE, 0, 0);
                        return 0;
                        }  
                    SetWindowPos(ToolTipWindow, HWND_TOPMOST, X, Y, ReqResize->rc.right - ReqResize->rc.left+8, ReqResize->rc.bottom - ReqResize->rc.top+8, SWP_SHOWWINDOW);
                    SetWindowPos(ToolTipText, HWND_TOP, 0, 0, ReqResize->rc.right - ReqResize->rc.left, ReqResize->rc.bottom - ReqResize->rc.top, SWP_SHOWWINDOW);
                    return 0;
                    }
                return 0;
                }
            return 0;
            }
 

 

So, just to clarify, that ODS string gives values like such:

 

Retry: X,Y: 1015,30    ReqResize: 0,200,0,825    Confining: 460,1460,330,870
Retry: X,Y: 1015,30    ReqResize: 0,250,0,825    Confining: 460,1460,330,870
Retry: X,Y: 1015,30    ReqResize: 0,300,0,825    Confining: 460,1460,330,870

 

Notice ReqResize width is increasing by 50 at a time, but the height isn't changing.

 

Any suggestions?

Share this post


Link to post
Share on other sites
Advertisement

Maybe you could check for the vertical scroolbar range value, and if it's higher than the height of you're richedit box, change it to this value.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!