CEdit align right with longer text

Hi, I have problem with align text in CEdit. When I set the long text for example filepath which is longer that CEdit box's length and I wanna make it can be seen the most right hand side of text. I set the property of control when design and try to change style by ModifyStyle too but I didn work.  Who know how can I do that in the approproated way?
wasawasAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

itsmeandnobodyelseCommented:
You can call

   GetDlgItem(IDC_MY_EDIT)->SetSel(n, n-1);

where n is the position within the string that should be shown as first character.
0
ZoppoCommented:
There's one problem with that code - to get this work the 'CWnd*' returned by GetDlgItem() has to be casted to a 'CEdit*'.

To show the text right aligned you can do:

>       CEdit* pEdit = (CEdit*)GetDlgItem( IDC_MY_EDIT );
>      int nLen = pEdit->GetWindowTextLength();
>      pEdit->SetSel( nLen, nLen );

ZOPPO
0
itsmeandnobodyelseCommented:
>>>> to get this work the 'CWnd*' returned by GetDlgItem() has to be casted to a 'CEdit*'.

Thanks Zoppo ;-)

>>>> pEdit->SetSel( nLen, nLen );

That would position the caret (text cursor) to the right of the text thus scrolling most right horizontally.


0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

ZoppoCommented:
That's how I understood this:
>> I wanna make it can be seen the most right hand side of text.
0
itsmeandnobodyelseCommented:
>> I wanna make it can be seen the most right hand side of text.

Yes, I have same understandness ;-)

>>>> ((CEdit*)GetDlgItem(IDC_MY_EDIT))->SetSel(n, n-1);
>>>> where n is the position within the string that should be shown as first character.

It would be much more difficult to determine the n in my suggestion cause the CEdit most probably was using proportional font. To do it rightly you would need to call GetTextExtentPoint32 applying an appropriate device context for increasing substrings to the right until the size calculated is bigger than the size of the CEdit.

A quite different idea to solve the issue is to showing a tooltip withe the full edit string when hoovering with the mouse over the CEdit (requires some free space right of the edit field).
0
wasawasAuthor Commented:
Hi,All

Thanks for you all.

SetSel() is  the one that I've been tried before but it cannot work with some way with using OnEnchange so I was really wanna know is there any properties to set that or not by not using trick with SetSel(). As I say "the approproated way".

Do you have any other idea?

0
itsmeandnobodyelseCommented:
>>>> cannot work with some way with using OnEnchange so
If you mean DoDataExchange by that you simply could comment the path field in
DoDataExchange function and it wouldn't be changed back to left aligned.

>>>> by not using trick with SetSel(). As I say "the approproated way".

The trick is only needed cause you want to show only the right part of a long string what actually is not the standard behavior.

So it would be better to go back to standard behavior, what means that if you want to show only the relevant parts of the file path you better make a static field and show the path like C:\...\some folder\subfolder\filename.ext which fully fits into the field.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ZoppoCommented:
>> by not using trick with SetSel().

I agree with itsmeandnobodyelse. Without the SetSel() IMO there's no chance to do what you want with an edit-control. The problem simply is an edit control always scrolls the shown text in a way the cursor is visible. So, without moving the cursor there's no way.

You could use 'DrawText' to get a string like that one shown by itsmeandnobodyelse which fits into the controls rect using the flags DT_MODIFYSTRING and DT_PATH_ELLIPSIS
0
wasawasAuthor Commented:
Thanks a lot for the answer and  the good comment. I voted the 2nd comment above cause we really want the length to make it go right.

And for who are seeking for "How to set align right with long text for edit control" the answer is "No way" to do that but you can use SetSel( ) to tricking it easier. You should not try to use ModifyStyle() or other properties changing(As here people's answer and comment) cause you will waste time for that.

If others can find another way really good for this. Please put your comment please.

Thanks again.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.