Link to home
Start Free TrialLog in
Avatar of l_d_allan
l_d_allan

asked on

Baffled by CEdit.SetRect and CRect.DeflateRect

Baffled by CEdit.SetRect and CRect.DeflateRect

I'm enhancing an MFC dialog app that has overlapping controls. Now I'd like to implement something fancier.  

Here's how it works now ...
mouse over #2 CTreeCtrl control

222222222222222
222222222222222
222222222222222
222222222222222
222222222222222888888888888888888
222222222222222888888888888888888
222222222222222888888888888888888
222222222222222888888888888888888
222222222222222888888888888888888
222222222222222888888888888888888

mouse over #8 CEdit

222222222222222
222222222222222
222222222222222
222222222222222
888888888888888888888888888888888
888888888888888888888888888888888
888888888888888888888888888888888
888888888888888888888888888888888
888888888888888888888888888888888
888888888888888888888888888888888

The glitch is that the left side text in the #8 CEdit isn't visible when the #2 CTreeControl has focus ... it's covered up by the #2 CTreeCtrl.

What I want to implement is having the text in the #8 CEdit window 'auto-fit' when the #2 CTreeCtrl is in the foreground. It would shrink the left margin sufficiently and let auto-wrap keep all the text in view.

I looked over the documentation, and it would seem like CEdit.GetRect + CRect.DeflateRect + CEdit.SetRect would accomplish what I'm looking for.  The vertical scroll bar would be enabled if all the text wouldn't fit into the shrunk CEdit window.

However, I'm getting unexpected behavior. Several of the margins change, instead of just the left.  And the amount of text gets less/truncated. I don't know if I should be normalizing or otherwise doing coordinate transformations ... or if I'm just fouling up.

If you want to tackle this, I've defined a barebones dialog app with the controls and OnToggle defined. It can be downloaded directly at:
http://groups.yahoo.com/group/InVerse/files/Prototype/Deflate.zip

It has a member function, OnToggle, that I want to cause the 'margin' of the CEdit to deflate and inflate. The CEdit field is preloaded with a long string with embedded new-lines.  The net result should be the text starting off hidden behind #2 CTreeCtrl, then the toggle deflates the right margin so all the text is visible (and can be seen with the scroll bar), and another toggle inflates the right margin so some of the text is again hidden.

It has the vc6 .dsw, .dsp, and associated files. Note that I'm actually trying to get the #8 Cedit window on the right side, but that would not show up in the 'drawing' above due to proportional fonts.

TIA
ASKER CERTIFIED SOLUTION
Avatar of Yechezkel
Yechezkel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of l_d_allan
l_d_allan

ASKER

Worked very well.  Thanks.