[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Forcing Read-only text field to the right

Posted on 2004-08-24
4
Medium Priority
?
268 Views
Last Modified: 2013-11-20
I have an MFC text box that contains a file path. I'm running short on screen real estate, and the text box is smaller than the path. I want to have the text box display the end of the filepath instead of the beginning. Is there an easy way to do this?
0
Comment
Question by:tcf22
  • 2
4 Comments
 
LVL 13

Expert Comment

by:SteH
ID: 11883812
You need to change it to ownerdrawn. Then you can test the size of the full string and display only the right hand part.  
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11883994
You can send a WM_SETSEL message to the control passing position of last character. Something like:

CString text = "c:\\your main folder\\your subfolder\\additional folder\\the file.txt";

yourControl.SetWindowText(text);
yourControl.SetSel(text.GetLenght(), text.GetLenght());

0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 375 total points
ID: 11885502
>> Is there an easy way to do this?

No, but you can do this:

void CTestDlgDlg::ShowFilePath(const CString& strPath)
{
     CWnd*     pEdit = GetDlgItem(IDC_EDIT);
     CFont*    pFont = pEdit->GetFont();
     CClientDC cdc(this);
     CFont*    pOldFont = cdc.SelectObject(pFont);
     CRect     rectEdit;
     pEdit->GetClientRect(&rectEdit);

     CString str = strPath;
     int        len;
     bool     first = true;
     while ((len = str.GetLength()) > 10)
     {
          CSize sz = cdc.GetTextExtent(str, len);
          if (sz.cx < rectEdit.Width())
               break;
          if (first)
          {
               str = str.Left(3) + "..." + str.Mid(6);  
               first = false;
          }
          else
          {
               str = str.Left(6) + str.Mid(7);
          }
     }
     cdc.SelectObject(pOldFont);

     pEdit->SetWindowText(str);  
}

Call it in OnInitDialog(..) after UpdateData(FALSE) or whenever you have to show a new file name like that

 ShowFilePath("c:\\Documents and Settings\\p602078\\more settings\\anything\\stuff\\mydata.dat",
                     IDC_EDIT);

Regards, Alex




0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 11885522
Correction:

void CTestDlgDlg::ShowFilePath(const CString& strPath, UINT idcEdit)
{
     CWnd*     pEdit = GetDlgItem(idcEdit);
     ...


Regards, Alex
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question